Module: Axn::Core::Contract::InstanceMethods

Defined in:
lib/axn/core/contract.rb

Instance Method Summary collapse

Instance Method Details

#clear_execution_contextObject

Clear any previously set additional execution context



403
404
405
# File 'lib/axn/core/contract.rb', line 403

def clear_execution_context
  @__additional_execution_context = nil
end

#execution_contextObject

Returns a structured hash for exception reporting and handlers. Contains :inputs, :outputs, and any extra keys from set_execution_context / additional_execution_context hook. Reserved keys (:inputs, :outputs) from extra context are stripped before merging at top level.



410
411
412
413
414
415
416
# File 'lib/axn/core/contract.rb', line 410

def execution_context
  explicit_context = @__additional_execution_context || {}
  hook_context = respond_to?(:additional_execution_context, true) ? additional_execution_context : {}
  extra_context = explicit_context.merge(hook_context).except(*RESERVED_EXECUTION_CONTEXT_KEYS)

  { inputs: inputs_for_logging, outputs: outputs_for_logging, **extra_context }
end

#expose(*args, **kwargs) ⇒ Object

Accepts either two positional arguments (key, value) or a hash of key/value pairs



377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
# File 'lib/axn/core/contract.rb', line 377

def expose(*args, **kwargs)
  if args.any?
    if args.size != 2
      raise ArgumentError,
            "expose must be called with exactly two positional arguments (or a hash of key/value pairs)"
    end

    kwargs.merge!(args.first => args.last)
  end

  kwargs.each do |key, value|
    raise Axn::ContractViolation::UnknownExposure, key unless result.respond_to?(key)

    @__context.exposed_data[key] = value
  end
end

#internal_contextObject



371
# File 'lib/axn/core/contract.rb', line 371

def internal_context = @internal_context ||= _build_context_facade(:inbound)

#resultObject



372
# File 'lib/axn/core/contract.rb', line 372

def result = @result ||= _build_context_facade(:outbound)

#set_execution_context(**kwargs) ⇒ Object

Set additional context to be included in execution_context for exception reporting/handlers. This context is NOT included in automatic pre/post logging (which only logs inputs/outputs). Reserved keys (:inputs, :outputs) are stripped before merging.



397
398
399
400
# File 'lib/axn/core/contract.rb', line 397

def set_execution_context(**kwargs)
  @__additional_execution_context ||= {}
  @__additional_execution_context.merge!(kwargs.except(*RESERVED_EXECUTION_CONTEXT_KEYS))
end