Class: Spellr::Check

Inherits:
Object
  • Object
show all
Defined in:
lib/spellr/check.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(files: [], reporter: Spellr.config.reporter) ⇒ Check

Returns a new instance of Check.



27
28
29
30
31
# File 'lib/spellr/check.rb', line 27

def initialize(files: [], reporter: Spellr.config.reporter)
  @files = files

  @main_reporter = @reporter = reporter
end

Instance Attribute Details

#filesObject (readonly)

Returns the value of attribute files.



21
22
23
# File 'lib/spellr/check.rb', line 21

def files
  @files
end

#reporterObject (readonly)

Returns the value of attribute reporter.



21
22
23
# File 'lib/spellr/check.rb', line 21

def reporter
  @reporter
end

Instance Method Details

#checkObject



33
34
35
36
37
38
39
40
41
# File 'lib/spellr/check.rb', line 33

def check
  return check_parallel if reporter.parallel?

  files.each do |file|
    check_and_count_file(file)
  end

  reporter.finish
end

#check_parallelObject

rubocop:disable Metrics/MethodLength



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/spellr/check.rb', line 43

def check_parallel # rubocop:disable Metrics/MethodLength
  acc_reporter = @reporter
  Parallel.each(files, finish: ->(_, _, result) { acc_reporter.output << result }) do |file|
    @reporter = acc_reporter.class.new(Spellr::OutputStubbed.new)
    check_and_count_file(file)
    reporter.output
  end
  @reporter = acc_reporter

  reporter.finish
end

#exit_codeObject



23
24
25
# File 'lib/spellr/check.rb', line 23

def exit_code
  reporter.exit_code
end