Class: Crabfarm::Modes::Console::ConsoleDsl
- Inherits:
-
Object
- Object
- Crabfarm::Modes::Console::ConsoleDsl
- Defined in:
- lib/crabfarm/modes/console.rb
Instance Method Summary collapse
- #help ⇒ Object
-
#initialize(_manager) ⇒ ConsoleDsl
constructor
A new instance of ConsoleDsl.
- #navigate(_name = nil, _params = {}) ⇒ Object (also: #nav)
- #reload! ⇒ Object
- #reset ⇒ Object
- #snap(_name = nil, _params = {}) ⇒ Object
Constructor Details
#initialize(_manager) ⇒ ConsoleDsl
Returns a new instance of ConsoleDsl.
21 22 23 |
# File 'lib/crabfarm/modes/console.rb', line 21 def initialize(_manager) @manager = _manager end |
Instance Method Details
#help ⇒ Object
75 76 77 78 |
# File 'lib/crabfarm/modes/console.rb', line 75 def help puts "Ejem..." nil end |
#navigate(_name = nil, _params = {}) ⇒ Object Also known as:
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/crabfarm/modes/console.rb', line 37 def navigate(_name=nil, _params={}) if _name.nil? puts "Must provide a navigator name".color Colors::ERROR return end begin puts "Navigating...".color Colors::NOTICE output = @manager.navigate _name, _params puts JSON.pretty_generate(output.doc).gsub(/(^|\\n)/, ' ').color Colors::RESULT puts "Completed in #{output.elapsed.real} s".color Colors::NOTICE rescue Exception => e puts "#{e.to_s}".color Colors::ERROR puts e.backtrace end end |
#reload! ⇒ Object
25 26 27 28 29 |
# File 'lib/crabfarm/modes/console.rb', line 25 def reload! puts "Reloading crawler source".color Colors::NOTICE @manager.reload nil end |
#reset ⇒ Object
31 32 33 34 35 |
# File 'lib/crabfarm/modes/console.rb', line 31 def reset puts "Resetting crawling context".color Colors::NOTICE @manager.reset nil end |
#snap(_name = nil, _params = {}) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/crabfarm/modes/console.rb', line 55 def snap(_name=nil, _params={}) if _name.nil? puts "Must provide a navigator name".color Colors::ERROR return end begin puts "Navigating, waiting to hit a reducer...".color Colors::NOTICE require 'crabfarm/modes/shared/snapshot_decorator' Factories::Reducer.with_decorator Shared::SnapshotDecorator do @manager.navigate _name, _params end puts "Navigation completed".color Colors::NOTICE rescue Exception => e puts "#{e.to_s}".color Colors::ERROR puts e.backtrace end end |