Class: CrashHook::Configuration

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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(options={})
  if options[:url].to_s.strip.empty?
    raise CrashHook::ConfigurationError, ":url option required!"
  end
  
  @url          = options[:url].to_s
  @method       = options.key?(:method) ? options[:method].to_sym : :post
  @format       = options.key?(:format) ? options[:format].to_sym : :json
  @extra_params = options[:params].kind_of?(Hash) ? options[:params] : {}
  @logger       = options[: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 += options[:ignore] if options[:ignore].kind_of?(Array)
  @ignore.map! { |c| c.to_s }
  @ignore.uniq!
end

Instance Attribute Details

#extra_paramsObject (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

#formatObject (readonly)

Returns the value of attribute format.



14
15
16
# File 'lib/crash_hook/configuration.rb', line 14

def format
  @format
end

#ignoreObject (readonly)

Returns the value of attribute ignore.



12
13
14
# File 'lib/crash_hook/configuration.rb', line 12

def ignore
  @ignore
end

#loggerObject (readonly)

Returns the value of attribute logger.



15
16
17
# File 'lib/crash_hook/configuration.rb', line 15

def logger
  @logger
end

#methodObject (readonly)

Returns the value of attribute method.



11
12
13
# File 'lib/crash_hook/configuration.rb', line 11

def method
  @method
end

#urlObject (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

Returns:

  • (Boolean)


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

Returns:

  • (Boolean)


52
53
54
# File 'lib/crash_hook/configuration.rb', line 52

def ignore_exception?(ex)
  @ignore.include?(ex.to_s) 
end