Sha256: 4ca0adc3eff7e9b6e78b59035de444be73caf4ee5ab82846f916671bf5082638
Contents?: true
Size: 1.83 KB
Versions: 1
Compression:
Stored size: 1.83 KB
Contents
require 'uri' module CrashHook @@config = nil class Configuration ALLOWED_METHODS = [:get, :post, :put, :delete].freeze ALLOWED_FORMATS = [:form, :json, :yaml] attr_reader :url attr_reader :method attr_reader :ignore attr_reader :extra_params attr_reader :format attr_reader :logger # 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) # 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 # Returns true if specified exception class is ignored # def ignore_exception?(ex) @ignore.include?(ex.to_s) end # Returns true if configuration has a logger def has_logger? !@logger.nil? end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
crash_hook-0.2.0 | lib/crash_hook/configuration.rb |