Class: IpTracker::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/ip_tracker/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Config

Returns a new instance of Config.



6
7
8
9
# File 'lib/ip_tracker/config.rb', line 6

def initialize(options={})
  @settings_path = File.expand_path(IpTracker::DEFAULT_CONFIG_PATH)
  @config_hash = load_settings || {}
end

Instance Attribute Details

#config_hashObject

Returns the value of attribute config_hash.



4
5
6
# File 'lib/ip_tracker/config.rb', line 4

def config_hash
  @config_hash
end

#settings_pathObject

Returns the value of attribute settings_path.



4
5
6
# File 'lib/ip_tracker/config.rb', line 4

def settings_path
  @settings_path
end

Instance Method Details

#host_tokenObject



11
12
13
# File 'lib/ip_tracker/config.rb', line 11

def host_token
  config_hash["host_token"] || nil
end

#pidObject



15
16
17
# File 'lib/ip_tracker/config.rb', line 15

def pid
  config_hash["pid"] || nil
end

#update(attr, value) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/ip_tracker/config.rb', line 19

def update(attr, value)
  config_hash[attr.to_s] = value

  File.open(settings_path, 'w') do |out|
    YAML.dump(config_hash, out)
  end
end