Sha256: 8e658213db54920175006b8bfad2b9eb36b34447af3394ae4ae9a3be1d4016ad

Contents?: true

Size: 751 Bytes

Versions: 1

Compression:

Stored size: 751 Bytes

Contents

module Caco
  class Executer < Trailblazer::Operation
    step :execute!

    def execute!(ctx, command:, **)
      s, e, o, error = self.class.send(:execute, command)
      ctx[:signal] = [s, e, o, error]
      ctx[:exit_code] = e
      ctx[:output] = o
      ctx[:stderr] = error

      return s
    end

    module ClassMethods
      private
      def execute(command)
        stdout = nil
        stderr = nil
        pid = nil
        exit_status = nil
        Open3.popen3(*command) do |i, o, e, t|
          pid = t.pid
          stdout = o.read
          stderr = e.read
          exit_status = t.value
        end
        return exit_status.success?, exit_status.exitstatus, stdout, stderr
      end
    end
    extend ClassMethods
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
caco-0.1.0 lib/caco/executer.rb