Class: Axn::Core::Flow::Handlers::Descriptors::MessageDescriptor
- Inherits:
-
BaseDescriptor
- Object
- BaseDescriptor
- Axn::Core::Flow::Handlers::Descriptors::MessageDescriptor
- Defined in:
- lib/axn/core/flow/handlers/descriptors/message_descriptor.rb
Overview
Data structure for message configuration - no behavior, just data
Instance Attribute Summary collapse
-
#prefix ⇒ Object
readonly
Returns the value of attribute prefix.
Attributes inherited from BaseDescriptor
Class Method Summary collapse
- ._build_matcher(if:, unless:, from:) ⇒ Object
- ._build_rule_for_from_condition(from_class) ⇒ Object
- .build(handler: nil, if: nil, unless: nil, prefix: nil, from: nil) ⇒ Object
Instance Method Summary collapse
-
#initialize(matcher:, handler:, prefix: nil) ⇒ MessageDescriptor
constructor
A new instance of MessageDescriptor.
Methods inherited from BaseDescriptor
Constructor Details
#initialize(matcher:, handler:, prefix: nil) ⇒ MessageDescriptor
Returns a new instance of MessageDescriptor.
14 15 16 17 |
# File 'lib/axn/core/flow/handlers/descriptors/message_descriptor.rb', line 14 def initialize(matcher:, handler:, prefix: nil) @prefix = prefix super(matcher:, handler:) end |
Instance Attribute Details
#prefix ⇒ Object (readonly)
Returns the value of attribute prefix.
12 13 14 |
# File 'lib/axn/core/flow/handlers/descriptors/message_descriptor.rb', line 12 def prefix @prefix end |
Class Method Details
._build_matcher(if:, unless:, from:) ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/axn/core/flow/handlers/descriptors/message_descriptor.rb', line 27 def self._build_matcher(if:, unless:, from:) rules = [ binding.local_variable_get(:if), binding.local_variable_get(:unless), _build_rule_for_from_condition(from), ].compact Axn::Core::Flow::Handlers::Matcher.new(rules, invert: !!binding.local_variable_get(:unless)) end |
._build_rule_for_from_condition(from_class) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/axn/core/flow/handlers/descriptors/message_descriptor.rb', line 37 def self._build_rule_for_from_condition(from_class) return nil unless from_class # Special case: `from: true` means "from any child action" return ->(exception:, **) { exception.is_a?(Axn::Failure) && exception.source } if from_class == true from_classes = Array(from_class) lambda { |exception:, **| return false unless exception.is_a?(Axn::Failure) && exception.source source = exception.source from_classes.any? do |cls| if cls.is_a?(String) # rubocop:disable Style/ClassEqualityComparison # We're comparing class name strings, not classes themselves source.class.name == cls # rubocop:enable Style/ClassEqualityComparison else source.is_a?(cls) end end } end |
.build(handler: nil, if: nil, unless: nil, prefix: nil, from: nil) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/axn/core/flow/handlers/descriptors/message_descriptor.rb', line 19 def self.build(handler: nil, if: nil, unless: nil, prefix: nil, from: nil, **) new( handler:, prefix:, matcher: _build_matcher(if:, unless:, from:), ) end |