module Johac
Constants
- Config
Simple config class used to store global {Johac::Client} settings.
@attr base_uri [String] Hostname of
Johac
API. @attr auth_scheme [Symbol] Authorization scheme to be used on all requests,:basic
or:hmac
. @attr access_key [String] Public access key used for authorization of requests. @attr secret_key [String] Private key used for authorization of requests. @attr env [String] Environment. 'testing', 'development', or 'production'.- Version
Public Class Methods
Return the config object for the global {Johac::Client} instance. @return [Johac::Config]
# File lib/johac.rb, line 47 def config unless defined? @config raise "#{self.name} not configured. Configure via #{self.name}.configure { |cfg| ... }, or via client constructor" end @config end
Configure the global defaults for all clients built.
@yield [config] Passes a config object to the block. @yieldparam config [Johac::Config] Config
object.
@example
Johac.defaults do |config| config.base_uri = 'http://api.myservice.com' config.auth_scheme = :basic config.access_key = 'user' config.secret_key = 'password' end
@return [Johac::Config]
# File lib/johac.rb, line 38 def defaults(&block) c = @config ||= Config.new c.env = environment || 'production' yield c c end
Merge the new config with defaults
# File lib/johac.rb, line 55 def merged_config(overrides) case overrides when Hash dup_config.tap do |conf| overrides.each do |k, v| conf[k] = v end end when Struct dup_config.tap do |conf| overrides.each_pair do |k, v| conf[k] = v end end else config end end
Protected Class Methods
# File lib/johac.rb, line 76 def environment ENV.values_at('JOHAC_ENV', 'RAILS_ENV').compact.first end
Private Class Methods
# File lib/johac.rb, line 82 def dup_config defined?(@config) ? @config.dup : Config.new end