Class: BuildEm::Executor

Inherits:
Object
  • Object
show all
Defined in:
lib/buildem/executor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args, kernel = Kernel, matcher = BuildEm::ConditionMatcher.new) ⇒ Executor

Returns a new instance of Executor.



8
9
10
11
12
# File 'lib/buildem/executor.rb', line 8

def initialize(args, kernel=Kernel, matcher=BuildEm::ConditionMatcher.new)
  @kernel = kernel
  @argz ||= args
  @matcher = matcher
end

Instance Attribute Details

#argzObject

Returns the value of attribute argz.



6
7
8
# File 'lib/buildem/executor.rb', line 6

def argz
  @argz
end

Instance Method Details

#nameObject



14
15
16
# File 'lib/buildem/executor.rb', line 14

def name
  BuildEm::Executor
end

#runObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/buildem/executor.rb', line 18

def run
  optz = argz[1]
  quit_on_error = (optz[:quit_on_error].nil?   ? true : optz[:quit_on_error])
  retry_amount  = (optz[:retry_amount].nil?    ? 1 : optz[:retry_amount])
  condition     = (optz[:retry_condition].nil? ? 0 : optz[:retry_condition])
  executions    = 0
  begin
    puts "retrying command [#{argz[0]}]" if executions > 0
    executions += 1
    @comamnd_output     = @kernel.run_command("#{argz[0]}")
    @command_exitstatus = @kernel.exitstatus
    match = @matcher.match(@command_exitstatus, @comamnd_output, condition)
    puts @comamnd_output if match
    return @command_exitstatus if match
  rescue Exception => e
    if quit_on_error
      raise e
    end
  end while executions < retry_amount
  fail "Failed to execute [#{argz[0]}]. Tried #{retry_amount} time(s), expected match was [#{condition}] got [#{@command_exitstatus}]." if quit_on_error
  @command_exitstatus
end