Sha256: 11583c027fb203ce4402bf77bfec329572142518d7cb6e1154521cecfec71b48

Contents?: true

Size: 1.51 KB

Versions: 1

Compression:

Stored size: 1.51 KB

Contents

require 'aruba/processes/spawn_process'

module Aruba
  module Processes
    # Debug Process
    class DebugProcess < BasicProcess
      # Use only if mode is :debug
      def self.match?(mode)
        mode == :debug || (mode.is_a?(Class) && mode <= DebugProcess)
      end

      # rubocop:disable Metrics/MethodLength
      # rubocop:disable Metrics/CyclomaticComplexity
      def run!
        # rubocop:disable  Metrics/LineLength
        fail LaunchError, %(Command "#{command}" not found in PATH-variable "#{environment['PATH']}".) unless which(command)
        # rubocop:enable  Metrics/LineLength

        if RUBY_VERSION < '1.9'
          begin
            old_env = ENV.to_hash.dup
            ENV.update environment

            Dir.chdir @working_directory do
              @exit_status = system(@cmd) ? 0 : 1
            end
          ensure
            ENV.clear
            ENV.update old_env
          end
        elsif RUBY_VERSION < '2'
          Dir.chdir @working_directory do
            @exit_status = system(environment, @cmd) ? 0 : 1
          end
        else
          @exit_status = system(environment, @cmd, :chdir => @working_directory) ? 0 : 1
        end
      end
      # rubocop:enable Metrics/CyclomaticComplexity
      # rubocop:enable Metrics/MethodLength

      def stdin(*); end

      def stdout(*)
        ''
      end

      def stderr(*)
        ''
      end

      def stop(_reader)
        @stopped = true

        @exit_status
      end

      def terminate(*)
        stop
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
aruba-0.9.0.pre lib/aruba/processes/debug_process.rb