Module: Exceptional::Config

Included in:
Exceptional
Defined in:
lib/exceptional/config.rb

Defined Under Namespace

Classes: ConfigurationException

Constant Summary collapse

REMOTE_HOST =

Defaults for configuration variables

"getexceptional.com"
REMOTE_PORT =
80
REMOTE_SSL_PORT =
443
SSL =
false
LOG_LEVEL =
'info'
LOG_PATH =
nil

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#api_keyObject

Returns the value of attribute api_key.



16
17
18
# File 'lib/exceptional/config.rb', line 16

def api_key
  @api_key
end

#remote_hostObject



40
41
42
# File 'lib/exceptional/config.rb', line 40

def remote_host
  @remote_host || REMOTE_HOST
end

#remote_portObject



44
45
46
# File 'lib/exceptional/config.rb', line 44

def remote_port
  @remote_port || default_port
end

#ssl_enabled=(value) ⇒ Object (writeonly)

Sets the attribute ssl_enabled

Parameters:

  • value

    the value to set the attribute ssl_enabled to.



17
18
19
# File 'lib/exceptional/config.rb', line 17

def ssl_enabled=(value)
  @ssl_enabled = value
end

Instance Method Details

#application_rootObject



36
37
38
# File 'lib/exceptional/config.rb', line 36

def application_root
  @applicaton_root || (File.dirname(__FILE__) + '/../..')
end

#default_portObject



52
53
54
# File 'lib/exceptional/config.rb', line 52

def default_port
  ssl_enabled? ? REMOTE_SSL_PORT : REMOTE_PORT
end

#enabled?Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/exceptional/config.rb', line 60

def enabled?
  @enabled || false
end

#log_config_infoObject



68
69
70
71
72
# File 'lib/exceptional/config.rb', line 68

def log_config_info
  Exceptional.to_log('debug', "API Key: #{api_key}")
  Exceptional.to_log('debug', "Remote Host: #{remote_host}:#{remote_port}")
  Exceptional.to_log('debug', "Log level: #{log_level}")
end

#log_levelObject



48
49
50
# File 'lib/exceptional/config.rb', line 48

def log_level
  @log_level || LOG_LEVEL
end

#setup_config(environment, config_file) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/exceptional/config.rb', line 19

def setup_config(environment, config_file)
  begin
    config = YAML::load(File.open(config_file))[environment]
    @api_key = config['api-key'] unless config['api-key'].nil?
    @ssl_enabled = config['ssl'] unless config['ssl'].nil?
    @log_level = config['log-level'] unless config['log-level'].nil?
    @enabled = config['enabled'] unless config['enabled'].nil?
    @remote_port = config['remote-port'].to_i unless config['remote-port'].nil?
    @remote_host = config['remote-host'] unless config['remote-host'].nil?
    @applicaton_root = application_root

    log_config_info
  rescue Exception => e
    raise ConfigurationException.new("Unable to load configuration #{config_file} for environment #{environment} : #{e.message}")
  end
end

#ssl_enabled?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/exceptional/config.rb', line 56

def ssl_enabled?
  @ssl_enabled || SSL
end

#valid_api_key?Boolean

Returns:

  • (Boolean)


64
65
66
# File 'lib/exceptional/config.rb', line 64

def valid_api_key?
  @api_key && @api_key.length == 40 ? true : false
end