Class: Formidable::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/formidable/config.rb

Constant Summary collapse

DEFAULTS =
{
  :api_key => "",
  :use_ssl => false,
  :track_values => false,
  :thread => true
}

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.api_keyObject

Returns the value of attribute api_key.



14
15
16
# File 'lib/formidable/config.rb', line 14

def api_key
  @api_key
end

.threadObject

Returns the value of attribute thread.



14
15
16
# File 'lib/formidable/config.rb', line 14

def thread
  @thread
end

.track_valuesObject

Returns the value of attribute track_values.



14
15
16
# File 'lib/formidable/config.rb', line 14

def track_values
  @track_values
end

.use_sslObject

Returns the value of attribute use_ssl.



14
15
16
# File 'lib/formidable/config.rb', line 14

def use_ssl
  @use_ssl
end

Class Method Details

.load(settings) ⇒ Object



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

def load(settings)
  # symbolize keys
  settings = settings.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}

  # ensure we have default settings
  settings = DEFAULTS.merge(settings)

  [:api_key, :use_ssl, :track_values, :thread].each do |setting|
    self.send("#{setting}=", settings[setting])
  end
end

.load_file(config_file) ⇒ Object



16
17
18
19
20
21
22
23
24
25
# File 'lib/formidable/config.rb', line 16

def load_file(config_file)
  begin
    config = YAML::load_file(config_file)
    env_config = config[app_env] || {}
    settings = config.merge(env_config)
    load(settings)
  rescue Exception => e
    raise "Configuration error: #{e.message}"
  end
end