Class: RR::GenerateRunner
- Inherits:
-
Object
- Object
- RR::GenerateRunner
- Defined in:
- lib/rubyrep/generate_runner.rb
Overview
This class implements the functionality of the ‘generate’ command.
Constant Summary collapse
- CONFIG_TEMPLATE =
<<EOF RR::Initializer::run do |config| config.left = { :adapter => 'postgresql', # or 'mysql' :database => 'SCOTT', :username => 'scott', :password => 'tiger', :host => '172.16.1.1' } config.right = { :adapter => 'postgresql', :database => 'SCOTT', :username => 'scott', :password => 'tiger', :host => '172.16.1.2' } config.include_tables 'dept' config.include_tables /^e/ # regexp matching all tables starting with e # config.include_tables /./ # regexp matching all tables in the database end EOF
Instance Attribute Summary collapse
-
#options ⇒ Object
Provided options.
Class Method Summary collapse
-
.run(args) ⇒ Object
Entry points for executing a processing run.
Instance Method Summary collapse
-
#execute ⇒ Object
Generates a configuration file template.
-
#process_options(args) ⇒ Object
Parses the given command line parameter array.
Instance Attribute Details
#options ⇒ Object
Provided options. Possible values:
-
:config_file
: path to config file
40 41 42 |
# File 'lib/rubyrep/generate_runner.rb', line 40 def @options 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.
92 93 94 95 96 97 98 99 100 |
# File 'lib/rubyrep/generate_runner.rb', line 92 def self.run(args) runner = new status = runner.(args) if runner. runner.execute end status end |
Instance Method Details
#execute ⇒ Object
Generates a configuration file template.
81 82 83 84 85 86 87 88 |
# File 'lib/rubyrep/generate_runner.rb', line 81 def execute if File.exists?([:file_name]) raise("Cowardly refuse to overwrite existing file '#{[:file_name]}'") end File.open([:file_name], 'w') do |f| f.write CONFIG_TEMPLATE end 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)
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/rubyrep/generate_runner.rb', line 45 def (args) status = 0 self. = {} parser = OptionParser.new do |opts| opts. = <<EOS Usage: #{$0} generate [file_name] Generates a configuration file template under name [file_name]. EOS opts.separator "" opts.separator " Specific options:" 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 raise("Please specify the name of the configuration file") if unprocessed_args.empty? [:file_name] = unprocessed_args[0] end rescue Exception => e $stderr.puts "Command line parsing failed: #{e}" $stderr.puts parser.help self. = nil status = 1 end return status end |