Class: EventStoreClient::DeserializedEvent
- Inherits:
-
Object
- Object
- EventStoreClient::DeserializedEvent
- Defined in:
- lib/event_store_client/deserialized_event.rb
Constant Summary collapse
- LINK_TYPE =
'$>'
Instance Attribute Summary collapse
-
#commit_position ⇒ Object
readonly
Returns the value of attribute commit_position.
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#prepare_position ⇒ Object
readonly
Returns the value of attribute prepare_position.
-
#stream_name ⇒ Object
readonly
Returns the value of attribute stream_name.
-
#stream_revision ⇒ Object
readonly
Returns the value of attribute stream_revision.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Implements comparison of
EventStoreClient::DeserializedEvent-s. -
#initialize(args = {}) ⇒ DeserializedEvent
constructor
A new instance of DeserializedEvent.
-
#link? ⇒ Boolean
Detect whether an event is a link event.
-
#payload_content_type ⇒ Object
content type of the event data.
-
#schema ⇒ Object
event schema.
- #to_h ⇒ Hash
Constructor Details
#initialize(args = {}) ⇒ DeserializedEvent
Returns a new instance of DeserializedEvent.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/event_store_client/deserialized_event.rb', line 26 def initialize(args = {}) validate(args[:data]) unless args[:skip_validation] @data = args.fetch(:data) { {} } @type = args[:type] || self.class.name = args.fetch(:metadata) { {} }. merge( 'type' => @type, 'content-type' => payload_content_type ) @stream_name = args[:stream_name] @stream_revision = args[:stream_revision] @prepare_position = args[:prepare_position] @commit_position = args[:commit_position] @title = args[:title] @id = args[:id] end |
Instance Attribute Details
#commit_position ⇒ Object (readonly)
Returns the value of attribute commit_position.
10 11 12 |
# File 'lib/event_store_client/deserialized_event.rb', line 10 def commit_position @commit_position end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
10 11 12 |
# File 'lib/event_store_client/deserialized_event.rb', line 10 def data @data end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
10 11 12 |
# File 'lib/event_store_client/deserialized_event.rb', line 10 def id @id end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
10 11 12 |
# File 'lib/event_store_client/deserialized_event.rb', line 10 def end |
#prepare_position ⇒ Object (readonly)
Returns the value of attribute prepare_position.
10 11 12 |
# File 'lib/event_store_client/deserialized_event.rb', line 10 def prepare_position @prepare_position end |
#stream_name ⇒ Object (readonly)
Returns the value of attribute stream_name.
10 11 12 |
# File 'lib/event_store_client/deserialized_event.rb', line 10 def stream_name @stream_name end |
#stream_revision ⇒ Object (readonly)
Returns the value of attribute stream_revision.
10 11 12 |
# File 'lib/event_store_client/deserialized_event.rb', line 10 def stream_revision @stream_revision end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
10 11 12 |
# File 'lib/event_store_client/deserialized_event.rb', line 10 def title @title end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
10 11 12 |
# File 'lib/event_store_client/deserialized_event.rb', line 10 def type @type end |
Instance Method Details
#==(other) ⇒ Boolean
Implements comparison of EventStoreClient::DeserializedEvent-s. Two events matches if all of
their attributes matches
57 58 59 60 61 |
# File 'lib/event_store_client/deserialized_event.rb', line 57 def ==(other) return false unless other.is_a?(EventStoreClient::DeserializedEvent) to_h == other.to_h end |
#link? ⇒ Boolean
Detect whether an event is a link event
74 75 76 |
# File 'lib/event_store_client/deserialized_event.rb', line 74 def link? type == LINK_TYPE end |
#payload_content_type ⇒ Object
content type of the event data
49 50 51 |
# File 'lib/event_store_client/deserialized_event.rb', line 49 def payload_content_type 'application/json' end |
#schema ⇒ Object
event schema
46 |
# File 'lib/event_store_client/deserialized_event.rb', line 46 def schema; end |
#to_h ⇒ Hash
64 65 66 67 68 69 70 |
# File 'lib/event_store_client/deserialized_event.rb', line 64 def to_h instance_variables.each_with_object({}) do |var, result| key = var.to_s key[0] = '' # remove @ sign result[key.to_sym] = instance_variable_get(var) end end |