class AbstractImporter::Reporters::DebugReporter
Attributes
invalid_params[R]
Public Class Methods
new(io)
click to toggle source
Calls superclass method
AbstractImporter::Reporters::BaseReporter::new
# File lib/abstract_importer/reporters/debug_reporter.rb, line 6 def initialize(io) super @notices = {} @errors = {} @invalid_params = {} end
Public Instance Methods
count_error(message)
click to toggle source
# File lib/abstract_importer/reporters/debug_reporter.rb, line 75 def count_error(message) @errors[message] = (@errors[message] || 0) + 1 end
count_notice(message)
click to toggle source
# File lib/abstract_importer/reporters/debug_reporter.rb, line 71 def count_notice(message) @notices[message] = (@notices[message] || 0) + 1 end
file(s)
click to toggle source
# File lib/abstract_importer/reporters/debug_reporter.rb, line 65 def file(s) io.puts s.inspect end
finish_all(importer, ms)
click to toggle source
Calls superclass method
AbstractImporter::Reporters::BaseReporter#finish_all
# File lib/abstract_importer/reporters/debug_reporter.rb, line 19 def finish_all(importer, ms) print_invalid_params super end
finish_collection(collection, summary)
click to toggle source
# File lib/abstract_importer/reporters/debug_reporter.rb, line 38 def finish_collection(collection, summary) print_summary summary, collection.name print_messages @notices, "Notices" print_messages @errors, "Errors" end
finish_setup(importer, ms)
click to toggle source
Calls superclass method
AbstractImporter::Reporters::BaseReporter#finish_setup
# File lib/abstract_importer/reporters/debug_reporter.rb, line 26 def finish_setup(importer, ms) super end
record_failed(record, hash)
click to toggle source
# File lib/abstract_importer/reporters/debug_reporter.rb, line 46 def record_failed(record, hash) error_messages = invalid_params[record.class.name] ||= Hash.new { |hash, key| hash[key] = [] } record.errors.full_messages.each do |error_message| error_messages[error_message].push hash count_error(error_message) end end
start_all(importer)
click to toggle source
Calls superclass method
AbstractImporter::Reporters::BaseReporter#start_all
# File lib/abstract_importer/reporters/debug_reporter.rb, line 15 def start_all(importer) super end
start_collection(collection)
click to toggle source
Calls superclass method
AbstractImporter::Reporters::BaseReporter#start_collection
# File lib/abstract_importer/reporters/debug_reporter.rb, line 32 def start_collection(collection) super @notices = {} @errors = {} end
stat(s)
click to toggle source
# File lib/abstract_importer/reporters/debug_reporter.rb, line 60 def stat(s) io.puts " #{s}" end
Also aliased as: info
status(s)
click to toggle source
# File lib/abstract_importer/reporters/debug_reporter.rb, line 56 def status(s) io.puts s end
Private Instance Methods
print_invalid_params()
click to toggle source
# File lib/abstract_importer/reporters/debug_reporter.rb, line 83 def print_invalid_params return if invalid_params.empty? status "\n\n\n#{("="*80)}\nInvalid records\n#{("="*80)}" invalid_params.each do |model_name, errors| status "\n\n--#{model_name}#{("-"*(78 - model_name.length))}" errors.each do |error_message, hashes| status "\n #{error_message}:" hashes.each do |hash| status "\n" hash.each do |key, value| status " #{key.inspect}\t#{value.inspect}" end end end end end
print_messages(array, caption)
click to toggle source
# File lib/abstract_importer/reporters/debug_reporter.rb, line 114 def print_messages(array, caption) return if array.empty? status "\n--#{caption}#{("-"*(78-caption.length))}\n\n" array.each do |message, count| stat "#{count} × #{message}" end end
print_summary(summary, plural)
click to toggle source
# File lib/abstract_importer/reporters/debug_reporter.rb, line 100 def print_summary(summary, plural) stat "\n #{summary.total} #{plural} were found" if summary.total > 0 stat "#{summary.already_imported} #{plural} were imported previously" stat "#{summary.redundant} #{plural} would create duplicates and will not be imported" stat "#{summary.invalid} #{plural} were invalid" stat "#{summary.skipped} #{plural} were skipped" stat "#{summary.created} #{plural} were imported" stat "#{distance_of_time(summary.ms)} elapsed (#{summary.average_ms.to_i}ms each)" else stat "#{distance_of_time(summary.ms)} elapsed" end end