Class: AbstractImporter::Reporters::DebugReporter

Inherits:
BaseReporter
  • Object
show all
Defined in:
lib/abstract_importer/reporters/debug_reporter.rb

Direct Known Subclasses

DotReporter

Instance Attribute Summary collapse

Attributes inherited from BaseReporter

#io

Instance Method Summary collapse

Methods inherited from BaseReporter

#record_created

Constructor Details

#initialize(io) ⇒ DebugReporter

Returns a new instance of DebugReporter.



6
7
8
9
10
11
# File 'lib/abstract_importer/reporters/debug_reporter.rb', line 6

def initialize(io)
  super
  @notices = {}
  @errors  = {}
  @invalid_params = {}
end

Instance Attribute Details

#invalid_paramsObject (readonly)

Returns the value of attribute invalid_params.



4
5
6
# File 'lib/abstract_importer/reporters/debug_reporter.rb', line 4

def invalid_params
  @invalid_params
end

Instance Method Details

#count_error(message) ⇒ Object



82
83
84
# File 'lib/abstract_importer/reporters/debug_reporter.rb', line 82

def count_error(message)
  @errors[message] = (@errors[message] || 0) + 1
end

#count_notice(message) ⇒ Object



77
78
79
80
# File 'lib/abstract_importer/reporters/debug_reporter.rb', line 77

def count_notice(message)
  return if production?
  @notices[message] = (@notices[message] || 0) + 1
end

#file(s) ⇒ Object



71
72
73
# File 'lib/abstract_importer/reporters/debug_reporter.rb', line 71

def file(s)
  io.puts s.inspect
end

#finish_all(importer, ms) ⇒ Object



25
26
27
28
# File 'lib/abstract_importer/reporters/debug_reporter.rb', line 25

def finish_all(importer, ms)
  print_invalid_params
  super
end

#finish_collection(collection, summary) ⇒ Object



44
45
46
47
48
# File 'lib/abstract_importer/reporters/debug_reporter.rb', line 44

def finish_collection(collection, summary)
  print_summary summary, collection.name
  print_messages @notices, "Notices"
  print_messages @errors,  "Errors"
end

#finish_setup(ms) ⇒ Object



32
33
34
# File 'lib/abstract_importer/reporters/debug_reporter.rb', line 32

def finish_setup(ms)
  super
end

#production?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/abstract_importer/reporters/debug_reporter.rb', line 15

def production?
  Rails.env.production?
end

#record_failed(record, hash) ⇒ Object



52
53
54
55
56
57
58
# File 'lib/abstract_importer/reporters/debug_reporter.rb', line 52

def record_failed(record, hash)
  error_messages = invalid_params[record.class.name] ||= {}
  record.errors.full_messages.each do |error_message|
    error_messages[error_message] = hash unless error_messages.key?(error_message)
    count_error(error_message)
  end
end

#start_all(importer) ⇒ Object



21
22
23
# File 'lib/abstract_importer/reporters/debug_reporter.rb', line 21

def start_all(importer)
  super
end

#start_collection(collection) ⇒ Object



38
39
40
41
42
# File 'lib/abstract_importer/reporters/debug_reporter.rb', line 38

def start_collection(collection)
  super
  @notices = {}
  @errors  = {}
end

#stat(s) ⇒ Object Also known as: info



66
67
68
# File 'lib/abstract_importer/reporters/debug_reporter.rb', line 66

def stat(s)
  io.puts "  #{s}"
end

#status(s) ⇒ Object



62
63
64
# File 'lib/abstract_importer/reporters/debug_reporter.rb', line 62

def status(s)
  io.puts s
end