Class: Cardio::Command::RakeCommand

Inherits:
CommandBase show all
Defined in:
lib/cardio/command/rake_command.rb

Overview

enhance standard rake command with some decko/card -specific options

Instance Method Summary collapse

Methods inherited from CommandBase

#exit_with_child_status, #split_args

Constructor Details

#initialize(gem, command, args = {}) ⇒ RakeCommand

Returns a new instance of RakeCommand.



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/cardio/command/rake_command.rb', line 7

def initialize gem, command, args={}
  @command = command
  @task = "#{gem}:#{command}"
  @args = [args].flatten
  # opts = {}
  # if args.is_a? Array
  #   Parser.new(rake_task, opts).parse!(args)
  # else
  #   opts = args
  # end
  # # @envs = Array(opts[:envs])
end

Instance Method Details

#commandsObject



32
33
34
35
36
37
38
39
40
# File 'lib/cardio/command/rake_command.rb', line 32

def commands
  task_cmd = "bundle exec rake #{@task}"
  task_cmd += " -- #{@args.join ' '}" unless @args.empty?
  return [task_cmd] if !@envs || @envs.empty?

  # @envs.map do |env|
  #   "env RAILS_ENV=#{env} #{task_cmd}"
  # end
end

#runObject



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/cardio/command/rake_command.rb', line 20

def run
  commands.each do |cmd|
    # puts cmd
    # exit_with_child_status cmd

    result = `#{cmd}`
    process = $CHILD_STATUS
    puts result
    exit process.exitstatus unless process.success?
  end
end