Class: ChurnVsComplexity::Delta::ComplexityAnnotator

Inherits:
Object
  • Object
show all
Defined in:
lib/churn_vs_complexity/delta/complexity_annotator.rb

Instance Method Summary collapse

Constructor Details

#initialize(factory:, changes:) ⇒ ComplexityAnnotator

Returns a new instance of ComplexityAnnotator.



6
7
8
9
# File 'lib/churn_vs_complexity/delta/complexity_annotator.rb', line 6

def initialize(factory:, changes:)
  @factory = factory
  @changes = changes
end

Instance Method Details

#enhance(worktree_folder:, language:, excluded:, commit:) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/churn_vs_complexity/delta/complexity_annotator.rb', line 11

def enhance(worktree_folder:, language:, excluded:, commit:)
  @changes.each do |change|
    change[:full_path] = File.join(worktree_folder, change[:path])
  end

  files = @changes.reject { |change| change[:type] == :deleted }.map { |change| change[:full_path] }

  engine = @factory.engine(cache_components: [worktree_folder, commit], language:, excluded:, files:)

  values_by_file = engine.check(folder: worktree_folder)[:values_by_file]

  valid_extensions = FileSelector.extensions(language)
  @changes.select! { |change| valid_extensions.any? { |ext| change[:path].end_with?(ext) } }
  @changes.each do |annotated_file|
    annotated_file[:complexity] = values_by_file.dig(annotated_file[:full_path], 1)
  end
end