This class implements the base functionality for runners that process table specs.
Default options if not overriden in command line
Entry points for executing a processing run. args: the array of command line options that were provided by the user.
# File lib/rubyrep/base_runner.rb, line 182 def self.run(args) runner = new status = runner.process_options(args) if runner.options runner.execute end status end
Intended to be overwritten by derived classes that need to add additional options to the provided OptionParser object.
# File lib/rubyrep/base_runner.rb, line 135 def add_specific_options(opts) end
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.
# File lib/rubyrep/base_runner.rb, line 129 def create_processor(left_table, right_table) # not implemented in the base class end
Executes a run based on the established options.
# 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
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.
# File lib/rubyrep/base_runner.rb, line 142 def prepare_table_pairs(table_pairs) table_pairs end
Parses the given command line parameter array. Returns the status (as per UNIX conventions: 1 if parameters were invalid, 0 otherwise)
# File lib/rubyrep/base_runner.rb, line 57 def process_options(args) status = 0 self.options = DEFAULT_OPTIONS.clone parser = OptionParser.new do |opts| opts.banner = Usage: #{$0} #{self.class.name.sub(/^.*::(.*)Runner$/, '\\1').downcase} [options] [table_spec] [table_spec] ... #{summary_description} table_spec can be either: * a specific table name (e. g. 'users') or * a pair of (specific) table names (e. g.: 'users,users_backup') (In this case the first table in the 'left' database is compared with the second table in the 'right' database.) * a regular expression (e. g. '/^user/') [case insensitive match] If no table_specs are provided via command line, the ones from the configuration file are used. 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| options[:config_file] = arg end add_specific_options(opts) opts.on_tail("--help", "Show this message") do $stderr.puts opts self.options = nil end end begin unprocessed_args = parser.parse!(args) if options # this will be +nil+ if the --help option is specified options[:table_specs] = unprocessed_args raise("Please specify configuration file") unless options.include?(:config_file) end rescue Exception => e $stderr.puts "Command line parsing failed: #{e}" $stderr.puts parser.help self.options = nil status = 1 end return status end
Returns the active ScanProgressPrinter class (as selected through the command line options OR if none was selected, the default one).
# File lib/rubyrep/base_runner.rb, line 41 def progress_printer if selected_progress_printer selected_progress_printer else printer_key = session.configuration.options[:scan_progress_printer] ScanProgressPrinters.printers[printer_key][:printer_class] end end
Returns the active ScanReportPrinters instance (as selected through the command line options OR if none was selected, the default one).
# 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
Returns the active Session. Loads config file and creates session if necessary.
# File lib/rubyrep/base_runner.rb, line 148 def session unless @session load options[:config_file] @session = Session.new Initializer.configuration end @session end
Signals scan completion to the (active) scan report printer if it supports that method.
# 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
Generated with the Darkfish Rdoc Generator 2.