Module: Sandthorn::AggregateRoot::Base
- Included in:
- Sandthorn::AggregateRoot
- Defined in:
- lib/sandthorn/aggregate_root_base.rb
Defined Under Namespace
Modules: ClassMethods
Instance Attribute Summary collapse
-
#aggregate_current_event_version ⇒ Object
(also: #aggregate_version)
readonly
Returns the value of attribute aggregate_current_event_version.
-
#aggregate_events ⇒ Object
readonly
Returns the value of attribute aggregate_events.
-
#aggregate_id ⇒ Object
(also: #id)
readonly
Returns the value of attribute aggregate_id.
-
#aggregate_originating_version ⇒ Object
readonly
Returns the value of attribute aggregate_originating_version.
-
#aggregate_trace_information ⇒ Object
readonly
Returns the value of attribute aggregate_trace_information.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #aggregate_base_initialize ⇒ Object
- #aggregate_trace(args) {|_self| ... } ⇒ Object
- #commit ⇒ Object (also: #record_event)
- #default_attributes ⇒ Object
- #save ⇒ Object
- #unsaved_events? ⇒ Boolean
Instance Attribute Details
#aggregate_current_event_version ⇒ Object (readonly) Also known as: aggregate_version
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_events ⇒ Object (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_id ⇒ Object (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_version ⇒ Object (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_trace_information ⇒ Object (readonly)
Returns the value of attribute aggregate_trace_information.
9 10 11 |
# File 'lib/sandthorn/aggregate_root_base.rb', line 9 def aggregate_trace_information @aggregate_trace_information end |
Instance Method Details
#==(other) ⇒ Object
37 38 39 |
# File 'lib/sandthorn/aggregate_root_base.rb', line 37 def ==(other) other.respond_to?(:aggregate_id) && aggregate_id == other.aggregate_id end |
#aggregate_base_initialize ⇒ Object
15 16 17 18 19 |
# File 'lib/sandthorn/aggregate_root_base.rb', line 15 def aggregate_base_initialize @aggregate_current_event_version = 0 @aggregate_originating_version = 0 @aggregate_events = [] end |
#aggregate_trace(args) {|_self| ... } ⇒ Object
45 46 47 48 49 |
# File 'lib/sandthorn/aggregate_root_base.rb', line 45 def aggregate_trace args @aggregate_trace_information = args yield self if block_given? @aggregate_trace_information = nil end |
#commit ⇒ Object Also known as: record_event
51 52 53 54 |
# File 'lib/sandthorn/aggregate_root_base.rb', line 51 def commit event_name = caller_locations(1,1)[0].label.gsub(/block ?(.*) in /, "") commit_with_event_name(event_name) end |
#default_attributes ⇒ Object
56 57 58 |
# File 'lib/sandthorn/aggregate_root_base.rb', line 56 def default_attributes #NOOP end |
#save ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/sandthorn/aggregate_root_base.rb', line 21 def save if aggregate_events.any? Sandthorn.save_events( aggregate_events, aggregate_id, self.class ) @aggregate_events = [] @aggregate_originating_version = @aggregate_current_event_version end Sandthorn.save_snapshot self if self.class.snapshot self end |
#unsaved_events? ⇒ Boolean
41 42 43 |
# File 'lib/sandthorn/aggregate_root_base.rb', line 41 def unsaved_events? aggregate_events.any? end |