Class: StudFinder::FanIn
- Inherits:
-
Object
- Object
- StudFinder::FanIn
- Defined in:
- lib/stud_finder/fan_in.rb
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) ⇒ FanIn
constructor
A new instance of FanIn.
Constructor Details
#initialize(repo_path:, files:, stderr: $stderr) ⇒ FanIn
Returns a new instance of FanIn.
14 15 16 17 18 |
# File 'lib/stud_finder/fan_in.rb', line 14 def initialize(repo_path:, files:, stderr: $stderr) @repo_path = File.(repo_path) @files = files @stderr = stderr end |
Instance Method Details
#call ⇒ Object
20 21 22 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 |
# File 'lib/stud_finder/fan_in.rb', line 20 def call 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) end |