Class: StudFinder::Edges

Inherits:
Object
  • Object
show all
Defined in:
lib/stud_finder/edges.rb

Defined Under Namespace

Classes: CouplingConfig

Constant Summary collapse

MAX_ROWS =
50

Instance Method Summary collapse

Constructor Details

#initialize(target:, rows:, edges:, coupling: {}, churn_days: 180, coupling_min_commits: 5, coupling_threshold: 0.30, stdout: $stdout, stderr: $stderr) ⇒ Edges

Returns a new instance of Edges.



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/stud_finder/edges.rb', line 9

def initialize(target:, rows:, edges:, coupling: {}, churn_days: 180,
               coupling_min_commits: 5, coupling_threshold: 0.30,
               stdout: $stdout, stderr: $stderr)
  @target = target
  @rows = rows.to_h { |row| [row[:path], row] }
  @edges = edges
  @coupling = CouplingConfig.new(data: coupling, churn_days: churn_days,
                                 min_commits: coupling_min_commits, threshold: coupling_threshold)
  @stdout = stdout
  @stderr = stderr
end

Instance Method Details

#callObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/stud_finder/edges.rb', line 21

def call
  if @target.nil? || @target.empty?
    @stderr.puts 'Usage: stud-finder edges FILE [PATH]'
    return 1
  end

  unless @edges.key?(@target)
    @stderr.puts "Error: '#{@target}' was not found in the scored file set."
    return 1
  end

  target_row = @rows[@target]
  edge_data = @edges[@target]

  emit_header(target_row)
  emit_section('Dependents', edge_data[:dependents], '(files that depend on this file — blast radius)')
  emit_section('Dependencies', edge_data[:dependencies], '(files this file depends on — fan-out)')
  emit_coupling_section
  @stdout.puts
  @stdout.puts 'Edges are statically computed — dynamic references not counted.'
  @stdout.puts "Temporal coupling from git history (#{@coupling.churn_days}-day window)."
  0
end