class Dandelion::Config

Attributes

data[R]
path[R]

Public Class Methods

new(options = {}) click to toggle source
# File lib/dandelion/config.rb, line 8
def initialize(options = {})
  @path = options[:path]
  @data = @path ? load : (options[:data] || {})
end

Public Instance Methods

[](key) click to toggle source
# File lib/dandelion/config.rb, line 13
def [](key)
  @data[key] || @data[key.to_s]
end
[]=(key, value) click to toggle source
# File lib/dandelion/config.rb, line 17
def []=(key, value)
  @data[key.to_s] = value
end
defaults(values) click to toggle source
# 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

Private Instance Methods

content() click to toggle source
# File lib/dandelion/config.rb, line 37
def content
  IO.read(path)
end
load() click to toggle source
# File lib/dandelion/config.rb, line 33
def load
  YAML.load(template.result(binding)) || {}
end
template() click to toggle source
# File lib/dandelion/config.rb, line 41
def template
  ERB.new(content)
end