Class: CodeKeeper::Scorer

Inherits:
Object
  • Object
show all
Defined in:
lib/code_keeper/scorer.rb

Overview

Run and store score of metrics.

Class Method Summary collapse

Class Method Details

.keep(paths) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/code_keeper/scorer.rb', line 7

def keep(paths)
  result = CodeKeeper::Result.new
  metrics = result.scores.keys
  ruby_file_paths = Finder.new(paths).file_paths
  num_threads = CodeKeeper.config.number_of_threads

  # NOTE: If the configuration says no concurrent execution, the parallel gem is not used.
  # `in_threads: 1` makes 2 threads, a sleep_forever thread and the main thread.
  if num_threads == 1
    ruby_file_paths.each do |path|
      metrics.each { |metric| calculate_score(metric, path, result) }
    end
  else
    Parallel.map(ruby_file_paths, in_threads: num_threads) do |path|
      metrics.each { |metric| calculate_score(metric, path, result) }
    end
  end

  result
end