class ProcessExecuter::Options::SpawnOptions


@api public
Valid options are those accepted by Process.spawn.
Allow subclasses to add additional options that are not passed to ‘Process.spawn`
Validate Process.spawn options and return Process.spawn options

def define_options

Other tags:
    Api: - private

Returns:
  • (Hash) -

Other tags:
    Example: Adding new options in a subclass -
def define_options
  [*super, *SPAWN_OPTIONS].freeze
end

def include_spawn_option?(option_key, value)

Other tags:
    Api: - private

Returns:
  • (Boolean) - true if the given option should be passed to `Process.spawn`

Parameters:
  • value (Object) -- the value of the option
  • option_key (Symbol, Integer, IO) -- the option to be tested
def include_spawn_option?(option_key, value)
  return false if value == :not_set
  redirection?(option_key) || SPAWN_OPTIONS.any? { |o| o.name == option_key }
end

def redirection?(option_key)

Other tags:
    Api: - private

Returns:
  • (Boolean) -

Parameters:
  • option_key (Symbol, Integer, IO, Array) -- the option key to be tested
def redirection?(option_key)
  test = ->(key) { %i[in out err].include?(key) || key.is_a?(Integer) || (key.is_a?(IO) && !key.fileno.nil?) }
  test.call(option_key) || (option_key.is_a?(Array) && option_key.all? { |key| test.call(key) })
end

def spawn_options

Returns:
  • (Hash) -
def spawn_options
  {}.tap do |spawn_options|
    options.each do |option_key, value|
      spawn_options[option_key] = value if include_spawn_option?(option_key, value)
    end
  end
end

def std_redirection?(option_key, symbol, fileno)

Other tags:
    Api: - private

Returns:
  • (Boolean) -

Parameters:
  • fileno (Integer) -- the file descriptor number to test for
  • symbol (:in, :out, :err) -- the symbol to test for
  • option_key (Symbol, Integer, IO, Array) -- the option key to be tested
def std_redirection?(option_key, symbol, fileno)
  test = ->(key) { key == symbol || key == fileno || (key.is_a?(IO) && key.fileno == fileno) }
  test.call(option_key) || (option_key.is_a?(Array) && option_key.any? { |key| test.call(key) })
end

def stderr_redirection?(option_key) = std_redirection?(option_key, :err, 2)

Other tags:
    Api: - private

Returns:
  • (Boolean) -

Parameters:
  • option_key (Symbol, Integer, IO, Array) -- the option key to be tested
def stderr_redirection?(option_key) = std_redirection?(option_key, :err, 2)

def stderr_redirection_key

Other tags:
    Api: - private

Returns:
  • (Symbol, Integer, IO, Array, nil) - nil if not found
def stderr_redirection_key
  options.keys.find { |option_key| option_key if stderr_redirection?(option_key) }
end

def stderr_redirection_value

Other tags:
    Api: - private

Returns:
  • (Object) -
def stderr_redirection_value
  options[stderr_redirection_key]
end

def stdout_redirection?(option_key) = std_redirection?(option_key, :out, 1)

Other tags:
    Api: - private

Returns:
  • (Boolean) -

Parameters:
  • option_key (Symbol, Integer, IO, Array) -- the option key to be tested
def stdout_redirection?(option_key) = std_redirection?(option_key, :out, 1)

def stdout_redirection_key

Other tags:
    Api: - private

Returns:
  • (Symbol, Integer, IO, Array, nil) - nil if not found
def stdout_redirection_key
  options.keys.find { |option_key| option_key if stdout_redirection?(option_key) }
end

def stdout_redirection_value

Other tags:
    Api: - private

Returns:
  • (Object) -
def stdout_redirection_value
  options[stdout_redirection_key]
end

def valid_option?(option_key)

Other tags:
    Api: - private

Returns:
  • (Boolean) - true if the given option is a valid option

Parameters:
  • option_key (Symbol) -- the option to be tested
def valid_option?(option_key)
  super || redirection?(option_key)
end