class Flyml::Configuration

Attributes

env[R]
root[R]

Public Class Methods

new(root, env) click to toggle source
# File lib/flyml/configuration.rb, line 5
def initialize(root, env)
  @root = root
  @env = env
end

Public Instance Methods

[](file) click to toggle source
# File lib/flyml/configuration.rb, line 10
def [](file)
  @config ||= {}
  @config[file.to_sym] = load_settings(file) unless @config[file.to_sym]
  @config[file.to_sym]
end

Private Instance Methods

file_path(name) click to toggle source
# File lib/flyml/configuration.rb, line 23
def file_path(name)
  File.join(root, 'config', "#{name}.yml")
end
load_file_content(path) click to toggle source
# File lib/flyml/configuration.rb, line 36
def load_file_content(path)
  File.read(path)
end
load_settings(file) click to toggle source
# File lib/flyml/configuration.rb, line 27
def load_settings(file)
  path = file_path(file)
  return unless File.exist?(path)

  content = load_file_content(path)
  data = YAML.load(content)
  prepare_hash(data)
end
prepare_hash(data) click to toggle source
# File lib/flyml/configuration.rb, line 18
def prepare_hash(data)
  hash = data.is_a?(Hash) && data[env.to_s] ? data[env.to_s] : {}
  Values.build(hash)
end