Class: Axn::Core::Flow::Handlers::Resolvers::MessageResolver
- Inherits:
-
BaseResolver
- Object
- BaseResolver
- Axn::Core::Flow::Handlers::Resolvers::MessageResolver
- Defined in:
- lib/axn/core/flow/handlers/resolvers/message_resolver.rb
Overview
Internal: resolves messages with different strategies
Constant Summary collapse
- DEFAULT_ERROR =
"Something went wrong"- DEFAULT_SUCCESS =
"Action completed successfully"- DEFAULT_JOIN =
": "
Instance Method Summary collapse
- #base_message ⇒ Object
-
#matched_reason ⇒ Object
The winning reason as [descriptor, body], or nil if no conditional/dynamic (or explicitly
standalone: false) entry matches. - #resolve_default_message ⇒ Object
- #resolve_message ⇒ Object
-
#with_base(reason) ⇒ Object
Combine an externally-supplied reason (e.g. a fail!/done! message) with the base.
Methods inherited from BaseResolver
Constructor Details
This class inherits a constructor from Axn::Core::Flow::Handlers::Resolvers::BaseResolver
Instance Method Details
#base_message ⇒ Object
60 |
# File 'lib/axn/core/flow/handlers/resolvers/message_resolver.rb', line 60 def = resolved_base&.last |
#matched_reason ⇒ Object
The winning reason as [descriptor, body], or nil if no conditional/dynamic (or explicitly
standalone: false) entry matches. Unconditional standalone entries are headlines, excluded
here and surfaced via base_message. filter_map captures each body once (body_for invokes the
handler block), so the winning entry's message block runs a single time. Memoized — a
resolver is single-use — so an external caller (Result#_resolve_error, deciding whether a
parent override should beat a bubbled child message) and resolve_message share one pass.
Plain truthiness: an entry that supplied no body is already nil, decided undispatched in
body_for, which is the one place that question is asked about a handler's own return value.
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/axn/core/flow/handlers/resolvers/message_resolver.rb', line 35 def matched_reason return @matched_reason if defined?(@matched_reason) @matched_reason = matching_entries.lazy.filter_map do |d| next unless reason?(d) body = body_for(d) [d, body] if body end.first end |
#resolve_default_message ⇒ Object
46 |
# File 'lib/axn/core/flow/handlers/resolvers/message_resolver.rb', line 46 def = || |
#resolve_message ⇒ Object
19 20 21 22 23 24 |
# File 'lib/axn/core/flow/handlers/resolvers/message_resolver.rb', line 19 def descriptor, reason = matched_reason return || unless descriptor descriptor.standalone? ? reason : with_base(reason) end |
#with_base(reason) ⇒ Object
Combine an externally-supplied reason (e.g. a fail!/done! message) with the base.
Truthiness rather than present?, on the same terms as matched_reason above: a base that
resolved to nothing is already nil, and what a resolved base HOLDS is the handler's own return
value — asking that object whether it is blank runs the caller's code from inside the path
settling the failure.
54 55 56 57 58 |
# File 'lib/axn/core/flow/handlers/resolvers/message_resolver.rb', line 54 def with_base(reason) return reason unless combine(, reason) end |