Module: Axn::Internal::CurrentCallOptions

Defined in:
lib/axn/internal/current_call_options.rb

Overview

Per-call tuning gates set by a caller (today only Axn::Tools::Invoker) and read once by the executor. Scoped via IsolatedExecutionState (same pattern as Async::CurrentRetryContext) so nothing rides on .call's kwargs. The executor consumes (reads + clears) at the top of its contract phase, so the gates apply to exactly the wrapped action and a nested .call in its body sees a cleared holder and runs with default semantics.

Defined Under Namespace

Classes: Options

Class Method Summary collapse

Class Method Details

.coerce_input_types_for(action) ⇒ Object

The effective coerce_input_types for action's current call: a non-nil per-call gate wins, else the class/global setting — so a normal call resolves exactly as before. Single-sourced so the executor's validation-message path and the read-path value coercion (ContractForSubfields) decide identically.



46
47
48
49
# File 'lib/axn/internal/current_call_options.rb', line 46

def coerce_input_types_for(action)
  per_call = for_action(action)&.coerce_input_types
  per_call.nil? ? Axn::Configuration.resolve_override_for(action.class, :coerce_input_types) : per_call
end

.consumeObject

Read the current options and clear the holder, so the reading action takes sole ownership and nested sub-actions do not inherit the gates.



30
# File 'lib/axn/internal/current_call_options.rb', line 30

def consume = current.tap { self.current = nil }

.currentObject



14
# File 'lib/axn/internal/current_call_options.rb', line 14

def current = ActiveSupport::IsolatedExecutionState[:_axn_call_options]

.current=(value) ⇒ Object



16
17
18
# File 'lib/axn/internal/current_call_options.rb', line 16

def current=(value)
  ActiveSupport::IsolatedExecutionState[:_axn_call_options] = value
end

.for_action(action) ⇒ Object

The Options in force for action's current call, or nil for a normal call. The executor stashes the consumed Options on the action at the top of its contract phase (per-call state lives on the action instance), so the read-path coercion can reach the same gate the executor's validation-message path reads.



36
37
38
39
40
# File 'lib/axn/internal/current_call_options.rb', line 36

def for_action(action)
  return nil unless action.instance_variable_defined?(:@__call_options)

  action.instance_variable_get(:@__call_options)
end

.with(coerce_input_types: nil, user_facing_input_errors: false, reject_undeclared_inputs: false) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/axn/internal/current_call_options.rb', line 20

def with(coerce_input_types: nil, user_facing_input_errors: false, reject_undeclared_inputs: false)
  previous = current
  self.current = Options.new(coerce_input_types:, user_facing_input_errors:, reject_undeclared_inputs:)
  yield
ensure
  self.current = previous
end