Class: Allorails::Core::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/allorails/core.rb

Overview

Holds the configuration options for Allorails

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Configuration

creates a new Configuration object

Parameters:

  • options (defaults to: {})

Options Hash (options):

  • (Object)


14
15
16
17
18
19
20
21
# File 'lib/allorails/core.rb', line 14

def initialize options = {}
  options.each_pair do |opt_name, value|
    opt_name = opt_name.to_sym
    if self.class.accepted_options.include?(opt_name)
      supplied[opt_name] = value
    end
  end
end

Class Method Details

.accepted_optionsObject

accepted options



86
87
88
# File 'lib/allorails/core.rb', line 86

def accepted_options
  @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
  accepted_options << 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
  (email)[:api_key]
end

#private_key(email = nil) ⇒ Object



42
43
44
# File 'lib/allorails/core.rb', line 42

def private_key email = nil
  (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 options = {}
  # symbolize option keys
  options = symbolize_keys options
  values = supplied.merge(options)
  
  if supplied == values
    self # no changes
  else
    self.class.new(values)
  end
end