Class: AdGear::Config
- Inherits:
-
Object
- Object
- AdGear::Config
- Defined in:
- lib/ad_gear/config.rb
Defined Under Namespace
Classes: MissingEnvironmentSpecification
Instance Method Summary collapse
-
#format ⇒ Object
Returns a format object suitable for use by ActiveResource.
-
#initialize(obj = {}, environment = nil) ⇒ Config
constructor
Reads in a YAML file containing configuration parameters for the AdGear::Client.
-
#logger ⇒ Object
Returns the Logger instance that was configured in #logger=.
-
#logger=(value) ⇒ Object
Register a Logger for use by AdGear’s client.
-
#password ⇒ Object
Returns the configured password.
- #password=(value) ⇒ Object
-
#site ⇒ Object
Returns the configured site, which is the root of the API.
- #site=(value) ⇒ Object
-
#to_hash ⇒ Object
Returns a Hash of the currect configuration.
-
#use_basic_authentication ⇒ Object
Denies or allows using Basic authentication method.
- #use_basic_authentication=(value) ⇒ Object
-
#use_digest_authentication ⇒ Object
Denies or allows using Digest authentication method.
- #use_digest_authentication=(value) ⇒ Object
-
#user ⇒ Object
Returns the configured username / login.
- #user=(value) ⇒ Object
Constructor Details
#initialize(obj = {}, environment = nil) ⇒ Config
Reads in a YAML file containing configuration parameters for the AdGear::Client. The file can contain sections relating to the environment the client is running within.
The YAML configuration file must use strings as keys.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/ad_gear/config.rb', line 42 def initialize(obj={}, environment=nil) @config = Hash.new @logger = nil config = if obj.kind_of?(Hash) then obj elsif obj.respond_to?(:read) then YAML.load(ERB.new(obj.read).result) else YAML.load(ERB.new(IO.read(obj)).result) end if environment then raise MissingEnvironmentSpecification, "Could not find #{environment.to_s.inspect} in #{config.inspect} read from #{obj.inspect}. Add the missing environment declaration, or change the parameter to this method." unless config.respond_to?(:has_key?) && config.has_key?(environment.to_s) config = config[environment.to_s] end config.each_pair do |key, value| send("#{key}=", value) end end |
Instance Method Details
#format ⇒ Object
Returns a format object suitable for use by ActiveResource.
114 115 116 |
# File 'lib/ad_gear/config.rb', line 114 def format AdGear::XmlFormat end |
#logger ⇒ Object
Returns the Logger instance that was configured in #logger=.
119 120 121 |
# File 'lib/ad_gear/config.rb', line 119 def logger @logger end |
#logger=(value) ⇒ Object
Register a Logger for use by AdGear’s client.
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/ad_gear/config.rb', line 127 def logger=(value) @config["logger"] = value @logger = case value when nil, "" # No logger nil when /^std(err|out)$/i # Existing stream Logger.new(Object.const_get(value.upcase)) else warn("WARNING: path to logger in AdGear::Client configuration is relative: CWD is #{Dir.pwd.inspect}") unless Pathname.new(value).absolute? # Path to a file Logger.new(value) end end |
#password ⇒ Object
Returns the configured password.
91 92 93 |
# File 'lib/ad_gear/config.rb', line 91 def password @config["password"] end |
#password=(value) ⇒ Object
86 87 88 |
# File 'lib/ad_gear/config.rb', line 86 def password=(value) @config["password"] = value end |
#site ⇒ Object
Returns the configured site, which is the root of the API.
73 74 75 |
# File 'lib/ad_gear/config.rb', line 73 def site @config["site"] end |
#site=(value) ⇒ Object
68 69 70 |
# File 'lib/ad_gear/config.rb', line 68 def site=(value) @config["site"] = value end |
#to_hash ⇒ Object
Returns a Hash of the currect configuration.
64 65 66 |
# File 'lib/ad_gear/config.rb', line 64 def to_hash @config.dup end |
#use_basic_authentication ⇒ Object
Denies or allows using Basic authentication method. This will have an effect only if you are using github.com/francois/rails/ar_basic/activeresource
96 97 98 |
# File 'lib/ad_gear/config.rb', line 96 def use_basic_authentication @config["use_basic_authentication"] end |
#use_basic_authentication=(value) ⇒ Object
100 101 102 |
# File 'lib/ad_gear/config.rb', line 100 def use_basic_authentication=(value) @config["use_basic_authentication"] = value end |
#use_digest_authentication ⇒ Object
Denies or allows using Digest authentication method. This will have an effect only if you are using github.com/francois/rails/ar_digest/activeresource
105 106 107 |
# File 'lib/ad_gear/config.rb', line 105 def use_digest_authentication @config["use_digest_authentication"] end |
#use_digest_authentication=(value) ⇒ Object
109 110 111 |
# File 'lib/ad_gear/config.rb', line 109 def use_digest_authentication=(value) @config["use_digest_authentication"] = value end |
#user ⇒ Object
Returns the configured username / login.
82 83 84 |
# File 'lib/ad_gear/config.rb', line 82 def user @config["user"] end |
#user=(value) ⇒ Object
77 78 79 |
# File 'lib/ad_gear/config.rb', line 77 def user=(value) @config["user"] = value end |