Class: Pricefinder::Configuration

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(config_hash = nil) ⇒ Configuration

Creates the configuration config_params set

Parameters:

  • hash (Hash)

    containing configuration params and their values



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_paramsObject

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

Returns:

  • (Boolean)


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