Module: ExceptionTransformer::Reportable

Defined in:
lib/exception_transformer/reportable.rb

Overview

Include this module when declaring an exception class to add the ‘reportable?` flag to individual exceptions. The presence of this flag can then be checked when capturing exceptions to send to a crash reporter.

This flag can be set at the instance level with ‘mark_reportable!`. Alternatively, the class method `as_reportable` returns a subclass for which `reportable?` is true when raised.

Examples:

Conditionally reporting exceptions

class MyError < StandardError
  include ExceptionTransformer::ReportableException
end

begin
  # do something that may fail
rescue MyError => e
  CrashReport.new(e) if e.reportable?
end

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object

Raises:

  • (TypeError)


24
25
26
27
# File 'lib/exception_transformer/reportable.rb', line 24

def self.included(base)
  raise TypeError, "#{base} is not a type of Exception" unless base <= Exception
  base.extend ClassMethods
end

Instance Method Details

#mark_reportable!Object



76
77
78
# File 'lib/exception_transformer/reportable.rb', line 76

def mark_reportable!
  @reportable = true
end

#reportable?Boolean

Returns:

  • (Boolean)


72
73
74
# File 'lib/exception_transformer/reportable.rb', line 72

def reportable?
  @reportable ||= false
end