Class: Docs::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/docs/config.rb

Instance Method Summary collapse

Constructor Details

#initialize(config_file = 'config.yaml') ⇒ Config

Returns a new instance of Config.



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/docs/config.rb', line 5

def initialize(config_file = 'config.yaml')
  @config = YAML.load(File.read(config_file))
  @environment = ENV['DOCS_ENV'] || 'production'

  begin
    env = @config.delete('environment')[@environment]
  rescue NoMethodError 
    env = {}
  end

  @config.merge!(env)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/docs/config.rb', line 18

def method_missing(name, *args, &block)
  name = name.to_s
  if @config.has_key?(name)
    @config[name]
  else
    super(name, *args, &block)
  end
end