module ExceptionTransformer::Reportable::ClassMethods

Public Instance Methods

as_reportable() click to toggle source

Returns a subclass 'Reportable_<name>' of the current class that includes `Reportable`. This subclass is created the first time this method is called and reused for subsequent invocations.

# File lib/exception_transformer/reportable.rb, line 33
def as_reportable
  return self if self <= ReportableException

  name = reportable_name
  mod = self.respond_to?(:module_parent) ? module_parent : parent

  mod.const_defined?(name) ? mod.const_get(name) : mod.const_set(name, build_reportable)
end
reported_class() click to toggle source
# File lib/exception_transformer/reportable.rb, line 49
def reported_class
  @reported_class ||= self
end
reported_class=(klass) click to toggle source
# File lib/exception_transformer/reportable.rb, line 53
def reported_class=(klass)
  @reported_class = klass
end
unload_reportable() click to toggle source
# File lib/exception_transformer/reportable.rb, line 42
def unload_reportable
  name = reportable_name
  mod = self.respond_to?(:module_parent) ? module_parent : parent

  mod.send(:remove_const, name) if mod.const_defined?(name)
end

Private Instance Methods

build_reportable() click to toggle source
# File lib/exception_transformer/reportable.rb, line 59
def build_reportable
  super_class = self
  Class.new(super_class) do
    include ReportableException
    self.reported_class = super_class
  end
end
reportable_name() click to toggle source
# File lib/exception_transformer/reportable.rb, line 67
def reportable_name
  [ReportableException.name, self.name].map(&:demodulize).join("_")
end