Module: Apimaster::Setting

Defined in:
lib/apimaster/setting.rb

Constant Summary collapse

ENVIRONMENTS =

environments: development, test and production.

%w[test production development]
@@hashes =
{}

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.environmentObject

Returns the value of attribute environment.



14
15
16
# File 'lib/apimaster/setting.rb', line 14

def environment
  @environment
end

Class Method Details

.get(key, default = nil) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/apimaster/setting.rb', line 20

def get(key, default = nil)
  current = @@hashes
  key.split('.').each do |k|
    if current and current.is_a?(Hash)
      current = current.has_key?(k) ? current[k] : default
    end
  end
  current
end

.load_file(*paths) ⇒ Object

Loads the configuration from the YAML files whose paths are passed as arguments, filtering the settings for the current environment. Note that these paths can actually be globs.



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/apimaster/setting.rb', line 33

def load_file(*paths)
  paths.each do |pattern|
    Dir.glob(pattern) do |file|
      yaml = config_for_env(YAML.load_file(file)) || {}
      yaml.each_pair do |key, value|
        for_env = config_for_env(value)
        set key, for_env unless value and for_env.nil? and respond_to? key
      end
    end
  end
end

.set(key, value) ⇒ Object



16
17
18
# File 'lib/apimaster/setting.rb', line 16

def set(key, value)
  @@hashes[key] = value
end