Class: Novel::SagaRepository

Inherits:
Object
  • Object
show all
Defined in:
lib/novel/saga_repository.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#adapterObject (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