Class: StudFinder::FanIn
- Inherits:
-
Object
- Object
- StudFinder::FanIn
- Defined in:
- lib/stud_finder/fan_in.rb
Overview
rubocop:disable Metrics/ClassLength
Defined Under Namespace
Classes: ReferenceCandidate, Result
Constant Summary collapse
- PATH_ROOTS =
%w[app lib test].freeze
- CLASS_OR_MODULE_TYPES =
%i[class module].freeze
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(repo_path:, files:, stderr: $stderr, rails_inference: true) ⇒ FanIn
constructor
A new instance of FanIn.
Constructor Details
#initialize(repo_path:, files:, stderr: $stderr, rails_inference: true) ⇒ FanIn
Returns a new instance of FanIn.
16 17 18 19 20 21 |
# File 'lib/stud_finder/fan_in.rb', line 16 def initialize(repo_path:, files:, stderr: $stderr, rails_inference: true) @repo_path = File.(repo_path) @files = files @stderr = stderr @rails_inference = rails_inference end |
Instance Method Details
#call ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/stud_finder/fan_in.rb', line 23 def call @warnings = [] constants = constant_ownership references = resolved_reference_sets(@files, constants) reverse_constants = constants.invert counts = @files.to_h { |file| [file, 0] } fan_out_counts = @files.to_h { |file| [file, 0] } dependents = @files.to_h { |file| [file, []] } dependencies = @files.to_h { |file| [file, []] } @files.each do |file| constant = constants[file] counts[file] = constant ? fan_in_count(file, constant, references) : 0 references[file]&.each do |ref_constant| dep_file = reverse_constants[ref_constant] next unless dep_file && dep_file != file fan_out_counts[file] += 1 dependencies[file] << dep_file dependents[dep_file] << file end end edges = @files.to_h do |file| [file, { dependents: dependents[file].uniq, dependencies: dependencies[file].uniq }] end Result.new(counts: counts, fan_out_counts: fan_out_counts, edges: edges, warnings: @warnings) end |