class Truth::Config
Attributes
config_folder[RW]
Public Class Methods
new(folder = '/etc/truth')
click to toggle source
# File lib/truth/config.rb, line 4 def initialize(folder = '/etc/truth') self.config_folder = folder end
Public Instance Methods
add_info(key, value)
click to toggle source
# File lib/truth/config.rb, line 44 def add_info(key, value) data[key] = value persist_data end
add_roles(roles)
click to toggle source
# File lib/truth/config.rb, line 26 def add_roles(roles) data['roles'] = (current_roles + roles).flatten.uniq persist_data end
config()
click to toggle source
# File lib/truth/config.rb, line 66 def config @config ||= read_config('config.yml') end
current_roles()
click to toggle source
# File lib/truth/config.rb, line 36 def current_roles data['roles'] || [] end
data()
click to toggle source
# File lib/truth/config.rb, line 40 def data @data ||= read_config('data.yml') end
data=(obj)
click to toggle source
# File lib/truth/config.rb, line 58 def data=(obj) write_config('data.yml', obj) end
environment()
click to toggle source
# File lib/truth/config.rb, line 12 def environment self.config['environment'] end
full_config_path(file)
click to toggle source
# File lib/truth/config.rb, line 70 def full_config_path(file) File.expand_path(File.join(config_folder,file)) end
hostname()
click to toggle source
reads the systems hostname, can be overridden in the config.yml
# File lib/truth/config.rb, line 17 def hostname self.config['hostname'] || `hostname`.strip end
info(key)
click to toggle source
# File lib/truth/config.rb, line 54 def info(key) data[key] end
persist_data()
click to toggle source
# File lib/truth/config.rb, line 62 def persist_data write_config('data.yml', @data) end
read_config(filename)
click to toggle source
# File lib/truth/config.rb, line 74 def read_config(filename) full_path = File.join(config_folder, filename) raise "file #{full_path} not found!" unless File.exist?(full_path) return YAML.load(File.read(full_path)) || {} end
redis_client()
click to toggle source
# File lib/truth/config.rb, line 22 def redis_client @redis_client ||= EM::Hiredis::Client.connect(redis_ip) end
redis_ip()
click to toggle source
# File lib/truth/config.rb, line 8 def redis_ip self.config['redis_ip'] end
remove_info(key)
click to toggle source
# File lib/truth/config.rb, line 49 def remove_info(key) data.delete key persist_data end
remove_roles(roles)
click to toggle source
# File lib/truth/config.rb, line 31 def remove_roles(roles) data['roles'] = (current_roles - roles).flatten.uniq persist_data end
write_config(filename, content)
click to toggle source
# File lib/truth/config.rb, line 80 def write_config(filename, content) full_path = File.join(config_folder, filename) raise unless File.exist?(full_path) content = YAML.dump(content) unless content.is_a? String File.open(full_path, 'w') do |f| f.puts content end end