Class: RailsAiContext::Introspectors::SourceIntrospector
- Inherits:
-
Object
- Object
- RailsAiContext::Introspectors::SourceIntrospector
- 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
-
.call(path) ⇒ Object
Introspect a file on disk (cached parse) with default listeners.
-
.from_source(source) ⇒ Object
Introspect a source string (no caching) with default listeners.
-
.walk(path, listener_map = LISTENER_MAP) ⇒ Object
Walk a file with a custom listener map.
-
.walk_source(source, listener_map = LISTENER_MAP) ⇒ Object
Walk a source string with a custom listener map.
Class Method Details
.call(path) ⇒ Object
Introspect a file on disk (cached parse) with default listeners.
27 28 29 30 |
# File 'lib/rails_ai_context/introspectors/source_introspector.rb', line 27 def self.call(path) result = AstCache.parse(path) walk_dispatch(result, LISTENER_MAP) end |
.from_source(source) ⇒ Object
Introspect a source string (no caching) with default listeners.
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) walk_dispatch(result, LISTENER_MAP) end |
.walk(path, listener_map = LISTENER_MAP) ⇒ Object
Walk a file with a custom listener map. Returns { key => results_array }.
39 40 41 42 |
# File 'lib/rails_ai_context/introspectors/source_introspector.rb', line 39 def self.walk(path, listener_map = LISTENER_MAP) result = AstCache.parse(path) walk_dispatch(result, listener_map) end |
.walk_source(source, listener_map = LISTENER_MAP) ⇒ Object
Walk a source string with a custom listener map. Returns { key => results_array }.
45 46 47 48 |
# File 'lib/rails_ai_context/introspectors/source_introspector.rb', line 45 def self.walk_source(source, listener_map = LISTENER_MAP) result = AstCache.parse_string(source) walk_dispatch(result, listener_map) end |