Class: RailsAiBridge::Introspectors::StaticPrismScanner
- Inherits:
-
Object
- Object
- RailsAiBridge::Introspectors::StaticPrismScanner
- Defined in:
- lib/rails_ai_bridge/introspectors/static_prism_scanner.rb
Overview
Optional Prism AST pass that finds controller filter macros and instance method definitions in source files.
Facts found this way carry provenance: :prism, so the tools layer can
render them as [VERIFIED]. Prism is not a gem dependency. When it cannot
be loaded, or the scan fails, facts_for returns an error hash and never raises.
Constant Summary collapse
- FILTER_MACROS =
Controller macros whose symbol arguments name filters.
%i[ before_action after_action around_action skip_before_action skip_after_action skip_around_action ].freeze
- NODE_ROLES =
Prism node classes, by short name, mapped to the role each plays in the walk. Names are strings so this file does not reference Prism when it loads.
{ 'ClassNode' => :class, 'ModuleNode' => :module, 'SingletonClassNode' => :singleton, 'BlockNode' => :block, 'DefNode' => :def, 'CallNode' => :call }.freeze
- NAMESPACE_ROLES =
Scopes whose name becomes part of the owner of the methods inside them.
%i[class module].freeze
Instance Method Summary collapse
-
#facts_for(path) ⇒ Hash
{ facts: [...] }on success, or{ error: String }when Prism is unavailable, the file limit is reached, or the file cannot be read or parsed. -
#initialize(max_files:, loader: -> { require 'prism' }) ⇒ StaticPrismScanner
constructor
A new instance of StaticPrismScanner.
Constructor Details
#initialize(max_files:, loader: -> { require 'prism' }) ⇒ StaticPrismScanner
Returns a new instance of StaticPrismScanner.
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/rails_ai_bridge/introspectors/static_prism_scanner.rb', line 34 def initialize(max_files:, loader: -> { require 'prism' }) @max_files = max_files @files_read = 0 @prism_available = begin loader.call true rescue LoadError false end end |
Instance Method Details
#facts_for(path) ⇒ Hash
Returns { facts: [...] } on success, or { error: String } when Prism is
unavailable, the file limit is reached, or the file cannot be read or parsed.
48 49 50 51 52 53 54 55 |
# File 'lib/rails_ai_bridge/introspectors/static_prism_scanner.rb', line 48 def facts_for(path) blocked_reason = scan_blocked_reason return { error: blocked_reason } if blocked_reason scan(path) rescue StandardError => error { error: "prism scan failed: #{error.}" } end |