Class: Command::Runner::Backends::PosixSpawn
- 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
-
.available?(_ = false) ⇒ Boolean
Determines whether or not the PosixSpawn class is available as a backend.
Instance Method Summary collapse
-
#spawn(env, command, arguments, options) ⇒ Numeric
Spawns a process with the given line, environment, and options.
Methods inherited from Spawn
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.
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 false end end |
Instance Method Details
#spawn(env, command, arguments, options) ⇒ Numeric
Spawns a process with the given line, environment, and options.
29 30 31 32 33 34 35 36 37 |
# File 'lib/command/runner/backends/posix_spawn.rb', line 29 def spawn(env, command, arguments, ) if .delete(:unsafe) POSIX::Spawn.spawn(env, "#{command} #{arguments.join(' ')}", ) else POSIX::Spawn.spawn(env, command, *[arguments, ].flatten) end end |