Class: Crabfarm::BaseNavigator
- Inherits:
-
Object
- Object
- Crabfarm::BaseNavigator
- Extended by:
- Forwardable
- Includes:
- Assertion::Context, Base, Live::Interactable
- Defined in:
- lib/crabfarm/base_navigator.rb
Instance Attribute Summary collapse
-
#params ⇒ Object
readonly
Returns the value of attribute params.
Instance Method Summary collapse
- #browser(_name = nil) ⇒ Object
- #download(_url) ⇒ Object
- #fork_each(_enumerator, &_block) ⇒ Object
-
#initialize(_context, _params) ⇒ BaseNavigator
constructor
A new instance of BaseNavigator.
- #navigate(_name, _params = {}) ⇒ Object (also: #nav)
- #reduce(_target = nil, _options = {}) ⇒ Object (also: #reduce_with_defaults)
- #run ⇒ Object
Methods included from Live::Interactable
Methods included from Assertion::Context
Methods included from Base
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
#params ⇒ Object (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 ("th_session_#{session_id}", value, _block, mutex) end ThreadsWait.all_waits(*ths) end |
#navigate(_name, _params = {}) ⇒ Object Also known as:
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, ={}) if _target.is_a? Hash = _target _target = browser elsif _target.nil? _target = browser end reduce_using(.delete(:using) || self.class.name, _target, ) end |
#run ⇒ Object
38 39 40 |
# File 'lib/crabfarm/base_navigator.rb', line 38 def run raise NotImplementedError.new end |