Class: Crabfarm::Context

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/crabfarm/context.rb

Direct Known Subclasses

CrabtrapContext

Instance Method Summary collapse

Constructor Details

#initializeContext

Returns a new instance of Context.



9
10
11
12
# File 'lib/crabfarm/context.rb', line 9

def initialize
  @store = StateStore.new
  @loaded = false
end

Instance Method Details

#loadObject



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

def load
  unless @loaded
    init_phantom_if_required
    @pool = DriverBucketPool.new build_driver_factory
    @loaded = true
  end
end

#releaseObject



35
36
37
38
39
40
41
# File 'lib/crabfarm/context.rb', line 35

def release
  if @loaded
    @pool.release
    @phantom.stop unless @phantom.nil?
    @loaded = false
  end
end

#resetObject



29
30
31
32
33
# File 'lib/crabfarm/context.rb', line 29

def reset
  load
  @store.reset
  @pool.reset
end

#run_state(_name, _params = {}) ⇒ Object



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

def run_state(_name, _params={})
  load
  state = LoaderService.load_state(_name).new @pool, @store, _params
  state.crawl
  state
end