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

#get_binding, #include

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:



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

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.



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

def command
  @command
end

#use_bundlerObject (readonly)

Returns the value of attribute use_bundler.



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

def use_bundler
  @use_bundler
end

Instance Method Details

#run_task(verbose) ⇒ Object



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

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 and gemfile_exists?
  cmd << command

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