Class: Axn::Core::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/axn/core/context.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**provided_data) ⇒ Context

Returns a new instance of Context.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/axn/core/context.rb', line 6

def initialize(**provided_data)
  # Normalize inbound keys to symbols so the read path has indifferent access: a declared field's
  # key (always symbolized at declaration) matches the call-arg key regardless of how the caller
  # spelled it. Splatting JSON/HTTP params straight into `.call(**body)` (string keys) Just Works
  # instead of silently reading nil. Top-level keys only — values (including nested hashes) are
  # untouched. Async deserialize paths already re-symbolize keys before re-invoking, so this is
  # consistent with the round-trip (see Axn::Async serialization). See PRO-2790.
  @provided_data = provided_data.transform_keys(&:to_sym)
  @exposed_data = {}

  # Framework-managed fields
  @failure = false
  @exception = nil
  @elapsed_time = nil
  @early_completion_standalone = false
end

Instance Attribute Details

#elapsed_timeObject

Framework field accessors



29
30
31
# File 'lib/axn/core/context.rb', line 29

def elapsed_time
  @elapsed_time
end

#exceptionObject (readonly)

Returns the value of attribute exception.



30
31
32
# File 'lib/axn/core/context.rb', line 30

def exception
  @exception
end

#exposed_dataObject

Framework field accessors



29
30
31
# File 'lib/axn/core/context.rb', line 29

def exposed_data
  @exposed_data
end

#provided_dataObject

Framework field accessors



29
30
31
# File 'lib/axn/core/context.rb', line 29

def provided_data
  @provided_data
end

Instance Method Details

#__classified_as_failure?Boolean

Returns:

  • (Boolean)


52
# File 'lib/axn/core/context.rb', line 52

def __classified_as_failure? = @classified_as_failure || false

#__classify_as_failure!Object

Recorded by the executor when an exception settles as a failure (a fail!, a fails_on match, or a nested fails_on made sticky) rather than an unhandled exception. result.outcome reads this so the failure/exception distinction survives after the per-execution classification set is cleared.



51
# File 'lib/axn/core/context.rb', line 51

def __classify_as_failure! = @classified_as_failure = true

#__combined_dataObject

INTERNAL: base for further filtering (for logging) or providing user with usage hints



38
# File 'lib/axn/core/context.rb', line 38

def __combined_data = @provided_data.merge(@exposed_data)

#__early_completion?Boolean

Returns:

  • (Boolean)


40
# File 'lib/axn/core/context.rb', line 40

def __early_completion? = @early_completion || false

#__early_completion_messageObject



64
# File 'lib/axn/core/context.rb', line 64

def __early_completion_message = @early_completion_message.presence

#__early_completion_standaloneObject



65
# File 'lib/axn/core/context.rb', line 65

def __early_completion_standalone = @early_completion_standalone

#__finalize!Object



67
68
69
# File 'lib/axn/core/context.rb', line 67

def __finalize!
  @finalized = true
end

#__record_early_completion(message, standalone: false) ⇒ Object



54
55
56
57
58
59
60
61
62
# File 'lib/axn/core/context.rb', line 54

def __record_early_completion(message, standalone: false)
  # Only store a real (non-sentinel) message, but always record the standalone opt-out so a bare
  # `done!(standalone: true)` isn't silently dropped (it's moot when no message resolves, but the
  # flag must reflect the call rather than retain the default).
  @early_completion_message = message unless message == Axn::Internal::EarlyCompletion.new.message
  @early_completion_standalone = standalone
  @early_completion = true
  @finalized = true
end

#__record_exception(e) ⇒ Object



42
43
44
45
46
# File 'lib/axn/core/context.rb', line 42

def __record_exception(e)
  @exception = e
  @failure = true
  @finalized = true
end

#failed?Boolean

Returns:

  • (Boolean)


25
# File 'lib/axn/core/context.rb', line 25

def failed? = @failure || false

#finalized?Boolean

Returns:

  • (Boolean)


26
# File 'lib/axn/core/context.rb', line 26

def finalized? = @finalized || false

#ok?Boolean

Framework state methods

Returns:

  • (Boolean)


24
# File 'lib/axn/core/context.rb', line 24

def ok? = !@failure