Module: Axn::Core::Flow::FailsOn::ClassMethods
- Defined in:
- lib/axn/core/flow/fails_on.rb
Instance Method Summary collapse
- #_fails_on?(exception) ⇒ Boolean
- #fails_on(exceptions, message = nil, standalone: nil) { ... } ⇒ Object
Instance Method Details
#_fails_on?(exception) ⇒ Boolean
49 50 51 |
# File 'lib/axn/core/flow/fails_on.rb', line 49 def _fails_on?(exception) _fails_on_matchers.any? { |klass| exception.is_a?(klass) } end |
#fails_on(exceptions, message = nil, standalone: nil) { ... } ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/axn/core/flow/fails_on.rb', line 27 def fails_on(exceptions, = nil, standalone: nil, &block) classes = Array(exceptions) if classes.empty? || classes.any? { |c| !(c.is_a?(Class) && c <= Exception) } raise ArgumentError, "fails_on requires one or more Exception classes (got #{exceptions.inspect})" end _reject_unreachable_fails_on!(classes) # standalone: only configures the wired `error`, so it's inert without a message/block — # raise rather than silently drop it (true and false alike), matching the message DSL. raise ArgumentError, "fails_on standalone: has no effect without a message or block" if !standalone.nil? && !( || block) self._fails_on_matchers = (_fails_on_matchers + classes).freeze # Wire the message through the existing `error` DSL when provided. Uses an OR proc # (not `if: classes`) because `if:` with an array matches via `all?` (AND). standalone: # is forwarded verbatim (nil = the DSL's conditional default: an attached reason). error(, if: ->(exception:) { classes.any? { |klass| exception.is_a?(klass) } }, standalone:, &block) if || block true end |