class Librato::Config
Public Instance Methods
[](key)
click to toggle source
# File lib/librato/config.rb, line 5 def [](key) data[key] end
account(name)
click to toggle source
# File lib/librato/config.rb, line 15 def account(name) accounts.find { |account| account['name'] == name } end
accounts()
click to toggle source
# File lib/librato/config.rb, line 19 def accounts (data['accounts'] || {}).map do |name, account| env(name).merge(account).merge('name' => name).tap do |account| validate(account, name) end end end
spaces()
click to toggle source
# File lib/librato/config.rb, line 9 def spaces (options[:spaces] || data['spaces'] || []).map do |space| space.is_a?(Hash) ? space : { 'name' => space } end end
Private Instance Methods
data()
click to toggle source
# File lib/librato/config.rb, line 29 def data @data ||= read.tap do |data| data['dir'] = options[:dir] if options[:dir] end end
env(name)
click to toggle source
# File lib/librato/config.rb, line 43 def env(name) { 'user' => var(:user, name), 'token' => var(:token, name) } end
path()
click to toggle source
# File lib/librato/config.rb, line 39 def path options[:config] || '.librato.yml' end
read()
click to toggle source
# File lib/librato/config.rb, line 35 def read File.exist?(path) ? YAML.load_file(path) : {} end
validate(account, name)
click to toggle source
# File lib/librato/config.rb, line 51 def validate(account, name) %w(user token).each { |key| validate_presence(account, name, key) } end
validate_presence(hash, name, key)
click to toggle source
# File lib/librato/config.rb, line 55 def validate_presence(hash, name, key) hash[key] || fail("Unknown #{key} for #{name}.") end
var(account, name)
click to toggle source
# File lib/librato/config.rb, line 47 def var(account, name) ENV["LIBRATO_#{account.upcase}_#{name.upcase}"] end