Class: Novel::SagaRepository
- Inherits:
-
Object
- Object
- Novel::SagaRepository
- Defined in:
- lib/novel/saga_repository.rb
Instance Attribute Summary collapse
-
#adapter ⇒ Object
readonly
Returns the value of attribute adapter.
Instance Method Summary collapse
- #find_or_create_context(saga_id, params) ⇒ Object
-
#initialize(adapter: RepositoryAdapters::Memory.new) ⇒ SagaRepository
constructor
A new instance of SagaRepository.
- #persist_context(context, **params) ⇒ Object
Constructor Details
#initialize(adapter: RepositoryAdapters::Memory.new) ⇒ SagaRepository
Returns a new instance of SagaRepository.
8 9 10 |
# File 'lib/novel/saga_repository.rb', line 8 def initialize(adapter: RepositoryAdapters::Memory.new) @adapter = adapter end |
Instance Attribute Details
#adapter ⇒ Object (readonly)
Returns the value of attribute adapter.
6 7 8 |
# File 'lib/novel/saga_repository.rb', line 6 def adapter @adapter end |
Instance Method Details
#find_or_create_context(saga_id, params) ⇒ Object
12 13 14 |
# File 'lib/novel/saga_repository.rb', line 12 def find_or_create_context(saga_id, params) adapter.find_context(saga_id) || adapter.persist_context(saga_id, Context.new(id: saga_id, params: params)) end |
#persist_context(context, **params) ⇒ Object
16 17 18 19 20 |
# File 'lib/novel/saga_repository.rb', line 16 def persist_context(context, **params) new_context = Context.new({ **context.to_h, **params }) adapter.persist_context(context.id, new_context) new_context end |