Class: EventStoreClient::DeserializedEvent

Inherits:
Object
  • Object
show all
Defined in:
lib/event_store_client/deserialized_event.rb

Constant Summary collapse

InvalidDataError =
Class.new(StandardError)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**args) ⇒ DeserializedEvent

Returns a new instance of DeserializedEvent.

Raises:



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/event_store_client/deserialized_event.rb', line 20

def initialize(**args)
  validation = schema.call(args[:data] || {})
  raise InvalidDataError.new(message: validation.errors.to_h) if validation.errors.any?

  @data = args.fetch(:data) { {} }
   = args.fetch(:metadata) { {} }.merge(
    'type' => self.class.name,
    'content-type' => 'application/vnd.eventstore.events+json'
  )
  @type = args[:type] || self.class.name
  @title = args[:title]
  @id = args[:id]
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



12
13
14
# File 'lib/event_store_client/deserialized_event.rb', line 12

def data
  @data
end

#idObject (readonly)

Returns the value of attribute id.



9
10
11
# File 'lib/event_store_client/deserialized_event.rb', line 9

def id
  @id
end

#metadataObject (readonly)

Returns the value of attribute metadata.



13
14
15
# File 'lib/event_store_client/deserialized_event.rb', line 13

def 
  
end

#titleObject (readonly)

Returns the value of attribute title.



11
12
13
# File 'lib/event_store_client/deserialized_event.rb', line 11

def title
  @title
end

#typeObject (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

#schemaObject



15
16
17
18
# File 'lib/event_store_client/deserialized_event.rb', line 15

def schema
  Dry::Schema.Params do
  end
end