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

Returns a new instance of Config.



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

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

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



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

def data
  @data
end

#pathObject (readonly)

Returns the value of attribute path.



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

def path
  @path
end

Instance Method Details

#[](key) ⇒ Object



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

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

#[]=(key, value) ⇒ Object



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

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

#defaults(values) ⇒ Object



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

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

  self
end