Class: RR::ScanReportPrinters::ScanDetailReporter
- Inherits:
-
ScanSummaryReporter
- Object
- ScanSummaryReporter
- RR::ScanReportPrinters::ScanDetailReporter
- Defined in:
- lib/rubyrep/scan_report_printers/scan_detail_reporter.rb
Overview
A ScanReportPrinter producing a summary (number of differences) only.
Instance Attribute Summary collapse
-
#primary_key_names ⇒ Object
Array of names of the primary key columns of the table currently being scanned.
-
#report_mode ⇒ Object
Mode of reporting.
-
#session ⇒ Object
The current Session object.
-
#tmpfile ⇒ Object
The temporary File receiving the differences.
Attributes inherited from ScanSummaryReporter
#left_table, #only_totals, #right_table, #scan_result
Instance Method Summary collapse
-
#clear_columns(row) ⇒ Object
Returns a cleaned row as per current
report_mode
. -
#initialize(session, arg) ⇒ ScanDetailReporter
constructor
A scan run is to be started using this scan result printer.
-
#report_difference(type, row) ⇒ Object
Each difference is handed to the printer as described in the format as described e.
-
#scan(left_table, right_table) ⇒ Object
A scan of the given ‘left’ table and corresponding ‘right’ table is executed.
-
#scanning_finished ⇒ Object
Optional method.
Constructor Details
#initialize(session, arg) ⇒ ScanDetailReporter
A scan run is to be started using this scan result printer. arg
is the command line argument as yielded by OptionParser#on.
39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/rubyrep/scan_report_printers/scan_detail_reporter.rb', line 39 def initialize(session, arg) super session, "" self.session = session self.report_mode = case arg when 'diff' :diff when 'keys' :keys else :full end end |
Instance Attribute Details
#primary_key_names ⇒ Object
Array of names of the primary key columns of the table currently being scanned.
35 36 37 |
# File 'lib/rubyrep/scan_report_printers/scan_detail_reporter.rb', line 35 def primary_key_names @primary_key_names end |
#report_mode ⇒ Object
Mode of reporting. Should be either
-
:
full
-
:
keys
or -
:
diff
31 32 33 |
# File 'lib/rubyrep/scan_report_printers/scan_detail_reporter.rb', line 31 def report_mode @report_mode end |
#session ⇒ Object
The current Session object
22 23 24 |
# File 'lib/rubyrep/scan_report_printers/scan_detail_reporter.rb', line 22 def session @session end |
#tmpfile ⇒ Object
The temporary File receiving the differences
25 26 27 |
# File 'lib/rubyrep/scan_report_printers/scan_detail_reporter.rb', line 25 def tmpfile @tmpfile end |
Instance Method Details
#clear_columns(row) ⇒ Object
Returns a cleaned row as per current report_mode
. row
is either a column_name => value hash or an array of 2 such rows.
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/rubyrep/scan_report_printers/scan_detail_reporter.rb', line 72 def clear_columns(row) case report_mode when :full row when :keys row = row[0] if row.kind_of?(Array) self.primary_key_names ||= session.left.primary_key_names(self.left_table) row.reject {|column, value| !self.primary_key_names.include?(column)} when :diff self.primary_key_names ||= session.left.primary_key_names(self.left_table) if row.kind_of?(Array) new_row_array = [{}, {}] row[0].each do |column, value| if self.primary_key_names.include?(column) or value != row[1][column] new_row_array[0][column] = row[0][column] new_row_array[1][column] = row[1][column] end end new_row_array else row end end end |
#report_difference(type, row) ⇒ Object
Each difference is handed to the printer as described in the format as described e. g. in DirectTableScan#run
99 100 101 102 103 |
# File 'lib/rubyrep/scan_report_printers/scan_detail_reporter.rb', line 99 def report_difference(type, row) self.tmpfile ||= Tempfile.new 'rubyrep_scan_details' tmpfile.puts({type => clear_columns(row)}.to_yaml) super type, row end |
#scan(left_table, right_table) ⇒ Object
A scan of the given ‘left’ table and corresponding ‘right’ table is executed. Needs to yield so that the actual scan can be executed.
55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/rubyrep/scan_report_printers/scan_detail_reporter.rb', line 55 def scan(left_table, right_table) super left_table, right_table ensure self.primary_key_names = nil if self.tmpfile self.tmpfile.close self.tmpfile.open self.tmpfile.each_line {|line| puts line} self.tmpfile.close! self.tmpfile = nil end end |
#scanning_finished ⇒ Object
Optional method. If a scan report printer has it, it is called after the last table scan is executed. (A good place to print a final summary.)
108 109 |
# File 'lib/rubyrep/scan_report_printers/scan_detail_reporter.rb', line 108 def scanning_finished end |