class Quandl::Configuration

Attributes

config_env[RW]
config_file[RW]

Public Class Methods

attribute_names() click to toggle source
# File lib/quandl/configuration.rb, line 37
def attribute_names
  @attribute_names ||= []
end
configures(*names) click to toggle source
# File lib/quandl/configuration.rb, line 14
def configures(*names)
  define_attributes(*names)
end
define_attribute(name) click to toggle source
# File lib/quandl/configuration.rb, line 22
def define_attribute(name)
  name = name.to_sym
  define_method(name) do
    read_attribute(name)
  end
  define_method("#{name}=") do |value|
    write_attribute(name, value)
  end
  define_method("#{name}?") do
    read_attribute(name).present?
  end
  # store an array of defined attriubte names
  attribute_names << name unless attribute_names.include?(name)
end
define_attributes(*names) click to toggle source
# File lib/quandl/configuration.rb, line 18
def define_attributes(*names)
  Array(names).each{|name| define_attribute(name) }
end
from_file(file, env) click to toggle source
# File lib/quandl/configuration.rb, line 9
def from_file(file, env)
  self.config_file = file
  self.config_env = env
end
new(*args) click to toggle source
# File lib/quandl/configuration.rb, line 43
def initialize(*args)
  attrs = args.extract_options!
  self.attributes
  self.assign_attributes(attrs)
  from_file(self.class.config_file, self.class.config_env) if self.class.config_file.present? && self.class.config_env.present?
end

Public Instance Methods

assign_attributes(hash) click to toggle source
# File lib/quandl/configuration.rb, line 56
def assign_attributes(hash)
  hash.each do |k,v|
    send("#{k}=", v) if self.class.attribute_names.include?(k.to_sym) && respond_to?("#{k}=")
  end
end
attributes() click to toggle source
# File lib/quandl/configuration.rb, line 66
def attributes
  @attributes ||= self.class.attribute_names.inject({}){|m,k| m[k] ||= nil; m }
end
attributes=(value) click to toggle source
# File lib/quandl/configuration.rb, line 70
def attributes=(value)
  @attributes = value.symbolize_keys! if value.is_a?(Hash)
end
from_file(path, env) click to toggle source
# File lib/quandl/configuration.rb, line 50
def from_file(path, env)
  config = YAML.load_file( path )[ env ]
  raise ArgumentError, "Unknown env #{env}" if config.nil?
  config.each{|k,v| self.send("#{k}=",v) if respond_to?("#{k}=") }
end
inspect() click to toggle source
# File lib/quandl/configuration.rb, line 62
def inspect
  "#{self.class.name} " + attributes.inspect
end
read_attribute(attribute) click to toggle source
# File lib/quandl/configuration.rb, line 78
def read_attribute(attribute)
  @attributes[:"#{attribute}"]
end
write_attribute(attribute, value) click to toggle source
# File lib/quandl/configuration.rb, line 74
def write_attribute(attribute, value)
  @attributes[:"#{attribute}"] = value
end