Class: Dandelion::Config

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Config



7
8
9
10
# File 'lib/dandelion/config.rb', line 7

def initialize(options = {})
  @path = options[:path]
  @data = @path ? load : (options[:data] || {})
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



5
6
7
# File 'lib/dandelion/config.rb', line 5

def data
  @data
end

#pathObject (readonly)

Returns the value of attribute path.



5
6
7
# File 'lib/dandelion/config.rb', line 5

def path
  @path
end

Instance Method Details

#[](key) ⇒ Object



12
13
14
# File 'lib/dandelion/config.rb', line 12

def [](key)
  @data[key] || @data[key.to_s]
end

#[]=(key, value) ⇒ Object



16
17
18
# File 'lib/dandelion/config.rb', line 16

def []=(key, value)
  @data[key.to_s] = value
end

#defaults(values) ⇒ Object



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

def defaults(values)
  values.each do |k, v|
    if self[k].nil?
      self[k] = v
    end
  end

  self
end