class Dumpdb::Runner
Attributes
cmd_runner[R]
script[R]
Public Class Methods
new(script, opts={})
click to toggle source
# File lib/dumpdb/runner.rb, line 9 def initialize(script, opts={}) @script = script @cmd_runner = opts[:cmd_runner] || scmd_cmd_runner end
Public Instance Methods
run()
click to toggle source
# File lib/dumpdb/runner.rb, line 14 def run run_callback 'before_run' run_callback 'before_setup' run_setup begin run_callback 'after_setup' [:dump, :copy_dump, :restore].each{ |phase_name| run_phase phase_name } ensure run_phase 'teardown' run_callback 'after_run' end end
Private Instance Methods
run_callback(meth, *args)
click to toggle source
# File lib/dumpdb/runner.rb, line 65 def run_callback(meth, *args) @script.send(meth.to_s, *args) end
run_cmd(cmd_str)
click to toggle source
# File lib/dumpdb/runner.rb, line 58 def run_cmd(cmd_str) cmd_obj = @cmd_runner.new(cmd_str) run_callback('before_cmd_run', cmd_obj) cmd_obj.run! run_callback('after_cmd_run', cmd_obj) end
run_copy_dump()
click to toggle source
# File lib/dumpdb/runner.rb, line 39 def run_copy_dump run_cmd @script.copy_dump_cmd end
run_dump()
click to toggle source
# File lib/dumpdb/runner.rb, line 35 def run_dump @script.dump_cmds.each{ |cmd| run_cmd(cmd) } end
run_phase(phase_name)
click to toggle source
# File lib/dumpdb/runner.rb, line 52 def run_phase(phase_name) run_callback "before_#{phase_name}" self.send("run_#{phase_name}") run_callback "after_#{phase_name}" end
run_restore()
click to toggle source
# File lib/dumpdb/runner.rb, line 43 def run_restore @script.restore_cmds.each{ |cmd| run_cmd(cmd) } end
run_setup()
click to toggle source
# File lib/dumpdb/runner.rb, line 30 def run_setup run_cmd(@script.dump_cmd{ "mkdir -p #{source.output_dir}" }) run_cmd(@script.restore_cmd{ "mkdir -p #{target.output_dir}" }) end
run_teardown()
click to toggle source
# File lib/dumpdb/runner.rb, line 47 def run_teardown run_cmd(@script.dump_cmd{ "rm -rf #{source.output_dir}" }) run_cmd(@script.restore_cmd{ "rm -rf #{target.output_dir}" }) end
scmd_cmd_runner()
click to toggle source
# File lib/dumpdb/runner.rb, line 69 def scmd_cmd_runner require 'scmd' Scmd end