Class: GenevaDrive::ExceptionPolicy::LazyExceptionMatcher Private

Inherits:
Object
  • Object
show all
Defined in:
lib/geneva_drive/exception_policy.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Matches exceptions by class name without requiring the constant to be loaded at definition time. The class lookup happens lazily on each #=== call. If the constant cannot be resolved, the matcher returns false (no match) rather than raising.

Examples:

on_exception "SomeLib::TransientError", action: :reattempt!

Instance Method Summary collapse

Constructor Details

#initialize(class_name) ⇒ LazyExceptionMatcher

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of LazyExceptionMatcher.

Parameters:

  • class_name (String)

    fully-qualified exception class name



53
54
55
# File 'lib/geneva_drive/exception_policy.rb', line 53

def initialize(class_name)
  @class_name = class_name.to_s.freeze
end

Instance Method Details

#===(error) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

  • error (Exception)

Returns:

  • (Boolean)


59
60
61
62
# File 'lib/geneva_drive/exception_policy.rb', line 59

def ===(error)
  klass = @class_name.safe_constantize
  klass ? error.is_a?(klass) : false
end

#inspectObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



64
65
66
# File 'lib/geneva_drive/exception_policy.rb', line 64

def inspect
  "#<LazyExceptionMatcher #{@class_name}>"
end