Class: Wagn::Commands::RakeCommand

Inherits:
Command
  • Object
show all
Defined in:
lib/wagn/commands/rake_command.rb,
lib/wagn/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.



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

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

#commandObject



24
25
26
27
28
29
30
# File 'lib/wagn/commands/rake_command.rb', line 24

def command
  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



17
18
19
20
21
22
# File 'lib/wagn/commands/rake_command.rb', line 17

def run
  command.each do |cmd|
    puts cmd
    puts `#{cmd}`
  end
end