Class: Axn::Core::Flow::Handlers::Matcher

Inherits:
Object
  • Object
show all
Defined in:
lib/axn/core/flow/handlers/matcher.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(if_rules: [], unless_rules: []) ⇒ Matcher

if: and unless: may be combined (ANDed): every if: rule must match AND every unless: rule must not — the same combination rule as steps and field declarations. Multi-rule arrays keep their existing semantics (if: [A, B] requires all; unless: [A, B] requires none).



83
84
85
86
# File 'lib/axn/core/flow/handlers/matcher.rb', line 83

def initialize(if_rules: [], unless_rules: [])
  @if_rules = Array(if_rules).compact
  @unless_rules = Array(unless_rules).compact
end

Class Method Details

.build(if: nil, unless: nil) ⇒ Object

Class method to build matcher from kwargs



98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/axn/core/flow/handlers/matcher.rb', line 98

def self.build(if: nil, unless: nil)
  if_condition = binding.local_variable_get(:if)
  unless_condition = binding.local_variable_get(:unless)

  # A bare falsey condition value (e.g. a forwarded feature flag that's currently `false`)
  # means "no condition" -- matching both the pre-existing `||`-based behavior and the
  # field-declaration gates' measured ActiveModel semantics. A falsey element *inside* an
  # array (e.g. `if: [false, :other]`) is left alone and still hits the invalid-matcher path.
  new(
    if_rules: if_condition ? Array(if_condition).compact : [],
    unless_rules: unless_condition ? Array(unless_condition).compact : [],
  )
end

Instance Method Details

#call(exception:, action:) ⇒ Object



88
89
90
91
92
93
# File 'lib/axn/core/flow/handlers/matcher.rb', line 88

def call(exception:, action:)
  # See SingleRuleMatcher#call: matcher error policy is Invoker's, single-layered.
  Axn::Extensions.best_effort("determining if handler applies to exception", action:) do
    matches?(exception:, action:)
  end
end

#static?Boolean

Returns:

  • (Boolean)


95
# File 'lib/axn/core/flow/handlers/matcher.rb', line 95

def static? = @if_rules.empty? && @unless_rules.empty?