Method: Rubysh::Subprocess#initialize

Defined in:
lib/rubysh/subprocess.rb

#initialize(args, blk = nil, directives = [], post_fork = [], runner = nil) ⇒ Subprocess

TODO: switch directives over to an OrderedHash of some form? Really want to preserve the semantics here.

Raises:

  • (ArgumentError)


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/rubysh/subprocess.rb', line 17

def initialize(args, blk=nil, directives=[], post_fork=[], runner=nil)
  raise ArgumentError.new("Must provide an array (#{args.inspect} provided)") unless args.kind_of?(Array)

  if args.length > 0 && blk
    raise ArgumentError.new("Provided both arguments (#{args.inspect}) and a block (#{blk.inspect}). You can only provide one.")
  elsif args.length == 0 && !blk
    raise ArgumentError.new("No command specified (#{args.inspect} provided)")
  end

  @command = args[0]
  @args = args[1..-1]
  @blk = blk
  @directives = directives
  @runner = runner

  Rubysh.assert(@directives.length == 0 || @runner, "Directives provided but no runner is", true)

  @exec_status = nil
  @post_fork = post_fork

  @pid = nil
  @status = nil
  @exec_error = nil

  Rubysh.log.debug("Just created: #{self}")
end