lib/restly/configuration.rb in restly-0.0.1.alpha.1 vs lib/restly/configuration.rb in restly-0.0.1.alpha.2
- old
+ new
@@ -2,42 +2,44 @@
def self.config
defaults = {
session_key: :access_token,
load_middleware: true,
- :authorize_url => '/oauth/authorize',
- :token_url => '/oauth/token',
- :token_method => :post,
- :connection_opts => {},
- :max_redirects => 5,
- :raise_errors => 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
+ }
}
- defaults.merge(@config || {})
+ 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.select do |k,v|
- [ :authorize_url,
- :token_url,
- :token_method,
- :connection_opts,
- :max_redirects,
- :raise_errors
- ].include?(k.to_sym)
- end
+ config[:client_options].merge(config[:oauth_options])
end
def self.load_config(hash)
- @config = hash
+ @config = hash.symbolize_keys
end
def self.method_missing(m, *args, &block)
config.with_indifferent_access[m]
end
def respond_to_missing?
true
end
- load_config YAML.load_file(File.join(Rails.root, 'config', 'restly.yml'))[Rails.env] if defined? Rails
+ config_file = File.join(Rails.root, 'config', 'restly.yml')
+ load_config YAML.load_file(config_file)[Rails.env] if defined?(Rails) && File.exists?(config_file)
end
\ No newline at end of file