Method: Tor::Config.load

Defined in:
lib/tor/config.rb

.load(filename, options = {}) ⇒ Config

Loads the configuration options from a Tor configuration file.

Parameters:

  • filename (String, #to_s)
  • options (Hash{Symbol => Object}) (defaults to: {})

Returns:

Since:

  • 0.1.2



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/tor/config.rb', line 45

def self.load(filename, options = {})
  self.new(options) do |config|
    File.open(filename.to_s, 'rb') do |file|
      file.each_line do |line|
        case line = line.strip.chomp.strip
          when ''   then next # skip empty lines
          when /^#/ then next # skip comments
          else line = line.split('#').first.strip
        end
        # TODO: support for unquoting and unescaping values
        config << line.split(/\s+/, 2)
      end
    end
  end
end