Class: RailsAiContext::Introspectors::SourceIntrospector

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_ai_context/introspectors/source_introspector.rb

Overview

Single-pass Prism AST introspector using the Dispatcher pattern. Walks the AST once and feeds events to all registered listeners, extracting associations, validations, scopes, enums, callbacks, macros, and methods in a single tree traversal.

Can be called with a file path (cached via AstCache) or a source string.

Constant Summary collapse

LISTENER_MAP =

Map result keys to listener classes. Iteration order is preserved (Ruby >= 1.9), but results are accessed by key — never by index.

{
  associations: Listeners::AssociationsListener,
  validations:  Listeners::ValidationsListener,
  scopes:       Listeners::ScopesListener,
  enums:        Listeners::EnumsListener,
  callbacks:    Listeners::CallbacksListener,
  macros:       Listeners::MacrosListener,
  methods:      Listeners::MethodsListener
}.freeze

Class Method Summary collapse

Class Method Details

.call(path) ⇒ Object

Introspect a file on disk (cached parse).



27
28
29
30
# File 'lib/rails_ai_context/introspectors/source_introspector.rb', line 27

def self.call(path)
  result = AstCache.parse(path)
  dispatch(result)
end

.from_source(source) ⇒ Object

Introspect a source string (no caching).



33
34
35
36
# File 'lib/rails_ai_context/introspectors/source_introspector.rb', line 33

def self.from_source(source)
  result = AstCache.parse_string(source)
  dispatch(result)
end