Class: Axn::Core::Flow::Handlers::Descriptors::MessageDescriptor

Inherits:
BaseDescriptor
  • Object
show all
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

Attributes inherited from BaseDescriptor

#handler, #matcher

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseDescriptor

#matches?, #static?

Constructor Details

#initialize(matcher:, handler:, standalone: false, join: nil) ⇒ MessageDescriptor

Returns a new instance of MessageDescriptor.



14
15
16
17
18
# File 'lib/axn/core/flow/handlers/descriptors/message_descriptor.rb', line 14

def initialize(matcher:, handler:, standalone: false, join: nil)
  @standalone = standalone
  @join = join
  super(matcher:, handler:)
end

Instance Attribute Details

#joinObject (readonly)

Returns the value of attribute join.



12
13
14
# File 'lib/axn/core/flow/handlers/descriptors/message_descriptor.rb', line 12

def join
  @join
end

Class Method Details

.build(handler: nil, if: nil, unless: nil, standalone: nil, join: nil, **unsupported) ⇒ Object

Raises:

  • (ArgumentError)


32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/axn/core/flow/handlers/descriptors/message_descriptor.rb', line 32

def self.build(handler: nil, if: nil, unless: nil, standalone: nil, join: nil, **unsupported)
  reject_unsupported_options!(unsupported)
  matcher = Matcher.build(if:, unless:)

  # Default by conditionality: an unconditional entry is the standalone base headline; a
  # conditional entry is an attached reason. standalone: false on an unconditional entry
  # promotes it into an attached reason (renders under the base); standalone: true on a
  # conditional reason opts it out (renders on its own).
  standalone = matcher.static? if standalone.nil?

  # join: combines the base with its reasons, so it only belongs on the base — an
  # unconditional, standalone headline. A reason (conditional, or a promoted standalone:false
  # entry) is rejected rather than silently ignored.
  base = matcher.static? && standalone
  raise ArgumentError, "join: only applies to the base (an unconditional headline)" if !join.nil? && !base
  raise ArgumentError, "join: must be a String or a callable ->(base, reason) {}" if !join.nil? && !(join.is_a?(String) || join.respond_to?(:call))

  new(handler:, standalone:, join:, matcher:)
end

.reject_unsupported_options!(options) ⇒ Object

Raise for any unknown option rather than silently dropping it. Surface ALL unknown keys at once so the caller fixes them in one pass rather than one error at a time.

Raises:

  • (ArgumentError)


24
25
26
27
28
29
30
# File 'lib/axn/core/flow/handlers/descriptors/message_descriptor.rb', line 24

def self.reject_unsupported_options!(options)
  return if options.empty?

  keys = options.keys.map(&:inspect).join(", ")
  label = options.size == 1 ? "Unknown #{keys} option" : "Unknown options #{keys}"
  raise ArgumentError, "#{label} for error/success message"
end

Instance Method Details

#standalone?Boolean

Returns:

  • (Boolean)


20
# File 'lib/axn/core/flow/handlers/descriptors/message_descriptor.rb', line 20

def standalone? = @standalone