Sha256: ad1b53d54d0b332bc0de9d4c51ba379aa8d41d73bc56127bfaab803c386d0d49

Contents?: true

Size: 844 Bytes

Versions: 1

Compression:

Stored size: 844 Bytes

Contents

require 'ostruct'
require 'yaml'
require 'quandl/project_root'

module Quandl
  class Config < ::OpenStruct
    VERSION = '0.0.2'

    def initialize(file_name)
      raw_config = File.read(project_root.join('config', "#{file_name}.yml"))
      erb_config = ERB.new(raw_config).result
      config = YAML.load(erb_config)[project_environment]

      super(config)
    end

    def configurable_attributes
      setters_and_getters = methods - self.class.instance_methods
      getters = setters_and_getters.reject { |method| method =~ /=$/ }
      getters
    end

    private

    def project_root
      defined?(Rails) ? ::Rails.root : Pathname.new(ProjectRoot.root)
    end

    def project_environment
      defined?(Rails) ? ::Rails.env : (ENV['RAILS_ENV'] || ENV('RAKE_ENV') || 'default')
    end
  end
end

require 'quandl/configurable'

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
quandl-config-0.0.2 lib/quandl/config.rb