Module: Sandthorn::AggregateRootSnapshot
- Defined in:
- lib/sandthorn/aggregate_root_snapshot.rb
Instance Attribute Summary collapse
-
#aggregate_snapshot ⇒ Object
readonly
Returns the value of attribute aggregate_snapshot.
Instance Method Summary collapse
Instance Attribute Details
#aggregate_snapshot ⇒ Object (readonly)
Returns the value of attribute aggregate_snapshot.
3 4 5 |
# File 'lib/sandthorn/aggregate_root_snapshot.rb', line 3 def aggregate_snapshot @aggregate_snapshot end |
Instance Method Details
#aggregate_snapshot! ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/sandthorn/aggregate_root_snapshot.rb', line 5 def aggregate_snapshot! if @aggregate_events.count > 0 raise "Can't take snapshot on object with unsaved events" end @aggregate_snapshot = { :event_name => "aggregate_set_from_snapshot", :event_args => [self], :aggregate_version => @aggregate_current_event_version } end |
#save_snapshot ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/sandthorn/aggregate_root_snapshot.rb', line 18 def save_snapshot raise "No snapshot has been created!" unless @aggregate_snapshot @aggregate_snapshot[:event_data] = Sandthorn.serialize @aggregate_snapshot[:event_args] @aggregate_snapshot[:event_args] = nil Sandthorn.save_snapshot @aggregate_snapshot, @aggregate_id, self.class.name @aggregate_snapshot = nil end |