Class: Axn::Core::Flow::Handlers::Matcher
- Inherits:
-
Object
- Object
- Axn::Core::Flow::Handlers::Matcher
- Defined in:
- lib/axn/core/flow/handlers/matcher.rb
Class Method Summary collapse
-
.build(if: nil, unless: nil) ⇒ Object
Class method to build matcher from kwargs.
Instance Method Summary collapse
- #call(exception:, action:) ⇒ Object
-
#initialize(rules, invert: false) ⇒ Matcher
constructor
NOTE: invert means it’s an unless rather than an if.
- #invert? ⇒ Boolean
- #static? ⇒ Boolean
Constructor Details
#initialize(rules, invert: false) ⇒ Matcher
NOTE: invert means it’s an unless rather than an if. This will apply to ALL rules (sufficient for current use case, but flagging if we ever extend this for complex matching)
74 75 76 77 |
# File 'lib/axn/core/flow/handlers/matcher.rb', line 74 def initialize(rules, invert: false) @rules = Array(rules).compact @invert = invert end |
Class Method Details
.build(if: nil, unless: nil) ⇒ Object
Class method to build matcher from kwargs
89 90 91 92 93 94 95 96 |
# File 'lib/axn/core/flow/handlers/matcher.rb', line 89 def self.build(if: nil, unless: nil) if_condition = binding.local_variable_get(:if) unless_condition = binding.local_variable_get(:unless) raise Axn::UnsupportedArgument, "providing both :if and :unless" if if_condition && unless_condition new(Array(if_condition || unless_condition).compact, invert: !!unless_condition) end |
Instance Method Details
#call(exception:, action:) ⇒ Object
79 80 81 82 83 |
# File 'lib/axn/core/flow/handlers/matcher.rb', line 79 def call(exception:, action:) matches?(exception:, action:) rescue StandardError => e Axn::Internal::PipingError.swallow("determining if handler applies to exception", action:, exception: e) end |
#invert? ⇒ Boolean
86 |
# File 'lib/axn/core/flow/handlers/matcher.rb', line 86 def invert? = !!@invert |
#static? ⇒ Boolean
85 |
# File 'lib/axn/core/flow/handlers/matcher.rb', line 85 def static? = @rules.empty? |