Class: CrashHook::Configuration
- Inherits:
-
Object
- Object
- CrashHook::Configuration
- Defined in:
- lib/crash_hook/configuration.rb
Constant Summary collapse
- ALLOWED_METHODS =
[:get, :post, :put, :delete].freeze
- ALLOWED_FORMATS =
[:form, :json, :yaml]
Instance Attribute Summary collapse
-
#extra_params ⇒ Object
readonly
Returns the value of attribute extra_params.
-
#format ⇒ Object
readonly
Returns the value of attribute format.
-
#ignore ⇒ Object
readonly
Returns the value of attribute ignore.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#method ⇒ Object
readonly
Returns the value of attribute method.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
-
#has_logger? ⇒ Boolean
Returns true if configuration has a logger.
-
#ignore_exception?(ex) ⇒ Boolean
Returns true if specified exception class is ignored.
-
#initialize(options = {}) ⇒ Configuration
constructor
Initialize configuration.
Constructor Details
#initialize(options = {}) ⇒ Configuration
Initialize configuration. Options:
:url => Target url (required)
:method => Request method (default: post)
:format => Request format (default: json)
:params => Additional parameters for the request
:ignore => Set of exception classes to ignore
:logger => Set logger class (default: none)
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/crash_hook/configuration.rb', line 25 def initialize(={}) if [:url].to_s.strip.empty? raise CrashHook::ConfigurationError, ":url option required!" end @url = [:url].to_s @method = .key?(:method) ? [:method].to_sym : :post @format = .key?(:format) ? [:format].to_sym : :json @extra_params = [:params].kind_of?(Hash) ? [:params] : {} @logger = [:logger] unless ALLOWED_METHODS.include?(@method) raise CrashHook::ConfigurationError, "#{@method} is not a valid :method option." end unless ALLOWED_FORMATS.include?(@format) raise CrashHook::ConfigurationError, "#{@format} is not a valid :format option." end @ignore = [] @ignore += [:ignore] if [:ignore].kind_of?(Array) @ignore.map! { |c| c.to_s } @ignore.uniq! end |
Instance Attribute Details
#extra_params ⇒ Object (readonly)
Returns the value of attribute extra_params.
13 14 15 |
# File 'lib/crash_hook/configuration.rb', line 13 def extra_params @extra_params end |
#format ⇒ Object (readonly)
Returns the value of attribute format.
14 15 16 |
# File 'lib/crash_hook/configuration.rb', line 14 def format @format end |
#ignore ⇒ Object (readonly)
Returns the value of attribute ignore.
12 13 14 |
# File 'lib/crash_hook/configuration.rb', line 12 def ignore @ignore end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
15 16 17 |
# File 'lib/crash_hook/configuration.rb', line 15 def logger @logger end |
#method ⇒ Object (readonly)
Returns the value of attribute method.
11 12 13 |
# File 'lib/crash_hook/configuration.rb', line 11 def method @method end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
10 11 12 |
# File 'lib/crash_hook/configuration.rb', line 10 def url @url end |
Instance Method Details
#has_logger? ⇒ Boolean
Returns true if configuration has a logger
57 58 59 |
# File 'lib/crash_hook/configuration.rb', line 57 def has_logger? !@logger.nil? end |
#ignore_exception?(ex) ⇒ Boolean
Returns true if specified exception class is ignored
52 53 54 |
# File 'lib/crash_hook/configuration.rb', line 52 def ignore_exception?(ex) @ignore.include?(ex.to_s) end |