Class: IntuitIdsAggcat::Core::Configuration

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

Overview

A configuration object for the Intuit interface.

Configuring Credentials

In order to do anything with the AggCat services you will need to assign credentials. The simplest method is to assing your credentials into the default configuration:

AWS.config(:access_key_id => 'KEY', :secret_access_key => 'SECRET')

You can also export them into your environment and they will be picked up automatically:

export AWS_ACCESS_KEY_ID='YOUR_KEY_ID_HERE'
export AWS_SECRET_ACCESS_KEY='YOUR_SECRET_KEY_HERE'

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Configuration

Creates a new Configuration object.



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/intuit_ids_aggcat/core/configuration.rb', line 27

def initialize options = {}

  @created = options.delete(:__created__) || {}
  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



94
95
96
# File 'lib/intuit_ids_aggcat/core/configuration.rb', line 94

def accepted_options
  @options ||= Set.new
end

.add_option(name, default_value = nil, options = {}, &transform) ⇒ Object



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/intuit_ids_aggcat/core/configuration.rb', line 99

def add_option name, default_value = nil, options = {}, &transform

  accepted_options << name

  define_method(name) do |&default_override|

    value =
      if supplied.has_key?(name)
        supplied[name]
      elsif default_override
        default_override.call
      else
        default_value
      end

    transform ? transform.call(self, value) : value

  end

  alias_method("#{name}?", name) if options[:boolean]

end

Instance Method Details

#credentialsHash

Returns a hash with your configured credentials.

Returns:

  • (Hash)

    Returns a hash with your configured credentials.



40
41
42
43
44
45
46
47
48
# File 'lib/intuit_ids_aggcat/core/configuration.rb', line 40

def credentials
  credentials = {}
  [:saml_idp_id, :user_id].each do |opt|
    if value = credential_provider.send(opt)
      credentials[opt] = value
    end
  end
  credentials
end

#eql?(other) ⇒ Boolean Also known as: ==

Returns true if the two configuration objects have the same values.

Returns:

  • (Boolean)

    Returns true if the two configuration objects have the same values.



75
76
77
# File 'lib/intuit_ids_aggcat/core/configuration.rb', line 75

def eql? other
  other.is_a?(self.class) and self.supplied == other.supplied
end

#inspectObject



81
82
83
# File 'lib/intuit_ids_aggcat/core/configuration.rb', line 81

def inspect
  "<#{self.class.name}>"
end

#to_hHash Also known as: to_hash

Returns a hash of all configuration values.

Returns:

  • (Hash)

    Returns a hash of all configuration values.



66
67
68
69
70
# File 'lib/intuit_ids_aggcat/core/configuration.rb', line 66

def to_h
  self.class.accepted_options.inject({}) do |h,k|
    h.merge(k => send(k))
  end
end

#with(options = {}) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/intuit_ids_aggcat/core/configuration.rb', line 50

def with options = {}

  # symbolize option keys
  options = options.inject({}) {|h,kv| h[kv.first.to_sym] = kv.last; h }

  values = supplied.merge(options)

  if supplied == values
    self # nothing changed
  else
    self.class.new(values.merge(:__created__ => @created.dup))
  end

end