Class: Expectr::Adopt

Inherits:
Child
  • Object
show all
Defined in:
lib/expectr/adopt.rb,
lib/expectr/errstr.rb

Overview

Internal: The Expectr::Adopt Class contains the interface to interacting with child processes not spawned by Expectr.

All methods with the prefix ‘interface_’ in their name will return a Proc designed to be defined as an instance method in the primary Expectr object. These methods will all be documented as if they are the Proc in question.

Defined Under Namespace

Modules: Errstr

Instance Attribute Summary

Attributes inherited from Child

#pid, #stdin, #stdout

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Child

#interface_interact_thread, #interface_kill!, #interface_output_loop, #interface_prepare_interact_environment, #interface_send, #interface_winsize

Methods included from Interface

#init_instance, #interface_interact_thread, #interface_prepare_interact_interface, #interface_restore_environment

Constructor Details

#initialize(stdin, stdout) ⇒ Adopt

Public: Initialize a new Expectr::Adopt object. IO Objects are named in such a way as to maintain interoperability with the methods from the Expectr::Child class.

stdin - IO object open for writing. stdout - IO object open for reading. pid - FixNum corresponding to the PID of the process being adopted

(default: 1)

Raises TypeError if arguments are of type other than IO.



23
24
25
26
27
28
29
30
# File 'lib/expectr/adopt.rb', line 23

def initialize(stdin, stdout)
  unless stdin.kind_of?(IO) && stdout.kind_of?(IO)
    raise(TypeError, Errstr::IO_EXPECTED)
  end
  @stdin = stdin
  @stdout = stdout
  @stdout.winsize = $stdout.winsize if $stdout.tty?
end

Class Method Details

.spawn(stdout, stdin, pid = 1, args = {}) ⇒ Object

Public: Present a streamlined interface to create a new Expectr instance.

stdout - IO object open for reading. stdin - IO object open for writing. pid - FixNum corresponding to the PID of the process being adopted

(default: 1)

args - A Hash used to specify options for the new object, per

Expectr#initialize.

Returns a new Expectr object



42
43
44
45
46
47
48
# File 'lib/expectr/adopt.rb', line 42

def self.spawn(stdout, stdin, pid = 1, args = {})
  args[:interface] = :adopt
  args[:stdin] = stdin
  args[:stdout] = stdout
  args[:pid] = pid
  Expectr.new('', args)
end