Sha256: 248eddd9d55d275cff63a0b97312e3f351794981c8b907669be863cbb42a0069

Contents?: true

Size: 934 Bytes

Versions: 2

Compression:

Stored size: 934 Bytes

Contents

# coding: UTF-8

module Terrapin
  class CommandLine
    class PosixRunner
      def self.available?
        return @available unless @available.nil?

        @available = posix_spawn_gem_available?
      end

      def self.supported?
        available? && !OS.java?
      end

      def supported?
        self.class.supported?
      end

      def call(command, env = {}, options = {})
        pipe = MultiPipe.new
        pid = spawn(env, command, options.merge(pipe.pipe_options))
        pipe.read_and_then do
          waitpid(pid)
        end
        pipe.output
      end

      private

      def spawn(*args)
        POSIX::Spawn.spawn(*args)
      end

      def waitpid(pid)
        Process.waitpid(pid)
      end

      def self.posix_spawn_gem_available?
        require 'posix/spawn'
        true
      rescue LoadError
        false
      end

      private_class_method :posix_spawn_gem_available?
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
terrapin-0.6.0 lib/terrapin/command_line/runners/posix_runner.rb
terrapin-0.6.0.alpha lib/terrapin/command_line/runners/posix_runner.rb