Class: EventStoreClient::DeserializedEvent
- Inherits:
-
Object
- Object
- EventStoreClient::DeserializedEvent
- Defined in:
- lib/event_store_client/deserialized_event.rb
Instance Attribute Summary collapse
-
#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.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #content_type ⇒ Object
-
#initialize(**args) ⇒ DeserializedEvent
constructor
A new instance of DeserializedEvent.
- #schema ⇒ Object
Constructor Details
#initialize(**args) ⇒ DeserializedEvent
Returns a new instance of DeserializedEvent.
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/event_store_client/deserialized_event.rb', line 18 def initialize(**args) validation = schema.call(args[:data] || {}) @data = args.fetch(:data) { {} } @metadata = args.fetch(:metadata) { {} }.merge( 'type' => self.class.name, 'content-type' => content_type ) @metadata.merge!('validation-errors' => validation.errors.to_h) if validation.errors.any? @type = args[:type] || self.class.name @title = args[:title] @id = args[:id] end |
Instance Attribute Details
#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.
7 8 9 |
# File 'lib/event_store_client/deserialized_event.rb', line 7 def id @id end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
11 12 13 |
# File 'lib/event_store_client/deserialized_event.rb', line 11 def @metadata end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
9 10 11 |
# File 'lib/event_store_client/deserialized_event.rb', line 9 def title @title end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
8 9 10 |
# File 'lib/event_store_client/deserialized_event.rb', line 8 def type @type end |
Instance Method Details
#content_type ⇒ Object
31 32 33 34 35 |
# File 'lib/event_store_client/deserialized_event.rb', line 31 def content_type return 'application/json' if EventStoreClient.config.adapter == :grpc 'application/vnd.eventstore.events+json' end |
#schema ⇒ Object
13 14 15 16 |
# File 'lib/event_store_client/deserialized_event.rb', line 13 def schema Dry::Schema.Params do end end |