Module: Jouba::Aggregate::ClassMethods
- Defined in:
- lib/jouba/aggregate.rb
Instance Method Summary collapse
- #find(uuid) ⇒ Object
- #key_from_uuid(uuid) ⇒ Object
- #replay(events) ⇒ Object
- #stream(uuid, params = {}) ⇒ Object
Instance Method Details
#find(uuid) ⇒ Object
63 64 65 66 |
# File 'lib/jouba/aggregate.rb', line 63 def find(uuid) key = key_from_uuid(uuid) Jouba.Cache.fetch(key) { replay stream(uuid) } end |
#key_from_uuid(uuid) ⇒ Object
72 73 74 |
# File 'lib/jouba/aggregate.rb', line 72 def key_from_uuid(uuid) Jouba.Key.serialize(name, uuid) # => default "ClassName.id" end |
#replay(events) ⇒ Object
59 60 61 |
# File 'lib/jouba/aggregate.rb', line 59 def replay(events) new.tap { |aggregate| Array(events).each { |event| aggregate.replay(event) } } end |
#stream(uuid, params = {}) ⇒ Object
68 69 70 |
# File 'lib/jouba/aggregate.rb', line 68 def stream(uuid, params = {}) Jouba.Event.stream(key_from_uuid(uuid), params) end |