Module: Sandthorn::AggregateRoot::Base

Included in:
DirtyHashy
Defined in:
lib/sandthorn/aggregate_root_base.rb

Defined Under Namespace

Modules: ClassMethods

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#aggregate_current_event_versionObject (readonly)

Returns the value of attribute aggregate_current_event_version.



7
8
9
# File 'lib/sandthorn/aggregate_root_base.rb', line 7

def aggregate_current_event_version
  @aggregate_current_event_version
end

#aggregate_eventsObject (readonly)

Returns the value of attribute aggregate_events.



6
7
8
# File 'lib/sandthorn/aggregate_root_base.rb', line 6

def aggregate_events
  @aggregate_events
end

#aggregate_idObject (readonly) Also known as: id

Returns the value of attribute aggregate_id.



5
6
7
# File 'lib/sandthorn/aggregate_root_base.rb', line 5

def aggregate_id
  @aggregate_id
end

#aggregate_originating_versionObject (readonly)

Returns the value of attribute aggregate_originating_version.



8
9
10
# File 'lib/sandthorn/aggregate_root_base.rb', line 8

def aggregate_originating_version
  @aggregate_originating_version
end

#aggregate_stored_serialized_objectObject (readonly)

Returns the value of attribute aggregate_stored_serialized_object.



9
10
11
# File 'lib/sandthorn/aggregate_root_base.rb', line 9

def aggregate_stored_serialized_object
  @aggregate_stored_serialized_object
end

Instance Method Details

#aggregate_base_initializeObject



14
15
16
17
18
# File 'lib/sandthorn/aggregate_root_base.rb', line 14

def aggregate_base_initialize
  @aggregate_current_event_version = 0
  @aggregate_originating_version = 0
  @aggregate_events = []
end

#aggregate_trace(args) {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:



52
53
54
55
56
# File 'lib/sandthorn/aggregate_root_base.rb', line 52

def aggregate_trace args
  @aggregate_trace_information = args
  yield self
  @aggregate_trace_information = nil
end

#allObject



49
50
# File 'lib/sandthorn/aggregate_root_base.rb', line 49

def all
end

#commit(*args, method_name: nil) ⇒ Object Also known as: record_event



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/sandthorn/aggregate_root_base.rb', line 33

def commit *args, method_name: nil
  increase_current_aggregate_version!
  method_name = caller_locations(1,1)[0].label unless method_name
  aggregate_attribute_deltas = get_delta
  
  unless aggregate_attribute_deltas.empty?
    data = {:method_name => method_name, :method_args => args, :attribute_deltas => aggregate_attribute_deltas}
    data.merge!({trace: @aggregate_trace_information}) unless @aggregate_trace_information.nil? || @aggregate_trace_information.empty?
    @aggregate_events << ({:aggregate_version => @aggregate_current_event_version, :event_name => method_name, :event_args => data})
  end
  self
end

#saveObject



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

def save
  aggregate_events.each do |event|
    event[:event_data] = Sandthorn.serialize event[:event_args]
    event[:event_args] = nil #Not send extra data over the wire
  end
  unless aggregate_events.empty?
    Sandthorn.save_events( aggregate_events, aggregate_originating_version, aggregate_id, self.class.name)
    @aggregate_events = []
    @aggregate_originating_version = @aggregate_current_event_version
  end
  self
end