Class: Minipack::CommandRunner

Inherits:
Object
  • Object
show all
Defined in:
lib/minipack/command_runner.rb

Defined Under Namespace

Classes: UnsuccessfulError

Instance Method Summary collapse

Constructor Details

#initialize(env, command, chdir: '.', logger: nil, watcher: nil) ⇒ CommandRunner

Returns a new instance of CommandRunner.



10
11
12
13
14
15
16
# File 'lib/minipack/command_runner.rb', line 10

def initialize(env, command, chdir: '.', logger: nil, watcher: nil)
  @env = env
  @command = command
  @chdir = chdir
  @logger = logger || Logger.new(nil)
  @watcher = watcher
end

Instance Method Details

#runObject



18
19
20
21
22
# File 'lib/minipack/command_runner.rb', line 18

def run
  run!
rescue UnsuccessfulError
  false
end

#run!Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/minipack/command_runner.rb', line 24

def run!
  @logger.info "Start executing #{@command}, within #{@chdir}"

  return run_command if @watcher.nil?

  if @watcher.stale?
    run_command.tap do |success|
      @watcher.record_digest if success
    end
  else
    @logger.info 'Skipped because no file changes'
    true
  end
end