Class: Pricefinder::Configuration
- Inherits:
-
Object
- Object
- Pricefinder::Configuration
- Defined in:
- lib/pricefinder/configuration.rb
Constant Summary collapse
- TOKEN_PARAMS =
[:access_token]
- AUTH_PARAMS =
[:client_id, :client_secret]
- CONFIG_PARAMS =
TOKEN_PARAMS + AUTH_PARAMS
Instance Method Summary collapse
-
#config_params ⇒ Object
Returns a hash of config params and their values.
-
#initialize(config_hash = nil) ⇒ Configuration
constructor
Creates the configuration config_params set.
-
#valid? ⇒ Boolean
Check that we have all the required params.
Constructor Details
#initialize(config_hash = nil) ⇒ Configuration
Creates the configuration config_params set
15 16 17 18 19 20 21 |
# File 'lib/pricefinder/configuration.rb', line 15 def initialize(config_hash = nil) if config_hash.is_a?(Hash) config_hash.each do |config_name, config_value| self.send("#{config_name}=", config_value) end end end |
Instance Method Details
#config_params ⇒ Object
Returns a hash of config params and their values
24 25 26 27 28 29 |
# File 'lib/pricefinder/configuration.rb', line 24 def config_params CONFIG_PARAMS.inject({}) do |keys_hash, key| keys_hash[key] = send(key) keys_hash end end |
#valid? ⇒ Boolean
Check that we have all the required params
32 33 34 35 |
# File 'lib/pricefinder/configuration.rb', line 32 def valid? TOKEN_PARAMS.none? { |key| send(key).nil? || send(key).empty? } || AUTH_PARAMS.none? { |key| send(key).nil? || send(key).empty? } end |