Class: Selenium::WebDriver::Tor::Torrc

Inherits:
Object
  • Object
show all
Defined in:
lib/tor/torrc.rb

Overview

Respresentation of a torrc file

Constant Summary collapse

FIXED_CONFIG_KEYS =
%w[DataDirectory GeoIPFile GeoIPv6File SocksPort].freeze
INVALID_OPTION_REGEX =
%r{\[warn\] Failed to parse/validate config: (.*).$}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data_dir) ⇒ Torrc

Returns a new instance of Torrc.



16
17
18
19
20
21
# File 'lib/tor/torrc.rb', line 16

def initialize(data_dir)
  @data_dir = data_dir
  @torrc_file = File.new File.join(@data_dir, 'torrc'), 'w'
  @path = @torrc_file.path
  write_default_config
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



14
15
16
# File 'lib/tor/torrc.rb', line 14

def path
  @path
end

Instance Method Details

#configObject



23
24
25
# File 'lib/tor/torrc.rb', line 23

def config
  parse_config
end

#write_to_config(hash) ⇒ Object

Raises:

  • (ArgumentError)


27
28
29
30
31
32
33
# File 'lib/tor/torrc.rb', line 27

def write_to_config(hash)
  raise ArgumentError, 'Torrc#write_to_config takes a hash as argument' unless hash.is_a? Hash

  validate_torrc_options hash
  @torrc_file.write hash_to_config_string(config.merge(hash).merge(fixed_config))
  @torrc_file.rewind
end