Class: Crabfarm::Configuration

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

Defined Under Namespace

Classes: Option

Constant Summary collapse

OPTIONS =
[
  [:browser_dsl, :string, 'Default browser dsl used by states'],
  [:parser_engine, :string, 'Default parser engine used by parsers'],
  [: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.'],

  # 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.



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

def initialize
  reset
end

Instance Method Details

#crabtrap_configObject



110
111
112
113
114
115
# File 'lib/crabfarm/configuration.rb', line 110

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

#driver_configObject



85
86
87
88
89
90
91
92
93
94
95
# File 'lib/crabfarm/configuration.rb', line 85

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_hostObject



78
79
80
81
82
83
# File 'lib/crabfarm/configuration.rb', line 78

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_configObject



101
102
103
104
105
106
107
108
# File 'lib/crabfarm/configuration.rb', line 101

def phantom_config
  {
    load_images: phantom_load_images,
    proxy: proxy,
    ssl: phantom_ssl,
    bin_path: phantom_bin_path
  }
end

#phantom_mode_enabled?Boolean

Returns:

  • (Boolean)


97
98
99
# File 'lib/crabfarm/configuration.rb', line 97

def phantom_mode_enabled?
  driver.to_s == 'phantomjs'
end

#resetObject



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

def reset
  @values = {
    browser_dsl: :surfer,
    parser_engine: :nokogiri,
    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',
    crabtrap_bin_path: 'crabtrap',
    recorder_driver: :firefox
  }
end

#set(_options) ⇒ Object



74
75
76
# File 'lib/crabfarm/configuration.rb', line 74

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