class Yalphabetize::Logger
Constants
- DEFAULT_OUTPUT
Attributes
Public Class Methods
Source
# File lib/yalphabetize/logger.rb, line 7 def initialize @inspected_count = 0 @offences = {} end
Public Instance Methods
Source
# 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
Source
# File lib/yalphabetize/logger.rb, line 12 def initial_summary(file_paths) DEFAULT_OUTPUT.puts "Inspecting #{file_paths.size} YAML files" end
Source
# File lib/yalphabetize/logger.rb, line 41 def log_correction(file_path) offences[file_path] = :corrected end
Source
# File lib/yalphabetize/logger.rb, line 22 def log_no_offence self.inspected_count += 1 DEFAULT_OUTPUT.print green '.' end
Source
# 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
Source
# File lib/yalphabetize/logger.rb, line 37 def uncorrected_offences? offences.value?(:detected) end
Private Instance Methods
Source
# File lib/yalphabetize/logger.rb, line 71 def green(string) with_color(32, string) end
Source
# File lib/yalphabetize/logger.rb, line 59 def list_offences_color offences.any? ? :red : :green end
Source
# File lib/yalphabetize/logger.rb, line 50 def puts_offence(file_path, status) case status when :detected DEFAULT_OUTPUT.puts yellow file_path when :corrected DEFAULT_OUTPUT.puts("#{yellow(file_path)} #{green('CORRECTED')}") end end
Source
# File lib/yalphabetize/logger.rb, line 63 def red(string) with_color(31, string) end
Source
# File lib/yalphabetize/logger.rb, line 75 def with_color(color, string) "\e[#{color}m#{string}\e[0m" end
Source
# File lib/yalphabetize/logger.rb, line 67 def yellow(string) with_color(33, string) end