Class: Yalphabetize::Logger
- Inherits:
-
Object
- Object
- Yalphabetize::Logger
- Defined in:
- lib/yalphabetize/logger.rb
Constant Summary collapse
- DEFAULT_OUTPUT =
$stdout
Instance Method Summary collapse
- #final_summary ⇒ Object
- #initial_summary(file_paths) ⇒ Object
-
#initialize(output = DEFAULT_OUTPUT) ⇒ Logger
constructor
A new instance of Logger.
- #log_correction(file_path) ⇒ Object
- #log_no_offence ⇒ Object
- #log_offence(file_path) ⇒ Object
- #uncorrected_offences? ⇒ Boolean
Constructor Details
#initialize(output = DEFAULT_OUTPUT) ⇒ Logger
Returns a new instance of Logger.
7 8 9 10 11 |
# File 'lib/yalphabetize/logger.rb', line 7 def initialize(output = DEFAULT_OUTPUT) @output = output @inspected_count = 0 @offences = {} end |
Instance Method Details
#final_summary ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/yalphabetize/logger.rb', line 28 def final_summary output.puts "\nInspected: #{inspected_count}" output.puts send(list_offences_color, "Offences: #{offences.size}") offences.each { |file_path, status| puts_offence(file_path, status) } return unless uncorrected_offences? output.puts 'Offences can be automatically fixed with `-a` or `--autocorrect`' end |
#initial_summary(file_paths) ⇒ Object
13 14 15 |
# File 'lib/yalphabetize/logger.rb', line 13 def initial_summary(file_paths) output.puts "Inspecting #{file_paths.size} YAML files" end |
#log_correction(file_path) ⇒ Object
42 43 44 |
# File 'lib/yalphabetize/logger.rb', line 42 def log_correction(file_path) offences[file_path] = :corrected end |
#log_no_offence ⇒ Object
23 24 25 26 |
# File 'lib/yalphabetize/logger.rb', line 23 def log_no_offence self.inspected_count += 1 output.print green '.' end |
#log_offence(file_path) ⇒ Object
17 18 19 20 21 |
# File 'lib/yalphabetize/logger.rb', line 17 def log_offence(file_path) self.inspected_count += 1 offences[file_path] = :detected output.print red 'O' end |
#uncorrected_offences? ⇒ Boolean
38 39 40 |
# File 'lib/yalphabetize/logger.rb', line 38 def uncorrected_offences? offences.value?(:detected) end |