Module: RailsAiContext::Introspectors::StaticTier

Overview

What an introspector can answer when the host app did not boot. Extending this and declaring a kind is how an introspector becomes reachable in the static tier; an undeclared one is a spec failure, so "works statically but never said so" cannot be written.

See docs/adr/0002-static-tier-declared-not-detected.md.

Constant Summary collapse

FILES_ONLY =

call runs unchanged against the static app handle.

:files_only
RUNTIME_ONLY =

Needs live reflection; refuses honestly.

:runtime_only
ALTERNATE_SOURCE =

Answers from a different source through static_call.

:alternate_source
KINDS =
[ FILES_ONLY, RUNTIME_ONLY, ALTERNATE_SOURCE ].freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.unavailable_reasonObject

One wording for "the app did not boot", carrying whatever the boot failure said. Forked copies drift, and a single run then emits two different explanations for the same condition.



24
25
26
27
28
# File 'lib/rails_ai_context/introspectors/static_tier.rb', line 24

def self.unavailable_reason
  reason = RailsAiContext.static_reason
  base = "requires a booted Rails app"
  reason ? "#{base} (#{reason})" : base
end

Instance Method Details

#answers_statically?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/rails_ai_context/introspectors/static_tier.rb', line 44

def answers_statically?
  [ FILES_ONLY, ALTERNATE_SOURCE ].include?(static_tier)
end

#static_tier(kind = nil) ⇒ Object



30
31
32
33
34
35
36
37
38
# File 'lib/rails_ai_context/introspectors/static_tier.rb', line 30

def static_tier(kind = nil)
  return declared_static_tier if kind.nil?

  unless KINDS.include?(kind)
    raise ArgumentError, "#{self}: unknown static tier #{kind.inspect}, expected one of #{KINDS.join(', ')}"
  end

  @static_tier = kind
end

#static_tier_declared?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/rails_ai_context/introspectors/static_tier.rb', line 40

def static_tier_declared?
  !static_tier.nil?
end

#validate_static_tier!Object

The declaration and the method have to agree, or the runner would call something that does not exist, or skip one that does. Checked on demand because the macro runs before the class body defines its methods.

Raises:

  • (ArgumentError)


51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/rails_ai_context/introspectors/static_tier.rb', line 51

def validate_static_tier!
  kind = static_tier
  raise ArgumentError, "#{self} declares no static tier" if kind.nil?

  defines_static_call = method_defined?(:static_call) || private_method_defined?(:static_call)

  if kind == ALTERNATE_SOURCE && !defines_static_call
    raise ArgumentError, "#{self} declares #{kind} but defines no static_call"
  end

  if kind != ALTERNATE_SOURCE && defines_static_call
    raise ArgumentError, "#{self} declares #{kind} but defines static_call; declare alternate_source instead"
  end

  kind
end