module Dumpman::Executor

Public Instance Methods

info(cmd) click to toggle source
# File lib/dumpman/executor.rb, line 27
def info(cmd)
  puts 'EXECUTING:'

  puts cmd.gsub(/(\s{2})/, '\1')
      .split(/\n/)
      .map { |x| x.squeeze(' ') }
      .reject(&:blank?)
end
rake(*commands) click to toggle source
# File lib/dumpman/executor.rb, line 20
def rake(*commands)
  commands.each do |command|
    Rake::Task["db:#{command}"].reenable
    Rake::Task["db:#{command}"].invoke
  end
end
system(*commands) { |result| ... } click to toggle source
# File lib/dumpman/executor.rb, line 5
def system(*commands)
  cmd = commands.join(' && ')
  info(cmd)

  # execute & capture the result
  if block_given?
    # if success yield the result message
    result = %x[#{cmd}].strip
    yield result if $?.success?
  else
    # return execution t/f
    result = Kernel.system(cmd)
  end
end