Class: Decko::Commands::RakeCommand

Inherits:
Command
  • Object
show all
Defined in:
lib/decko/commands/rake_command.rb,
lib/decko/commands/rake_command/parser.rb

Defined Under Namespace

Classes: Parser

Instance Method Summary collapse

Methods inherited from Command

#exit_with_child_status, #split_args

Constructor Details

#initialize(rake_task, args = {}) ⇒ RakeCommand

Returns a new instance of RakeCommand.



7
8
9
10
11
12
13
14
15
16
# File 'lib/decko/commands/rake_command.rb', line 7

def initialize rake_task, args={}
  @task = rake_task
  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



30
31
32
33
34
35
36
# File 'lib/decko/commands/rake_command.rb', line 30

def commands
  task_cmd = "bundle exec rake #{@task}"
  return [task_cmd] if !@envs || @envs.empty?
  @envs.map do |env|
    "env RAILS_ENV=#{env} #{task_cmd}"
  end
end

#runObject



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/decko/commands/rake_command.rb', line 18

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

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