Class: Crabfarm::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/crabfarm/configuration.rb

Defined Under Namespace

Classes: Option

Constant Summary collapse

OPTIONS =
[
  # Global options
  [:browser, ['chrome', 'firefox', 'phantomjs', 'remote'], 'Browser engine to be used by navigators, common options: phantomjs, chrome, firefox, remote.'],
  [:parser, :string, 'Default parser engine used by reducers'],
  [: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'],

  # Webdriver configuration parameters
  [:webdriver_host, :string, 'Remote host, only available in driver: remote'],
  [:webdriver_port, :integer, 'Remote port, only available in driver: remote'],
  [:webdriver_capabilities, :mixed, 'Driver capabilities, depends on selected driver.'],
  [:webdriver_remote_timeout, :float, 'Request timeout in seconds, only available for remote or phatomjs driver.'],
  [:webdriver_window_width, :integer, 'Initial browser window width.'],
  [:webdriver_window_height, :integer, 'Initial browser window height.'],
  [:webdriver_dsl, :string, 'Webdriver wrapper to use, built in options are watir and surfer'],

  # 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.'],

  # Crabtrap launcher configuration
  [:crabtrap_bin_path, :string, 'Crabtrap binary path.'],

  # Recorder configuration
  [:recorder_driver, :string, 'Recorder driver name, defaults to \'firefox\'']
]
.map { |o| Option.new(*o) }

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



46
47
48
# File 'lib/crabfarm/configuration.rb', line 46

def initialize
  reset
end

Instance Method Details

#crabtrap_configObject



83
84
85
86
87
88
# File 'lib/crabfarm/configuration.rb', line 83

def crabtrap_config
  {
    bin_path: crabtrap_bin_path,
    proxy: proxy
  }
end

#resetObject



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/crabfarm/configuration.rb', line 50

def reset
  @values = {
    browser: 'phantomjs',
    parser: :nokogiri,
    driver_factory: nil,
    log_path: nil,
    proxy: nil,
    webdriver_capabilities: nil,
    webdriver_host: 'localhost',
    webdriver_port: '8080',
    webdriver_remote_timeout: 120,
    webdriver_window_width: 1280,
    webdriver_window_height: 800,
    webdriver_dsl: :watir,
    phantom_load_images: false,
    phantom_ssl: 'any',
    phantom_bin_path: 'phantomjs',
    crabtrap_bin_path: 'crabtrap',
    recorder_driver: :firefox
  }
end

#set(_options) ⇒ Object



72
73
74
# File 'lib/crabfarm/configuration.rb', line 72

def set(_options)
  @values.merge! _options
end

#webdriver_remote_hostObject



76
77
78
79
80
81
# File 'lib/crabfarm/configuration.rb', line 76

def webdriver_remote_host
  if webdriver_host then nil
  elsif webdriver_port then "http://#{webdriver_host}"
  else "http://#{webdriver_host}:#{webdriver_port}"
  end
end