Class: WhoopsLogger::Configuration
- Inherits:
-
Object
- Object
- WhoopsLogger::Configuration
- Defined in:
- lib/whoops_logger/configuration.rb
Overview
Used to set up and modify settings for the notifier.
Constant Summary collapse
- OPTIONS =
[:host, :http_open_timeout, :http_read_timeout, :port, :protocol, :proxy_host, :proxy_pass, :proxy_port, :proxy_user, :secure].freeze
Instance Attribute Summary collapse
-
#host ⇒ Object
The host to connect to.
-
#http_open_timeout ⇒ Object
The HTTP open timeout in seconds (defaults to 2).
-
#http_read_timeout ⇒ Object
The HTTP read timeout in seconds (defaults to 5).
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#port ⇒ Object
The port on which your Whoops server runs (defaults to 443 for secure connections, 80 for insecure connections).
-
#proxy_host ⇒ Object
The hostname of your proxy server (if using a proxy).
-
#proxy_pass ⇒ Object
The password to use when logging into your proxy server (if using a proxy).
-
#proxy_port ⇒ Object
The port of your proxy server (if using a proxy).
-
#proxy_user ⇒ Object
The username to use when logging into your proxy server (if using a proxy).
-
#secure ⇒ Object
(also: #secure?)
true
for https connections,false
for http connections.
Instance Method Summary collapse
-
#[](option) ⇒ Object
Allows config options to be read like a hash.
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
-
#merge(hash) ⇒ Object
Returns a hash of all configurable options merged with
hash
. - #protocol ⇒ Object
- #set(config) ⇒ Object
- #set_with_hash(config) ⇒ Object
- #set_with_io(config) ⇒ Object
-
#set_with_string(config) ⇒ Object
String should be either a filename or YAML.
- #set_with_yaml(config) ⇒ Object
-
#to_hash ⇒ Object
Returns a hash of all configurable options.
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
43 44 45 46 47 48 |
# File 'lib/whoops_logger/configuration.rb', line 43 def initialize @secure = false @host = nil @http_open_timeout = 2 @http_read_timeout = 5 end |
Instance Attribute Details
#host ⇒ Object
The host to connect to
12 13 14 |
# File 'lib/whoops_logger/configuration.rb', line 12 def host @host end |
#http_open_timeout ⇒ Object
The HTTP open timeout in seconds (defaults to 2).
22 23 24 |
# File 'lib/whoops_logger/configuration.rb', line 22 def http_open_timeout @http_open_timeout end |
#http_read_timeout ⇒ Object
The HTTP read timeout in seconds (defaults to 5).
25 26 27 |
# File 'lib/whoops_logger/configuration.rb', line 25 def http_read_timeout @http_read_timeout end |
#logger ⇒ Object
Returns the value of attribute logger.
39 40 41 |
# File 'lib/whoops_logger/configuration.rb', line 39 def logger @logger end |
#port ⇒ Object
The port on which your Whoops server runs (defaults to 443 for secure connections, 80 for insecure connections).
16 17 18 |
# File 'lib/whoops_logger/configuration.rb', line 16 def port @port end |
#proxy_host ⇒ Object
The hostname of your proxy server (if using a proxy)
28 29 30 |
# File 'lib/whoops_logger/configuration.rb', line 28 def proxy_host @proxy_host end |
#proxy_pass ⇒ Object
The password to use when logging into your proxy server (if using a proxy)
37 38 39 |
# File 'lib/whoops_logger/configuration.rb', line 37 def proxy_pass @proxy_pass end |
#proxy_port ⇒ Object
The port of your proxy server (if using a proxy)
31 32 33 |
# File 'lib/whoops_logger/configuration.rb', line 31 def proxy_port @proxy_port end |
#proxy_user ⇒ Object
The username to use when logging into your proxy server (if using a proxy)
34 35 36 |
# File 'lib/whoops_logger/configuration.rb', line 34 def proxy_user @proxy_user end |
#secure ⇒ Object Also known as: secure?
true
for https connections, false
for http connections.
19 20 21 |
# File 'lib/whoops_logger/configuration.rb', line 19 def secure @secure end |
Instance Method Details
#[](option) ⇒ Object
Allows config options to be read like a hash
53 54 55 |
# File 'lib/whoops_logger/configuration.rb', line 53 def [](option) send(option) end |
#merge(hash) ⇒ Object
Returns a hash of all configurable options merged with hash
67 68 69 |
# File 'lib/whoops_logger/configuration.rb', line 67 def merge(hash) to_hash.merge(hash) end |
#protocol ⇒ Object
75 76 77 78 79 80 81 |
# File 'lib/whoops_logger/configuration.rb', line 75 def protocol if secure? 'https' else 'http' end end |
#set(config) ⇒ Object
83 84 85 86 87 88 89 90 91 92 |
# File 'lib/whoops_logger/configuration.rb', line 83 def set(config) case config when Hash set_with_hash(config) when IO set_with_io(config) when String set_with_string(config) end end |
#set_with_hash(config) ⇒ Object
94 95 96 97 98 99 100 101 102 103 |
# File 'lib/whoops_logger/configuration.rb', line 94 def set_with_hash(config) OPTIONS.each do |option| next unless self.respond_to?("#{option}=") if config.has_key?(option) self.send("#{option}=", config[option]) elsif config.has_key?(option.to_s) self.send("#{option}=", config[option.to_s]) end end end |
#set_with_io(config) ⇒ Object
114 115 116 117 |
# File 'lib/whoops_logger/configuration.rb', line 114 def set_with_io(config) set_with_yaml(config) config.close end |
#set_with_string(config) ⇒ Object
String should be either a filename or YAML
106 107 108 109 110 111 112 |
# File 'lib/whoops_logger/configuration.rb', line 106 def set_with_string(config) if File.exists?(config) set_with_yaml(File.read(config)) else set_with_yaml(config) end end |
#set_with_yaml(config) ⇒ Object
119 120 121 |
# File 'lib/whoops_logger/configuration.rb', line 119 def set_with_yaml(config) set_with_hash(YAML.load(config)) end |
#to_hash ⇒ Object
Returns a hash of all configurable options
58 59 60 61 62 |
# File 'lib/whoops_logger/configuration.rb', line 58 def to_hash OPTIONS.inject({}) do |hash, option| hash.merge(option.to_sym => send(option)) end end |