Module: Dumpman::Executor

Extended by:
Executor
Included in:
Executor
Defined in:
lib/dumpman/executor.rb

Instance Method Summary collapse

Instance Method Details

#info(cmd) ⇒ Object



27
28
29
30
31
32
33
34
# 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) ⇒ Object



20
21
22
23
24
25
# 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) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# 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