Class: Exceptional::Config
- Inherits:
-
Object
- Object
- Exceptional::Config
- Defined in:
- lib/exceptional/config.rb
Constant Summary collapse
- DEFAULTS =
{ :ssl => false, :remote_host_http => 'plugin.getexceptional.com', :http_open_timeout => 2, :http_read_timeout => 4, :disabled_by_default => %w(development test) }
Class Attribute Summary collapse
-
.api_key ⇒ Object
Returns the value of attribute api_key.
-
.enabled ⇒ Object
Returns the value of attribute enabled.
-
.http_proxy_host ⇒ Object
Returns the value of attribute http_proxy_host.
-
.http_proxy_password ⇒ Object
Returns the value of attribute http_proxy_password.
-
.http_proxy_port ⇒ Object
Returns the value of attribute http_proxy_port.
-
.http_proxy_username ⇒ Object
Returns the value of attribute http_proxy_username.
-
.ssl ⇒ Object
writeonly
Sets the attribute ssl.
Class Method Summary collapse
- .application_environment ⇒ Object
- .application_root ⇒ Object
- .http_open_timeout ⇒ Object
- .http_read_timeout ⇒ Object
- .load(config_file = nil) ⇒ Object
- .remote_host ⇒ Object
- .remote_port ⇒ Object
- .reset ⇒ Object
- .should_send_to_api? ⇒ Boolean
- .ssl? ⇒ Boolean
Class Attribute Details
.api_key ⇒ Object
Returns the value of attribute api_key.
12 13 14 |
# File 'lib/exceptional/config.rb', line 12 def api_key @api_key end |
.enabled ⇒ Object
Returns the value of attribute enabled.
12 13 14 |
# File 'lib/exceptional/config.rb', line 12 def enabled @enabled end |
.http_proxy_host ⇒ Object
Returns the value of attribute http_proxy_host.
13 14 15 |
# File 'lib/exceptional/config.rb', line 13 def http_proxy_host @http_proxy_host end |
.http_proxy_password ⇒ Object
Returns the value of attribute http_proxy_password.
13 14 15 |
# File 'lib/exceptional/config.rb', line 13 def http_proxy_password @http_proxy_password end |
.http_proxy_port ⇒ Object
Returns the value of attribute http_proxy_port.
13 14 15 |
# File 'lib/exceptional/config.rb', line 13 def http_proxy_port @http_proxy_port end |
.http_proxy_username ⇒ Object
Returns the value of attribute http_proxy_username.
13 14 15 |
# File 'lib/exceptional/config.rb', line 13 def http_proxy_username @http_proxy_username end |
.ssl=(value) ⇒ Object (writeonly)
Sets the attribute ssl
14 15 16 |
# File 'lib/exceptional/config.rb', line 14 def ssl=(value) @ssl = value end |
Class Method Details
.application_environment ⇒ Object
45 46 47 |
# File 'lib/exceptional/config.rb', line 45 def application_environment ENV['RACK_ENV'] || ENV['RAILS_ENV']|| 'development' end |
.application_root ⇒ Object
54 55 56 |
# File 'lib/exceptional/config.rb', line 54 def application_root defined?(RAILS_ROOT) ? RAILS_ROOT : Dir.pwd end |
.http_open_timeout ⇒ Object
74 75 76 |
# File 'lib/exceptional/config.rb', line 74 def http_open_timeout @http_open_timeout ||= DEFAULTS[:http_open_timeout] end |
.http_read_timeout ⇒ Object
78 79 80 |
# File 'lib/exceptional/config.rb', line 78 def http_read_timeout @http_read_timeout ||= DEFAULTS[:http_read_timeout] end |
.load(config_file = nil) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/exceptional/config.rb', line 16 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 = 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.}") end end end |
.remote_host ⇒ Object
62 63 64 |
# File 'lib/exceptional/config.rb', line 62 def remote_host @remote_host ||= DEFAULTS[:remote_host_http] end |
.remote_port ⇒ Object
66 67 68 |
# File 'lib/exceptional/config.rb', line 66 def remote_port @remote_port ||= ssl? ? 443 : 80 end |
.reset ⇒ Object
70 71 72 |
# File 'lib/exceptional/config.rb', line 70 def reset @enabled = @ssl = @remote_host = @remote_port = @api_key = nil end |
.should_send_to_api? ⇒ Boolean
49 50 51 52 |
# File 'lib/exceptional/config.rb', line 49 def should_send_to_api? return @enabled unless @enabled.nil? @enabled = !(DEFAULTS[:disabled_by_default].include?(application_environment)) end |
.ssl? ⇒ Boolean
58 59 60 |
# File 'lib/exceptional/config.rb', line 58 def ssl? @ssl ||= DEFAULTS[:ssl] end |