Class: Cnfg::Base

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/cnfg/base.rb

Constant Summary collapse

@@settings =
{}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBase

Returns a new instance of Base.



11
12
13
# File 'lib/cnfg/base.rb', line 11

def initialize
  merge file.read
end

Instance Attribute Details

#barObject

Returns the value of attribute bar.



7
8
9
# File 'lib/cnfg/base.rb', line 7

def bar
  @bar
end

#fooObject

Returns the value of attribute foo.



7
8
9
# File 'lib/cnfg/base.rb', line 7

def foo
  @foo
end

Instance Method Details

#merge(settings) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'lib/cnfg/base.rb', line 15

def merge(settings)
  begin
    settings.each_pair{|k, v| send("#{k}=", v) }
  rescue NoMethodError => e
    method = e.message.match(/`(.*)\=/)[1]
    options = defaults.keys.map{|k| ":#{k}"}.join(', ')
    puts "No configuration setting for :#{method} in\n  #{options}\n\n"
    exit(0)
  end
end