Class: FiberAudit::Static::ExecutionContextResolver

Inherits:
Object
  • Object
show all
Defined in:
lib/fiber_audit/static/execution_context_resolver.rb

Overview

Resolves execution context for call sites based on semantic ancestry, path heuristics, and callback DSL patterns.

Resolution priority:

  1. Semantic inheritance (outranks path)
  2. Path-based fallback
  3. Callback DSL sniff
  4. :unknown

Never raises; always returns a Context symbol.

Constant Summary collapse

SEMANTIC_SIGNALS =

Semantic ancestry signals mapped to contexts

{
  'ActionController::Base' => Context::REQUEST,
  'ActionController::API' => Context::REQUEST,
  'ActionJob::Base' => Context::JOB, # typo tolerance
  'ActiveJob::Base' => Context::JOB,
  'ActionCable::Channel::Base' => Context::WEBSOCKET,
  'ActionView::Base' => Context::VIEW
}.freeze
CALLBACK_ANCESTORS =

Callback model ancestors (ActiveRecord/model ancestry only)

%w[
  ActiveRecord::Base
].freeze

Instance Method Summary collapse

Constructor Details

#initialize(workspace:) ⇒ ExecutionContextResolver

Returns a new instance of ExecutionContextResolver.

Parameters:

  • workspace (Object)

    responds to ancestors_of(name) OR exposes semantic_index



34
35
36
37
# File 'lib/fiber_audit/static/execution_context_resolver.rb', line 34

def initialize(workspace:)
  @workspace = workspace
  @ancestor_cache = {}
end

Instance Method Details

#resolve(call_site:) ⇒ Symbol

Resolve context for a single call site

Parameters:

  • call_site (CallSite)

    a call site with path, enclosing_symbol, nesting

Returns:

  • (Symbol)

    one of Context::ALL



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/fiber_audit/static/execution_context_resolver.rb', line 42

def resolve(call_site:)
  path = call_site.path
  enclosing = call_site.enclosing_symbol
  nesting = Array(call_site.nesting)

  # Try semantic inheritance first (outranks path)
  semantic = resolve_from_semantics(enclosing, nesting)
  return semantic if semantic

  # Path-based fallback
  path_ctx = resolve_from_path(path, enclosing)
  return path_ctx if path_ctx

  # Callback DSL sniff
  callback_ctx = resolve_callback(enclosing, nesting)
  return callback_ctx if callback_ctx

  Context::UNKNOWN
rescue StandardError
  Context::UNKNOWN
end

#resolve_all(call_sites:) ⇒ Array<CallSite>

Resolve contexts for all call sites, returning new CallSite objects with execution_context populated. Does not mutate originals.

Never silently returns an unchanged object when copying fails— unknown is still populated where compatible.

Parameters:

Returns:

  • (Array<CallSite>)

    new array in original order



71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/fiber_audit/static/execution_context_resolver.rb', line 71

def resolve_all(call_sites:)
  Array(call_sites).map do |cs|
    ctx = resolve(call_site: cs)
    copy_with_context(cs, ctx)
  end
rescue StandardError
  # If batch fails, try individually with :unknown.
  # If copy itself fails (not a Data type), let it propagate—
  # never silently return an unchanged object.
  Array(call_sites).map do |cs|
    copy_with_context(cs, Context::UNKNOWN)
  end
end