Class: Handy::ConfigLoader

Inherits:
Object
  • Object
show all
Defined in:
lib/handy/config_loader.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename) ⇒ ConfigLoader

Returns a new instance of ConfigLoader.



8
9
10
# File 'lib/handy/config_loader.rb', line 8

def initialize(filename)
  @filename = filename
end

Instance Attribute Details

#filenameObject (readonly)

Returns the value of attribute filename.



6
7
8
# File 'lib/handy/config_loader.rb', line 6

def filename
  @filename
end

Instance Method Details

#load(key = Rails.env) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/handy/config_loader.rb', line 12

def load(key = Rails.env)
  file            = Rails.root.join('config', filename)
  return unless File.exist?(file)

  hash            = YAML.load(ERB.new(File.read(file)).result)

  common_hash = hash['common'] || {}
  env_hash = hash[key.to_s] || {}

  final_hash = common_hash.deep_merge(env_hash)
  ::Hashr.new(final_hash)
end