Sha256: f3e26474e275cb0af7359ed9f992305bafdc859a93d288144e31e5adc980ab45
Contents?: true
Size: 1.96 KB
Versions: 2
Compression:
Stored size: 1.96 KB
Contents
require 'shellwords' require 'stringio' require 'aruba/processes/basic_process' module Aruba module Processes class InProcess < BasicProcess attr_reader :exit_status class FakeKernel attr_reader :exitstatus def initialize @exitstatus = 0 end def exit(exitstatus) @exitstatus = exitstatus end end class << self attr_accessor :main_class end def initialize(cmd, exit_timeout, io_wait, working_directory, environment = ENV.to_hash) @cmd = cmd @argv = arguments @stdin = StringIO.new @stdout = StringIO.new @stderr = StringIO.new @kernel = FakeKernel.new super end def run! raise "You need to call Aruba::InProcess.main_class = YourMainClass" unless self.class.main_class Dir.chdir @working_directory do before_run with_environment do self.class.main_class.new(@argv, @stdin, @stdout, @stderr, @kernel).execute! end after_run yield self if block_given? end end def stop(reader) @stopped = true @exit_status = @kernel.exitstatus end def stdin @stdin.string end def stdout @stdout.string end def stderr @stderr.string end def write(input) @stdin.write input end def close_io(name) fail ArgumentError, 'Only stdin stdout and stderr are allowed to close' unless [:stdin, :stdout, :stderr].include? name get_instance_variable(name.to_sym).close end def terminate stop end private def with_environment(&block) old_env = ENV.to_hash ENV.update(environment) block.call ensure ENV.clear ENV.update old_env end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
aruba-0.8.0.pre2 | lib/aruba/processes/in_process.rb |
aruba-0.8.0.pre | lib/aruba/processes/in_process.rb |