Class: FeduxOrgStdlib::Rake::ShellTask

Inherits:
Task
  • Object
show all
Defined in:
lib/fedux_org_stdlib/rake/shell_task.rb

Overview

Shell Task

See Also:

  • Rakefile

Instance Attribute Summary collapse

Attributes inherited from Task

#description, #name, #verbose, #verbose (true)

Instance Method Summary collapse

Methods inherited from Task

#include, #instance_binding

Constructor Details

#initialize(command:, use_bundler: false, **args) ⇒ ShellTask

Create a new shell task

Parameters:

  • command (String)

    The command to be executed

  • use_bundler (true, false) (defaults to: false)

    Should the command be prefixed with ‘bundle exec`

See Also:



31
32
33
34
35
36
37
38
39
40
# File 'lib/fedux_org_stdlib/rake/shell_task.rb', line 31

def initialize(
  command:,
  use_bundler: false,
  **args
)
  super(**args)

  @use_bundler = use_bundler
  @command     = command
end

Instance Attribute Details

#commandObject (readonly)

Returns the value of attribute command.



15
16
17
# File 'lib/fedux_org_stdlib/rake/shell_task.rb', line 15

def command
  @command
end

#use_bundlerObject (readonly)

Returns the value of attribute use_bundler.



19
20
21
# File 'lib/fedux_org_stdlib/rake/shell_task.rb', line 19

def use_bundler
  @use_bundler
end

Instance Method Details

#run_task(_verbose) ⇒ Object



43
44
45
46
47
48
49
50
51
# File 'lib/fedux_org_stdlib/rake/shell_task.rb', line 43

def run_task(_verbose)
  logger.warn 'Gemfile does not exist. Running bundler will fail. I am going to run the command without `bundle exec`.' unless gemfile_exists?

  cmd = []
  cmd << 'bundle exec' if use_bundler && gemfile_exists?
  cmd << command

  sh Erubis::Eruby.new(cmd.join(' ')).result(instance_binding)
end