Module: Euston::AggregateRoot::InstanceMethods
- Defined in:
- lib/euston/aggregate_root.rb
Instance Attribute Summary collapse
-
#aggregate_id ⇒ Object
readonly
Returns the value of attribute aggregate_id.
-
#log ⇒ Object
Returns the value of attribute log.
-
#stream ⇒ Object
readonly
Returns the value of attribute stream.
Instance Method Summary collapse
- #committed_messages ⇒ Object
- #consume_command(headers, command) ⇒ Object
- #consume_event_subscription(headers, event) ⇒ Object
- #has_uncommitted_changes? ⇒ Boolean
- #initial_version ⇒ Object
- #initialize(aggregate_id = nil) ⇒ Object
- #take_snapshot ⇒ Object
- #uncommitted_commands ⇒ Object
- #uncommitted_events ⇒ Object
- #uncommitted_headers ⇒ Object
- #version ⇒ Object
Instance Attribute Details
#aggregate_id ⇒ Object (readonly)
Returns the value of attribute aggregate_id.
25 26 27 |
# File 'lib/euston/aggregate_root.rb', line 25 def aggregate_id @aggregate_id end |
#log ⇒ Object
Returns the value of attribute log.
24 25 26 |
# File 'lib/euston/aggregate_root.rb', line 24 def log @log end |
#stream ⇒ Object (readonly)
Returns the value of attribute stream.
25 26 27 |
# File 'lib/euston/aggregate_root.rb', line 25 def stream @stream end |
Instance Method Details
#committed_messages ⇒ Object
35 36 37 |
# File 'lib/euston/aggregate_root.rb', line 35 def @committed_messages ||= Set.new end |
#consume_command(headers, command) ⇒ Object
51 52 53 |
# File 'lib/euston/aggregate_root.rb', line 51 def consume_command headers, command headers, command, :command, Euston::CommandHeaders, :send_command_to_method end |
#consume_event_subscription(headers, event) ⇒ Object
55 56 57 |
# File 'lib/euston/aggregate_root.rb', line 55 def consume_event_subscription headers, event headers, event, :event_subscription, Euston::EventHeaders, :send_event_subscription_to_method end |
#has_uncommitted_changes? ⇒ Boolean
31 32 33 |
# File 'lib/euston/aggregate_root.rb', line 31 def has_uncommitted_changes? !uncommitted_events.empty? end |
#initial_version ⇒ Object
27 28 29 |
# File 'lib/euston/aggregate_root.rb', line 27 def initial_version @initial_version ||= 0 end |
#initialize(aggregate_id = nil) ⇒ Object
19 20 21 22 |
# File 'lib/euston/aggregate_root.rb', line 19 def initialize aggregate_id = nil @aggregate_id = aggregate_id @log = Euston::NullLogger.instance end |
#take_snapshot ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/euston/aggregate_root.rb', line 59 def take_snapshot methods = self.class.instance_methods regex = self.class.take_snapshot_regexp methods = methods.map { |m| regex.match m }.compact raise "You tried to take a snapshot of #{self.class.name} but no snapshot method was found." if methods.empty? version = methods.map { |m| m[1].to_i }.sort.last name = self.class.take_snapshot_method_name version { :version => version, :payload => send(name) } end |
#uncommitted_commands ⇒ Object
39 40 41 |
# File 'lib/euston/aggregate_root.rb', line 39 def uncommitted_commands @uncommitted_commands ||= [] end |
#uncommitted_events ⇒ Object
43 44 45 |
# File 'lib/euston/aggregate_root.rb', line 43 def uncommitted_events @uncommitted_events ||= [] end |
#uncommitted_headers ⇒ Object
47 48 49 |
# File 'lib/euston/aggregate_root.rb', line 47 def uncommitted_headers @uncommitted_headers ||= {} end |
#version ⇒ Object
72 73 74 |
# File 'lib/euston/aggregate_root.rb', line 72 def version initial_version + uncommitted_events.length end |