Class: Crabfarm::BaseNavigator

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Assertion::Context, Base, Live::Interactable
Defined in:
lib/crabfarm/base_navigator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Live::Interactable

#highlight, included

Methods included from Assertion::Context

#assert

Methods included from Base

#debugger

Constructor Details

#initialize(_context, _params) ⇒ BaseNavigator

Returns a new instance of BaseNavigator.



19
20
21
22
# File 'lib/crabfarm/base_navigator.rb', line 19

def initialize(_context,  _params)
  @context = _context
  @params = _params
end

Instance Attribute Details

#paramsObject (readonly)

Returns the value of attribute params.



14
15
16
# File 'lib/crabfarm/base_navigator.rb', line 14

def params
  @params
end

Instance Method Details

#browser(_name = nil) ⇒ Object



30
31
32
# File 'lib/crabfarm/base_navigator.rb', line 30

def browser(_name=nil)
  @context.pool.driver(_name)
end

#download(_url) ⇒ Object



34
35
36
# File 'lib/crabfarm/base_navigator.rb', line 34

def download(_url)
  @context.http.get(_url).body
end

#fork_each(_enumerator, &_block) ⇒ Object



55
56
57
58
59
60
61
62
63
# File 'lib/crabfarm/base_navigator.rb', line 55

def fork_each(_enumerator, &_block)
  session_id = 0
  mutex = Mutex.new
  ths = _enumerator.map do |value|
    session_id += 1
    start_forked_navigation("th_session_#{session_id}", value, _block, mutex)
  end
  ThreadsWait.all_waits(*ths)
end


24
25
26
# File 'lib/crabfarm/base_navigator.rb', line 24

def navigate(_name, _params={})
  TransitionService.transition(@context, _name, params.merge(_params)).navigator
end

#reduce(_target = nil, _options = {}) ⇒ Object Also known as: reduce_with_defaults



42
43
44
45
46
47
48
49
50
51
# File 'lib/crabfarm/base_navigator.rb', line 42

def reduce(_target=nil, _options={})
  if _target.is_a? Hash
    _options = _target
    _target = browser
  elsif _target.nil?
    _target = browser
  end

  reduce_using(_options.delete(:using) || self.class.name, _target, _options)
end

#runObject

Raises:

  • (NotImplementedError)


38
39
40
# File 'lib/crabfarm/base_navigator.rb', line 38

def run
  raise NotImplementedError.new
end