Class: StudFinder::Complexity
- Inherits:
-
Object
- Object
- StudFinder::Complexity
- Defined in:
- lib/stud_finder/complexity.rb
Defined Under Namespace
Constant Summary collapse
- COMPLEXITY_COP =
'Metrics/CyclomaticComplexity'- COMPLEXITY_PATTERN =
%r{\[(\d+)/0\]}- INVALID_ENCODING_PATTERN =
/invalid byte sequence/i- PARSE_ERROR_COPS =
%w[Lint/Syntax].freeze
- BATCH_SIZE =
500- RUBOCOP_CONFIG =
<<~YAML AllCops: DisabledByDefault: true NewCops: disable Metrics/CyclomaticComplexity: Enabled: true Max: 0 YAML
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(repo_path:, files:, stderr: $stderr) ⇒ Complexity
constructor
A new instance of Complexity.
Constructor Details
#initialize(repo_path:, files:, stderr: $stderr) ⇒ Complexity
Returns a new instance of Complexity.
27 28 29 30 31 |
# File 'lib/stud_finder/complexity.rb', line 27 def initialize(repo_path:, files:, stderr: $stderr) @repo_path = File.(repo_path) @files = files @stderr = stderr end |
Instance Method Details
#call ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/stud_finder/complexity.rb', line 33 def call counts = zero_counts skipped = [] @files.each_slice(BATCH_SIZE) do |batch| result = run_batch(batch) counts.merge!(result.counts) { |_file, old, new| [old, new].max } skipped.concat(result.skipped_files) end skipped.uniq.each { |file| counts.delete(file) } Result.new(counts: counts, skipped_files: skipped.uniq) rescue Errno::ENOENT raise Error, 'Error: rubocop not found. Install it: gem install rubocop' rescue JSON::ParserError => e raise Error, "Error: failed to parse RuboCop JSON output: #{e.}" end |