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

AUTO =
'auto'
CONTROL_PORT =
'control_port'
GEOIP =
'geoip'
GEOIP6 =
'geoip6'
TORRC =
'torrc'
FIXED_CONFIG_KEYS =
%w[DataDirectory GeoIPFile GeoIPv6File SocksPort ControlPort ControlPortWriteToFile].freeze
INVALID_OPTION_REGEX =
%r{\[warn\] Failed to parse/validate config: (.*).$}
GEOIP_LOCATION_CHANGE_VER =
Gem::Version.new '16.0a4'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data_dir) ⇒ Torrc

Returns a new instance of Torrc.



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

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

Instance Attribute Details

#control_port_file_pathObject (readonly)

Returns the value of attribute control_port_file_path.



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

def control_port_file_path
  @control_port_file_path
end

#pathObject (readonly)

Returns the value of attribute path.



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

def path
  @path
end

Instance Method Details

#configObject



33
34
35
# File 'lib/tor/torrc.rb', line 33

def config
  parse_config
end

#write_to_config(hash) ⇒ Object

Raises:

  • (ArgumentError)


37
38
39
40
41
42
43
# File 'lib/tor/torrc.rb', line 37

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