Class: Dry::Facts::Event

Inherits:
Object
  • Object
show all
Defined in:
lib/dry/facts/event.rb

Constant Summary collapse

@@_aggregate_constructor =
false

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data: {}, metadata: {}) ⇒ Event

data



37
38
39
40
41
42
# File 'lib/dry/facts/event.rb', line 37

def initialize  data:     {},
                metadata: {}
  @metadata = () || Hash.new
  @data     = {}.merge(data) || Hash.new
  freeze
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



10
11
12
# File 'lib/dry/facts/event.rb', line 10

def data
  @data
end

#metadataObject (readonly)

Returns the value of attribute metadata.



11
12
13
# File 'lib/dry/facts/event.rb', line 11

def 
  @metadata
end

Class Method Details

.aggregate_constructorObject



14
15
16
# File 'lib/dry/facts/event.rb', line 14

def aggregate_constructor
  @@_aggregate_constructor = true
end

.from_h(h) ⇒ Object



18
19
20
21
22
23
# File 'lib/dry/facts/event.rb', line 18

def from_h(h)
  Object
  .const_get(h[:metadata][:type][:name])
  .new( data:     h[:data],
        metadata: h[:metadata])
end

Instance Method Details

#aggregate_idObject



56
57
58
# File 'lib/dry/facts/event.rb', line 56

def aggregate_id
  self.[:aggregate_id]
end

#idObject



44
45
46
# File 'lib/dry/facts/event.rb', line 44

def id
  @metadata[:id]
end

#to_hObject



60
61
62
63
# File 'lib/dry/facts/event.rb', line 60

def to_h
  { data:     self.data,
    metadata: self. }
end

#uuidObject



48
49
50
# File 'lib/dry/facts/event.rb', line 48

def uuid
  @metadata[:uuid]
end