Class: Exceptional::Config

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

Constant Summary collapse

DEFAULTS =
{
  :ssl_enabled => false,
  :remote_host_http => 'api.getexceptional.com',
  :remote_port_http => 80,
  :remote_host_https => 'getexceptional.appspot.com',
  :remote_port_https => 443,
  :http_open_timeout => 2,
  :http_read_timeout => 4,
  :disabled_by_default => %w(development test)
}

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.api_keyObject

Returns the value of attribute api_key.



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

def api_key
  @api_key
end

.http_proxy_hostObject

Returns the value of attribute http_proxy_host.



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

def http_proxy_host
  @http_proxy_host
end

.http_proxy_passwordObject

Returns the value of attribute http_proxy_password.



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

def http_proxy_password
  @http_proxy_password
end

.http_proxy_portObject

Returns the value of attribute http_proxy_port.



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

def http_proxy_port
  @http_proxy_port
end

.http_proxy_usernameObject

Returns the value of attribute http_proxy_username.



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

def http_proxy_username
  @http_proxy_username
end

.ssl_enabled=(value) ⇒ Object (writeonly)

Sets the attribute ssl_enabled



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

def ssl_enabled=(value)
  @ssl_enabled = value
end

Class Method Details

.application_environmentObject



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

def application_environment
  ENV['RACK_ENV'] || ENV['RAILS_ENV']|| 'development'
end

.application_rootObject



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

def application_root
  defined?(RAILS_ROOT) ? RAILS_ROOT : Dir.pwd
end

.http_open_timeoutObject



76
77
78
# File 'lib/exceptional/config.rb', line 76

def http_open_timeout
  @http_open_timeout ||= DEFAULTS[:http_open_timeout]
end

.http_read_timeoutObject



80
81
82
# File 'lib/exceptional/config.rb', line 80

def http_read_timeout
  @http_read_timeout ||= DEFAULTS[:http_read_timeout]
end

.load(config_file = nil) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/exceptional/config.rb', line 19

def load(config_file=nil)
  if (config_file && File.file?(config_file))
    begin
      config = YAML::load(File.open(config_file))
      env_config = config[application_environment] || {}
      @api_key = config['api-key'] || env_config['api-key']

      @http_proxy_host = config['http-proxy-host']
      @http_proxy_port = config['http-proxy-port']
      @http_proxy_username = config['http-proxy-username']
      @http_proxy_password = config['http-proxy-password']
      @http_open_timeout = config['http-open-timeout']
      @http_read_timeout = config['http-read-timeout'] 

      @ssl_enabled = config['ssl'] || env_config['ssl']
      @enabled = env_config['enabled']
      @remote_port = config['remote-port'].to_i unless config['remote-port'].nil?
      @remote_host = config['remote-host'] unless config['remote-host'].nil?
    rescue Exception => e
      raise ConfigurationException.new("Unable to load configuration #{config_file} for environment #{application_environment} : #{e.message}")
    end
  end
end

.remote_hostObject



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

def remote_host
  @remote_host ||= ssl_enabled? ? DEFAULTS[:remote_host_https] : DEFAULTS[:remote_host_http]
end

.remote_portObject



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

def remote_port
  @remote_port ||= ssl_enabled? ? DEFAULTS[:remote_port_https] : DEFAULTS[:remote_port_http]
end

.resetObject



72
73
74
# File 'lib/exceptional/config.rb', line 72

def reset
  @enabled = @ssl_enabled = @remote_host = @remote_port = @api_key = nil
end

.should_send_to_api?Boolean



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

def should_send_to_api?
  @enabled ||= DEFAULTS[:disabled_by_default].include?(application_environment) ? false : true
end

.ssl_enabled?Boolean



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

def ssl_enabled?
  @ssl_enabled ||= DEFAULTS[:ssl_enabled]
end