Class: SimpleEventSourcing::Events::StoredEvent

Inherits:
Object
  • Object
show all
Defined in:
lib/simple_event_sourcing/events/stored_event.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ StoredEvent

Returns a new instance of StoredEvent.



9
10
11
12
13
14
# File 'lib/simple_event_sourcing/events/stored_event.rb', line 9

def initialize(args)
  @aggregate_id = args[:aggregate_id]
  @occurred_on = args[:occurred_on]
  @event_type = args[:event_type]
  @event_data = args[:event_data]
end

Instance Attribute Details

#aggregate_idObject (readonly)

Returns the value of attribute aggregate_id.



7
8
9
# File 'lib/simple_event_sourcing/events/stored_event.rb', line 7

def aggregate_id
  @aggregate_id
end

#event_dataObject (readonly)

Returns the value of attribute event_data.



7
8
9
# File 'lib/simple_event_sourcing/events/stored_event.rb', line 7

def event_data
  @event_data
end

#event_typeObject (readonly)

Returns the value of attribute event_type.



7
8
9
# File 'lib/simple_event_sourcing/events/stored_event.rb', line 7

def event_type
  @event_type
end

#occurred_onObject (readonly)

Returns the value of attribute occurred_on.



7
8
9
# File 'lib/simple_event_sourcing/events/stored_event.rb', line 7

def occurred_on
  @occurred_on
end

Class Method Details

.create_from_json(json) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/simple_event_sourcing/events/stored_event.rb', line 20

def self.create_from_json(json)

  stored_event_hash = JSON.parse(json)

  self.new(
    aggregate_id: stored_event_hash['aggregate_id'],
    occurred_on: stored_event_hash['occurred_on'],
    event_type: stored_event_hash['event_type'],
    event_data: stored_event_hash['event_data']
  )

end

Instance Method Details

#to_json(*a) ⇒ Object



16
17
18
# File 'lib/simple_event_sourcing/events/stored_event.rb', line 16

def to_json(*a)
  {"aggregate_id" => @aggregate_id, "occurred_on" => @occurred_on.to_i, "event_type" => @event_type.to_s, "event_data" => @event_data }.to_json(*a)
end