class Phonocast::Configuration

Constants

CONFIGURABLE_KEYS
DEFAULTS

Public Class Methods

new(opts={}) click to toggle source
# File lib/phonocast/configuration.rb, line 29
def initialize(opts={})
  #attr_accessor for each CONFIGURABLE_KEY
  setup_attr_accessors

  #Start with a default config
  config = DEFAULTS.clone

  #YAML takes precedence to DEFAULTS
  yaml_path = opts.delete(:yaml_path) || 'phonocast.yaml'
  if File.exists?(yaml_path)

    yaml = YAML.load_file(yaml_path)
    yaml.keys.each do |key|
      yaml[(key.to_sym rescue key) || key] = yaml.delete(key)
    end

    config.merge!(yaml)
  end

  #opts take precedence to YAML
  config.merge!(opts)

  set_instance_variables(config)
end

Private Instance Methods

set_instance_variables(config) click to toggle source
# File lib/phonocast/configuration.rb, line 61
def set_instance_variables(config)
  CONFIGURABLE_KEYS.each do |key|
    instance_variable_set("@#{key.to_s}", config[key])
  end
end
setup_attr_accessors() click to toggle source
# File lib/phonocast/configuration.rb, line 55
def setup_attr_accessors
  CONFIGURABLE_KEYS.each do |key|
    self.class.__send__(:attr_accessor, key)
  end
end