Module: Crabfarm::ContextFactory

Extended by:
ContextFactory
Included in:
ContextFactory
Defined in:
lib/crabfarm/context_factory.rb

Instance Method Summary collapse

Instance Method Details

#build_context(_memento = nil) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/crabfarm/context_factory.rb', line 14

def build_context(_memento=nil)
  if _memento.nil?
    Crabfarm::Context.new
  else
    load_crabtrap_context _memento
  end
end

#load_crabtrap_context(_memento) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/crabfarm/context_factory.rb', line 22

def load_crabtrap_context(_memento)
  require 'crabfarm/crabtrap_context'
  require 'crabfarm/modes/recorder/memento'
  m_path = Modes::Recorder::Memento.memento_path _memento
  raise ResourceNotFoundError.new "Could not find memento '#{_name}'" unless File.exists? m_path
  Crabfarm::CrabtrapContext.new :replay, m_path
end

#with_context(_memento = nil) ⇒ Object



4
5
6
7
8
9
10
11
12
# File 'lib/crabfarm/context_factory.rb', line 4

def with_context(_memento=nil)
  ctx = build_context(_memento)
  begin
    ctx.prepare
    yield ctx
  ensure
    ctx.release
  end
end