class Swat::CommandExecution
Represents the whole execution pipeline of a command
Returns a hashmap that contains the following keys
execution_mode: self descriptive prepare, precheck, execute: the different stages of execution each stage will include a hash with: succesful: boolean, indicating if it was successful or not output: the stdout in case the stage was successfull, stderr otherwise
Public Class Methods
new(command, execution_mode = "dryrun")
click to toggle source
# File lib/swat.rb, line 41 def initialize(command, execution_mode = "dryrun") @command = command @stages = stages(execution_mode) @result = { execution_mode: execution_mode } @context = {} end
Public Instance Methods
execute_stage(stage)
click to toggle source
# File lib/swat.rb, line 56 def execute_stage(stage) @result[stage] = { successful: true, output: @command.public_send(stage, @context) } rescue => e @result[stage] = { successful: false, output: e.to_s } end
run()
click to toggle source
# File lib/swat.rb, line 48 def run @stages.each do |stage| execute_stage(stage) break unless @result[stage][:successful] end @result end
stages(execution_mode)
click to toggle source
# File lib/swat.rb, line 62 def stages(execution_mode) case execution_mode when "dryrun" %i(prepare pre_check) when "execute" %i(prepare pre_check execute) else fail "Invalid execution mode '#{execution_mode}'" end end