Module: DatabaseConsistency::PrismHelper
- Defined in:
- lib/database_consistency/prism_helper.rb
Overview
The module contains Prism AST helper methods for scanning project source files.
Class Method Summary collapse
- .build_find_by_calls_index ⇒ Object
-
.find_by_calls_index ⇒ Object
Returns a memoized index: => {column_name => “file:line”}.
- .merge_collector_results(results, index) ⇒ Object
Class Method Details
.build_find_by_calls_index ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/database_consistency/prism_helper.rb', line 17 def build_find_by_calls_index FilesHelper.project_source_files.each_with_object({}) do |file, index| collector = Checkers::MissingIndexFindByChecker::FindByCollector.new(file) collector.visit(Prism.parse_file(file).value) merge_collector_results(collector.results, index) rescue StandardError nil end end |
.find_by_calls_index ⇒ Object
Returns a memoized index: => {column_name => “file:line”}. Built once per run by scanning all project source files with Prism (Ruby 3.3+). Bare find_by calls are resolved to their lexical class/module scope.
11 12 13 14 15 |
# File 'lib/database_consistency/prism_helper.rb', line 11 def find_by_calls_index return {} unless defined?(Prism) @find_by_calls_index ||= build_find_by_calls_index end |
.merge_collector_results(results, index) ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/database_consistency/prism_helper.rb', line 27 def merge_collector_results(results, index) results.each do |(model_key, col), locations| index[model_key] ||= {} if (entry = index[model_key][col]) entry[:total_findings_count] += locations.size else index[model_key][col] = { first_location: locations.first, total_findings_count: locations.size } end end end |