Class: CommandPost::AggregateEvent
- Inherits:
-
Object
- Object
- CommandPost::AggregateEvent
- Defined in:
- lib/command_post/event_sourcing/aggregate_event.rb
Constant Summary collapse
- @@required_by_txn =
[ "aggregate_type", "aggregate_id", "event_description", "content", "transaction_id", "transacted" ]
Instance Attribute Summary collapse
-
#aggregate_id ⇒ Object
Returns the value of attribute aggregate_id.
-
#aggregate_type ⇒ Object
Returns the value of attribute aggregate_type.
-
#call_stack ⇒ Object
Returns the value of attribute call_stack.
-
#changes ⇒ Object
Returns the value of attribute changes.
-
#content ⇒ Object
Returns the value of attribute content.
-
#event_description ⇒ Object
Returns the value of attribute event_description.
-
#object ⇒ Object
Returns the value of attribute object.
-
#transacted ⇒ Object
Returns the value of attribute transacted.
-
#transaction_id ⇒ Object
Returns the value of attribute transaction_id.
-
#user_id ⇒ Object
Returns the value of attribute user_id.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ AggregateEvent
constructor
A new instance of AggregateEvent.
- #publish ⇒ Object
Constructor Details
#initialize ⇒ AggregateEvent
Returns a new instance of AggregateEvent.
19 20 21 22 23 |
# File 'lib/command_post/event_sourcing/aggregate_event.rb', line 19 def initialize @transaction_id = SequenceGenerator.transaction_id @transacted = Time.now @object = @changes = nil end |
Instance Attribute Details
#aggregate_id ⇒ Object
Returns the value of attribute aggregate_id.
7 8 9 |
# File 'lib/command_post/event_sourcing/aggregate_event.rb', line 7 def aggregate_id @aggregate_id end |
#aggregate_type ⇒ Object
Returns the value of attribute aggregate_type.
7 8 9 |
# File 'lib/command_post/event_sourcing/aggregate_event.rb', line 7 def aggregate_type @aggregate_type end |
#call_stack ⇒ Object
Returns the value of attribute call_stack.
7 8 9 |
# File 'lib/command_post/event_sourcing/aggregate_event.rb', line 7 def call_stack @call_stack end |
#changes ⇒ Object
Returns the value of attribute changes.
7 8 9 |
# File 'lib/command_post/event_sourcing/aggregate_event.rb', line 7 def changes @changes end |
#content ⇒ Object
Returns the value of attribute content.
7 8 9 |
# File 'lib/command_post/event_sourcing/aggregate_event.rb', line 7 def content @content end |
#event_description ⇒ Object
Returns the value of attribute event_description.
7 8 9 |
# File 'lib/command_post/event_sourcing/aggregate_event.rb', line 7 def event_description @event_description end |
#object ⇒ Object
Returns the value of attribute object.
7 8 9 |
# File 'lib/command_post/event_sourcing/aggregate_event.rb', line 7 def object @object end |
#transacted ⇒ Object
Returns the value of attribute transacted.
7 8 9 |
# File 'lib/command_post/event_sourcing/aggregate_event.rb', line 7 def transacted @transacted end |
#transaction_id ⇒ Object
Returns the value of attribute transaction_id.
7 8 9 |
# File 'lib/command_post/event_sourcing/aggregate_event.rb', line 7 def transaction_id @transaction_id end |
#user_id ⇒ Object
Returns the value of attribute user_id.
7 8 9 |
# File 'lib/command_post/event_sourcing/aggregate_event.rb', line 7 def user_id @user_id end |
Class Method Details
.get_history_by_aggregate_id(aggregate_id) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/command_post/event_sourcing/aggregate_event.rb', line 44 def self.get_history_by_aggregate_id aggregate_id hash = Hash.new cnt = 0 results = Array.new $DB.fetch("SELECT * FROM aggregate_events WHERE aggregate_id = ? order by transacted", aggregate_id ) do |row| hash = JSON.parse(row[:content]) results << "===================================================================================" results << "Version: #{cnt += 1} " results << "Event Description: #{row[:event_description]} " results << "Change Made By: #{row[:user_id]}" results << "------ change data ------------" results << hash.pretty_inspect end results end |
.publish(event) ⇒ Object
36 37 38 |
# File 'lib/command_post/event_sourcing/aggregate_event.rb', line 36 def self.publish event event.publish end |
Instance Method Details
#publish ⇒ Object
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/command_post/event_sourcing/aggregate_event.rb', line 25 def publish if changes save_event changes elsif object @aggregate_lookup_value = object.aggregate_lookup_value save_event object.to_h else raise 'Event has no state to publish.' end end |