Class: Command::Runner::Backends::PosixSpawn

Inherits:
Spawn
  • Object
show all
Defined in:
lib/command/runner/backends/posix_spawn.rb

Overview

Spawns a process using POSIX::Spawn. This is the preferred method, as POSIX::Spawn is much faster than Process.spawn.

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Spawn

#call, #initialize, #wait2

Methods inherited from Fake

#call, #initialize, #ran?, unsafe?, #unsafe?, unsafe_execution?

Constructor Details

This class inherits a constructor from Command::Runner::Backends::Spawn

Class Method Details

.available?(_ = false) ⇒ Boolean

Determines whether or not the PosixSpawn class is available as a backend. Does this by checking to see if posix-spawn has been installed on the local computer; if it hasn't, it returns false.

Returns:

  • (Boolean)

See Also:



16
17
18
19
20
21
22
23
# File 'lib/command/runner/backends/posix_spawn.rb', line 16

def self.available?(_ = false)
  @_available ||= begin
    require 'posix/spawn'
    super
  rescue LoadError => e
    false
  end
end

Instance Method Details

#spawn(env, command, arguments, options) ⇒ Numeric

Spawns a process with the given line, environment, and options.

Returns:

  • (Numeric)

See Also:



29
30
31
32
33
34
35
36
37
# File 'lib/command/runner/backends/posix_spawn.rb', line 29

def spawn(env, command, arguments, options)
  if options.delete(:unsafe)
    POSIX::Spawn.spawn(env,
    "#{command} #{arguments.join(' ')}", options)
  else
    POSIX::Spawn.spawn(env, command,
      *[arguments, options].flatten)
  end
end