Class: Allorails::Core::Configuration
- Inherits:
-
Object
- Object
- Allorails::Core::Configuration
- Defined in:
- lib/allorails/core.rb
Overview
Holds the configuration options for Allorails
Class Method Summary collapse
-
.accepted_options ⇒ Object
accepted options.
-
.add_option(name, default_value = nil) ⇒ Object
used internally to register a configuration option.
Instance Method Summary collapse
-
#api_key(email = nil) ⇒ Object
API key and secret key depend on the account.
-
#initialize(options = {}) ⇒ Configuration
constructor
creates a new Configuration object.
- #private_key(email = nil) ⇒ Object
-
#with(options = {}) ⇒ Object
creates a new Configuration object with the given modifications does not modify the current object.
Constructor Details
#initialize(options = {}) ⇒ Configuration
creates a new Configuration object
14 15 16 17 18 19 20 21 |
# File 'lib/allorails/core.rb', line 14 def initialize = {} .each_pair do |opt_name, value| opt_name = opt_name.to_sym if self.class..include?(opt_name) supplied[opt_name] = value end end end |
Class Method Details
.accepted_options ⇒ Object
accepted options
86 87 88 |
# File 'lib/allorails/core.rb', line 86 def @options ||= Set.new end |
.add_option(name, default_value = nil) ⇒ Object
used internally to register a configuration option
91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/allorails/core.rb', line 91 def add_option name, default_value = nil # marks the option as accepted << name # defines an accessor method for the option define_method(name) do if supplied.has_key?(name) supplied[name] else default_value end end end |
Instance Method Details
#api_key(email = nil) ⇒ Object
API key and secret key depend on the account
38 39 40 |
# File 'lib/allorails/core.rb', line 38 def api_key email = nil account(email)[:api_key] end |
#private_key(email = nil) ⇒ Object
42 43 44 |
# File 'lib/allorails/core.rb', line 42 def private_key email = nil account(email)[:private_key] end |
#with(options = {}) ⇒ Object
creates a new Configuration object with the given modifications does not modify the current object
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/allorails/core.rb', line 25 def with = {} # symbolize option keys = symbolize_keys values = supplied.merge() if supplied == values self # no changes else self.class.new(values) end end |