Module: MultipleDevicesLogger::IgnoreExceptions
- Extended by:
- ActiveSupport::Concern
- Included in:
- MultipleDevicesLogger
- Defined in:
- lib/multiple_devices_logger/ignore_exceptions.rb
Instance Method Summary collapse
- #exception_ignored?(exception) ⇒ Boolean
- #ignore_exceptions(*arguments, &block) ⇒ Object
- #ignored_exception_classes ⇒ Object
- #ignored_exceptions_procs ⇒ Object
Instance Method Details
#exception_ignored?(exception) ⇒ Boolean
7 8 9 10 |
# File 'lib/multiple_devices_logger/ignore_exceptions.rb', line 7 def exception_ignored?(exception) return false unless exception.is_a?(Exception) ignored_exception_classes.any? { |klass| exception.is_a?(klass) } || ignored_exceptions_procs.any? { |proc| proc.call(exception) } end |
#ignore_exceptions(*arguments, &block) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/multiple_devices_logger/ignore_exceptions.rb', line 12 def ignore_exceptions(*arguments, &block) @ignored_exception_class_names ||= [] @ignored_exceptions_procs ||= [] @ignored_exceptions_procs << proc(&block) if block_given? [arguments].flatten.each do |argument| if argument.respond_to?(:call) @ignored_exceptions_procs << argument else klass = argument.is_a?(Class) ? argument : argument.to_s.presence.try(:constantize) raise("Invalid exception class: #{argument.inspect}") unless klass.is_a?(Class) && (klass == Exception || (klass < Exception)) @ignored_exception_class_names << klass.name end end @ignored_exception_class_names.uniq! nil end |
#ignored_exception_classes ⇒ Object
29 30 31 |
# File 'lib/multiple_devices_logger/ignore_exceptions.rb', line 29 def ignored_exception_classes (@ignored_exception_class_names || []).map(&:constantize) end |
#ignored_exceptions_procs ⇒ Object
33 34 35 |
# File 'lib/multiple_devices_logger/ignore_exceptions.rb', line 33 def ignored_exceptions_procs @ignored_exceptions_procs || [] end |