class Balancer::Setting
Public Instance Methods
data()
click to toggle source
# File lib/balancer/setting.rb, line 8 def data settings_file = Balancer.profile || 'default' settings_file += ".yml" profile = yaml_file("#{Balancer.root}/.balancer/profiles/#{settings_file}") user = yaml_file("#{home}/.balancer/#{settings_file}") default_file = File.expand_path("../default/settings.yml", __FILE__) default = yaml_file(default_file) data = merge(default, user, profile) if ENV['DEBUG_SETTINGS'] puts "settings data:" pp data end data end
home()
click to toggle source
# File lib/balancer/setting.rb, line 42 def home # hack but fast ENV['TEST'] ? "spec/fixtures/home" : ENV['HOME'] end
merge(*hashes)
click to toggle source
# File lib/balancer/setting.rb, line 27 def merge(*hashes) hashes.inject({}) do |result, hash| # note: important to compact for keys with nil value result.deep_merge(hash.compact) end end
yaml_file(path)
click to toggle source
Any empty file will result in “false”. Lets ensure that an empty file loads an empty hash instead.
# File lib/balancer/setting.rb, line 36 def yaml_file(path) # puts "yaml_file #{path}" return {} unless File.exist?(path) YAML.load_file(path) || {} end