Sha256: a88332bdfca17ec979de70c1272983b8aa02ec35d81d0e42f622d49245e80902

Contents?: true

Size: 1.17 KB

Versions: 18

Compression:

Stored size: 1.17 KB

Contents

module Restly::Configuration

  def self.load_config(hash)
    @config = hash.symbolize_keys
  end

  private

  def self.config
    defaults = {
      session_key: :access_token,
      load_middleware: true,
      use_oauth: false,
      cache: false,
      default_format: :json,
      oauth_options: {
        :authorize_url    => '/oauth/authorize',
        :token_url        => '/oauth/token',
        :token_method     => :post,
      },
      client_options: {
        :connection_opts  => {},
        :max_redirects    => 5,
        :raise_errors     => true
      }
    }
    config = defaults.deep_merge(@config || {})
    config.assert_valid_keys(:session_key, :load_middleware, :oauth_options, :use_oauth, :cache, :cache_options, :client_options, :site, :default_format)
    config
  end

  def self.client_options
    config[:client_options].merge(config[:oauth_options])
  end

  def self.method_missing(m, *args, &block)
    config.with_indifferent_access[m]
  end

  def respond_to_missing?
    true
  end

  if defined?(Rails)
    config_file = File.join(Rails.root, 'config', 'restly.yml')
    load_config YAML.load_file(config_file)[Rails.env] if File.exists?(config_file)
  end

end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
restly-0.0.1.beta.10 lib/restly/configuration.rb
restly-0.0.1.beta.9 lib/restly/configuration.rb
restly-0.0.1.beta.6 lib/restly/configuration.rb
restly-0.0.1.beta.5 lib/restly/configuration.rb
restly-0.0.1.beta.4 lib/restly/configuration.rb
restly-0.0.1.beta.3 lib/restly/configuration.rb
restly-0.0.1.beta.2 lib/restly/configuration.rb
restly-0.0.1.beta.1 lib/restly/configuration.rb
restly-0.0.1.alpha.22 lib/restly/configuration.rb
restly-0.0.1.alpha.19 lib/restly/configuration.rb
restly-0.0.1.alpha.18 lib/restly/configuration.rb
restly-0.0.1.alpha.16 lib/restly/configuration.rb
restly-0.0.1.alpha.12 lib/restly/configuration.rb
restly-0.0.1.alpha.11 lib/restly/configuration.rb
restly-0.0.1.alpha.10 lib/restly/configuration.rb
restly-0.0.1.alpha.9 lib/restly/configuration.rb
restly-0.0.1.alpha.8 lib/restly/configuration.rb
restly-0.0.1.alpha.7 lib/restly/configuration.rb