Class: Crabfarm::Configuration
- Inherits:
-
Object
- Object
- Crabfarm::Configuration
- Defined in:
- lib/crabfarm/configuration.rb
Defined Under Namespace
Classes: Option
Constant Summary collapse
- OPTIONS =
[ [:browser_dsl, :string, 'Default browser dsl used by parsers and states'], [:output_builder, :string, 'Default json output builder used by states'], [:driver_factory, :mixed, 'Driver factory, disabled if phantom_mode is used'], [:log_path, :string, 'Path where logs should be stored'], [:proxy, :string, 'If given, a proxy is used to connect to the internet if driver supports it'], # Default driver configuration parameters [:driver, ['chrome', 'firefox', 'phantomjs', 'remote'], 'Webdriver to be user, common options: chrome, firefox, phantomjs, remote.'], [:driver_host, :string, 'Remote host, only available in driver: remote'], [:driver_port, :integer, 'Remote port, only available in driver: remote'], [:driver_capabilities, :mixed, 'Driver capabilities, depends on selected driver.'], [:driver_remote_timeout, :float, 'Request timeout in seconds, only available for remote or phatomjs driver.'], [:driver_window_width, :integer, 'Initial browser window width.'], [:driver_window_height, :integer, 'Initial browser window height.'], # Phantom launcher configuration [:phantom_load_images, :boolean, 'Phantomjs image loading, only for phantomjs driver.'], [:phantom_ssl, ['sslv3', 'sslv2', 'tlsv1', 'any'], 'Phantomjs ssl mode: sslv3, sslv2, tlsv1 or any, only for phantomjs driver.'], [:phantom_bin_path, :string, 'Phantomjs binary path, only for phantomjs driver.'], [:phantom_lock_file, :string, 'Phantomjs lock file path, only for phantomjs driver.'], # Crabtrap launcher configuration [:crabtrap_bin_path, :string, 'Crabtrap binary path.'], [:crabtrap_port, :integer, 'Crabtrap port, defaults to 4000.'], [:crabtrap_mode, ['capture', 'replay'], 'Crabtrap operation mode.'] ] .map { |o| Option.new *o }
Instance Method Summary collapse
- #crabtrap_config ⇒ Object
- #driver_config ⇒ Object
- #driver_remote_host ⇒ Object
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
- #phantom_config ⇒ Object
- #phantom_mode_enabled? ⇒ Boolean
- #reset ⇒ Object
- #set(_options) ⇒ Object
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
46 47 48 |
# File 'lib/crabfarm/configuration.rb', line 46 def initialize reset end |
Instance Method Details
#crabtrap_config ⇒ Object
114 115 116 117 118 119 120 |
# File 'lib/crabfarm/configuration.rb', line 114 def crabtrap_config { bin_path: crabtrap_bin_path, port: crabtrap_port, proxy: proxy } end |
#driver_config ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/crabfarm/configuration.rb', line 87 def driver_config { name: driver, proxy: proxy, capabilities: driver_capabilities, remote_host: driver_remote_host, remote_timeout: driver_remote_timeout, window_width: driver_window_width, window_height: driver_window_height } end |
#driver_remote_host ⇒ Object
80 81 82 83 84 85 |
# File 'lib/crabfarm/configuration.rb', line 80 def driver_remote_host if driver_host then nil elsif driver_port then "http://#{driver_host}" else "http://#{driver_host}:#{driver_port}" end end |
#phantom_config ⇒ Object
103 104 105 106 107 108 109 110 111 112 |
# File 'lib/crabfarm/configuration.rb', line 103 def phantom_config { load_images: phantom_load_images, proxy: proxy, ssl: phantom_ssl, bin_path: phantom_bin_path, lock_file: phantom_lock_file, log_file: log_path ? File.join(log_path, 'phantom.log') : nil } end |
#phantom_mode_enabled? ⇒ Boolean
99 100 101 |
# File 'lib/crabfarm/configuration.rb', line 99 def phantom_mode_enabled? driver.to_s == 'phantomjs' end |
#reset ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/crabfarm/configuration.rb', line 50 def reset @values = { browser_dsl: :surfer, output_builder: :hash, driver_factory: nil, log_path: nil, proxy: nil, driver: 'phantomjs', driver_capabilities: Selenium::WebDriver::Remote::Capabilities.firefox, driver_host: 'localhost', driver_port: '8080', driver_remote_timeout: 120, driver_window_width: 1280, driver_window_height: 800, phantom_load_images: false, phantom_ssl: 'any', phantom_bin_path: 'phantomjs', phantom_lock_file: nil, crabtrap_bin_path: 'crabtrap', crabtrap_port: 4000 } end |
#set(_options) ⇒ Object
76 77 78 |
# File 'lib/crabfarm/configuration.rb', line 76 def set() @values.merge! end |