Class: RR::BaseRunner
- Inherits:
-
Object
- Object
- RR::BaseRunner
- Defined in:
- lib/rubyrep/base_runner.rb
Overview
This class implements the base functionality for runners that process table specs.
Direct Known Subclasses
Constant Summary collapse
- DEFAULT_OPTIONS =
Default options if not overriden in command line
{ :table_specs => [] }
Instance Attribute Summary collapse
-
#options ⇒ Object
Provided options.
-
#report_printer_arg ⇒ Object
The specified option parameter for the report printer.
-
#report_printer_class ⇒ Object
The class for the selected report printer.
-
#selected_progress_printer ⇒ Object
Returns the command line selected ScanProgressPrinters class.
-
#session ⇒ Object
Returns the active
Session
.
Class Method Summary collapse
-
.run(args) ⇒ Object
Entry points for executing a processing run.
Instance Method Summary collapse
-
#add_specific_options(opts) ⇒ Object
Intended to be overwritten by derived classes that need to add additional options to the provided
OptionParser
object. -
#create_processor(left_table, right_table) ⇒ Object
Creates a processor that does something with the given table.
-
#execute ⇒ Object
Executes a run based on the established options.
-
#prepare_table_pairs(table_pairs) ⇒ Object
Intended to be overwritten by derived classes that need to modify the table_pairs.
-
#process_options(args) ⇒ Object
Parses the given command line parameter array.
-
#progress_printer ⇒ Object
Returns the active ScanProgressPrinter class (as selected through the command line options OR if none was selected, the default one).
-
#report_printer ⇒ Object
Returns the active ScanReportPrinters instance (as selected through the command line options OR if none was selected, the default one).
-
#signal_scanning_completion ⇒ Object
Signals scan completion to the (active) scan report printer if it supports that method.
-
#summary_description ⇒ Object
Returns the default command summary description (nothing).
-
#table_pairs ⇒ Object
Returns the table pairs that should be processed.
Instance Attribute Details
#options ⇒ Object
Provided options. Possible values:
-
:config_file
: path to config file -
:table_specs
: array of table specification strings
18 19 20 |
# File 'lib/rubyrep/base_runner.rb', line 18 def end |
#report_printer_arg ⇒ Object
The specified option parameter for the report printer
24 25 26 |
# File 'lib/rubyrep/base_runner.rb', line 24 def report_printer_arg @report_printer_arg end |
#report_printer_class ⇒ Object
The class for the selected report printer
21 22 23 |
# File 'lib/rubyrep/base_runner.rb', line 21 def report_printer_class @report_printer_class end |
#selected_progress_printer ⇒ Object
Returns the command line selected ScanProgressPrinters class
37 38 39 |
# File 'lib/rubyrep/base_runner.rb', line 37 def selected_progress_printer @selected_progress_printer end |
#session ⇒ Object
Returns the active Session
. Loads config file and creates session if necessary.
148 149 150 151 152 153 154 |
# File 'lib/rubyrep/base_runner.rb', line 148 def session unless @session load [:config_file] @session = Session.new Initializer.configuration end @session end |
Class Method Details
.run(args) ⇒ Object
Entry points for executing a processing run. args: the array of command line options that were provided by the user.
182 183 184 185 186 187 188 189 190 |
# File 'lib/rubyrep/base_runner.rb', line 182 def self.run(args) runner = new status = runner.(args) if runner. runner.execute end status end |
Instance Method Details
#add_specific_options(opts) ⇒ Object
Intended to be overwritten by derived classes that need to add additional options to the provided OptionParser
object.
135 136 |
# File 'lib/rubyrep/base_runner.rb', line 135 def (opts) end |
#create_processor(left_table, right_table) ⇒ Object
Creates a processor that does something with the given table. A processor needs to implement a run
method that yields for progress reporting purposes pairs of diff_type and row as defined under DirectTableScan#run.
129 130 131 |
# File 'lib/rubyrep/base_runner.rb', line 129 def create_processor(left_table, right_table) # not implemented in the base class end |
#execute ⇒ Object
Executes a run based on the established options.
165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/rubyrep/base_runner.rb', line 165 def execute session.configuration.exclude_rubyrep_tables table_pairs.each do |table_pair| report_printer.scan table_pair[:left], table_pair[:right] do processor = create_processor \ table_pair[:left], table_pair[:right] processor.progress_printer = progress_printer processor.run do |diff_type, row| report_printer.report_difference diff_type, row end end end signal_scanning_completion end |
#prepare_table_pairs(table_pairs) ⇒ Object
Intended to be overwritten by derived classes that need to modify the table_pairs.
-
table_pairs: array of table pairs as returned by TableSpecResolver#resolve
Returns the new table pairs array.
142 143 144 |
# File 'lib/rubyrep/base_runner.rb', line 142 def prepare_table_pairs(table_pairs) table_pairs end |
#process_options(args) ⇒ Object
Parses the given command line parameter array. Returns the status (as per UNIX conventions: 1 if parameters were invalid, 0 otherwise)
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/rubyrep/base_runner.rb', line 57 def (args) status = 0 self. = DEFAULT_OPTIONS.clone parser = OptionParser.new do |opts| opts. = "Usage: \#{$0} \#{self.class.name.sub(/^.*::(.*)Runner$/, '\\\\1').downcase} [options] [table_spec] [table_spec] ...\n\n \#{summary_description}\n\n table_spec can be either:\n* a specific table name (e. g. 'users') or\n* a pair of (specific) table names (e. g.: 'users,users_backup')\n (In this case the first table in the 'left' database is compared\n with the second table in the 'right' database.)\n* a regular expression (e. g. '/^user/') [case insensitive match]\n If no table_specs are provided via command line, the ones from the\n configuration file are used.\n" opts.separator "" opts.separator " Specific options:" ScanReportPrinters.on_printer_selection(opts) do |printer_class, arg| self.report_printer_class = printer_class self.report_printer_arg = arg end ScanProgressPrinters.on_printer_selection(opts) do |printer| self.selected_progress_printer = printer end opts.on("-c", "--config", "=CONFIG_FILE", "Mandatory. Path to configuration file.") do |arg| [:config_file] = arg end (opts) opts.on_tail("--help", "Show this message") do $stderr.puts opts self. = nil end end begin unprocessed_args = parser.parse!(args) if # this will be +nil+ if the --help option is specified [:table_specs] = unprocessed_args raise("Please specify configuration file") unless .include?(:config_file) end rescue Exception => e $stderr.puts "Command line parsing failed: #{e}" $stderr.puts parser.help self. = nil status = 1 end return status end |
#progress_printer ⇒ Object
Returns the active ScanProgressPrinter class (as selected through the command line options OR if none was selected, the default one).
41 42 43 44 45 46 47 48 |
# File 'lib/rubyrep/base_runner.rb', line 41 def progress_printer if selected_progress_printer selected_progress_printer else printer_key = session.configuration.[:scan_progress_printer] ScanProgressPrinters.printers[printer_key][:printer_class] end end |
#report_printer ⇒ Object
Returns the active ScanReportPrinters instance (as selected through the command line options OR if none was selected, the default one).
28 29 30 31 32 33 34 |
# File 'lib/rubyrep/base_runner.rb', line 28 def report_printer unless @report_printer printer_class = report_printer_class || ScanReportPrinters::ScanSummaryReporter @report_printer ||= printer_class.new(session, report_printer_arg) end @report_printer end |
#signal_scanning_completion ⇒ Object
Signals scan completion to the (active) scan report printer if it supports that method.
119 120 121 122 123 |
# File 'lib/rubyrep/base_runner.rb', line 119 def signal_scanning_completion if report_printer.respond_to? :scanning_finished report_printer.scanning_finished end end |
#summary_description ⇒ Object
Returns the default command summary description (nothing). Should be overwritten by child classes.
52 |
# File 'lib/rubyrep/base_runner.rb', line 52 def summary_description; ""; end |
#table_pairs ⇒ Object
Returns the table pairs that should be processed. Refer to TableSpecRsolver#resolve for format of return value.
160 161 162 |
# File 'lib/rubyrep/base_runner.rb', line 160 def table_pairs prepare_table_pairs(session.configured_table_pairs([:table_specs])) end |