Class: Yalphabetize::Logger

Inherits:
Object
  • Object
show all
Defined in:
lib/yalphabetize/logger.rb

Constant Summary collapse

DEFAULT_OUTPUT =
Kernel

Instance Method Summary collapse

Constructor Details

#initializeLogger

Returns a new instance of Logger.



7
8
9
10
# File 'lib/yalphabetize/logger.rb', line 7

def initialize
  @inspected_count = 0
  @offences = {}
end

Instance Method Details

#final_summaryObject



27
28
29
30
31
32
33
34
35
# File 'lib/yalphabetize/logger.rb', line 27

def final_summary
  DEFAULT_OUTPUT.puts "\nInspected: #{inspected_count}"
  DEFAULT_OUTPUT.puts send(list_offences_color, "Offences: #{offences.size}")

  offences.each { |file_path, status| puts_offence(file_path, status) }
  return unless uncorrected_offences?

  DEFAULT_OUTPUT.puts 'Offences can be automatically fixed with `-a` or `--autocorrect`'
end

#initial_summary(file_paths) ⇒ Object



12
13
14
# File 'lib/yalphabetize/logger.rb', line 12

def initial_summary(file_paths)
  DEFAULT_OUTPUT.puts "Inspecting #{file_paths.size} YAML files"
end

#log_correction(file_path) ⇒ Object



41
42
43
# File 'lib/yalphabetize/logger.rb', line 41

def log_correction(file_path)
  offences[file_path] = :corrected
end

#log_no_offenceObject



22
23
24
25
# File 'lib/yalphabetize/logger.rb', line 22

def log_no_offence
  self.inspected_count += 1
  DEFAULT_OUTPUT.print green '.'
end

#log_offence(file_path) ⇒ Object



16
17
18
19
20
# File 'lib/yalphabetize/logger.rb', line 16

def log_offence(file_path)
  self.inspected_count += 1
  offences[file_path] = :detected
  DEFAULT_OUTPUT.print red 'O'
end

#uncorrected_offences?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/yalphabetize/logger.rb', line 37

def uncorrected_offences?
  offences.value?(:detected)
end