class Sonic::Setting

Public Instance Methods

data() click to toggle source
# File lib/sonic/setting.rb, line 9
def data
  settings_file = Sonic.profile || 'default'
  settings_file += ".yml"

  project = yaml_file("#{Sonic.root}/.sonic/#{settings_file}")
  user = yaml_file("#{home}/.sonic/#{settings_file}")
  default_file = File.expand_path("../default/settings.yml", __FILE__)
  default = yaml_file(default_file)

  data = merge(default, user, project)

  if ENV['DEBUG_SETTINGS']
    puts "settings data:"
    pp data
  end
  data
end
home() click to toggle source
# File lib/sonic/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/sonic/setting.rb, line 28
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/sonic/setting.rb, line 37
def yaml_file(path)
  return {} unless File.exist?(path)
  YAML.load_file(path) || {}
end