class ProcessExecuter::Options
@api public
* ‘:timeout_after`: the number of seconds to allow a process to run before killing it
Valid options are those accepted by Process.spawn plus the following additions:
Validate ProcessExecuter::Executer#spawn options and return Process.spawn options
def assert_no_unknown_options(options)
- Api: - private
Raises:
-
(ArgumentError)
- if the options hash contains any unknown options
Returns:
-
(void)
-
Parameters:
-
options
(Hash
) -- the hash of options
def assert_no_unknown_options(options) unknown_options = options.keys.reject { |key| valid_option?(key) } raise ArgumentError, "Unknown options: #{unknown_options.join(', ')}" unless unknown_options.empty? end
def assert_timeout_is_valid
- Api: - private
Raises:
-
(ArgumentError)
- if timeout_after is not a non-negative real number
Returns:
-
(void)
-
def assert_timeout_is_valid return if @options[:timeout_after].nil? return if @options[:timeout_after].is_a?(Numeric) && @options[:timeout_after].real? && !@options[:timeout_after].negative? raise ArgumentError, invalid_timeout_after_message end
def include_spawn_option?(option, value)
- Api: - private
Returns:
-
(Boolean)
- true if the given option should be passed to `Process.spawn`
Parameters:
-
value
(Object
) -- the value of the option -
option
(Symbol, Integer, IO
) -- the option to be tested
def include_spawn_option?(option, value) (option.is_a?(Integer) || option.is_a?(IO) || SPAWN_OPTIONS.include?(option)) && value != NOT_SET end
def initialize(**options)
(**options)
-
:timeout_after
(Integer, Float, nil
) --
Parameters:
-
options
(Hash
) -- Process.spawn options plus additional options listed below.
def initialize(**options) assert_no_unknown_options(options) @options = DEFAULTS.merge(options) assert_timeout_is_valid end
def invalid_timeout_after_message
- Api: - private
Returns:
-
(String)
-
def invalid_timeout_after_message "timeout_after must be nil or a non-negative real number but was #{options[:timeout_after].pretty_inspect}" end
def spawn_options
-
(Hash)
-
def spawn_options {}.tap do |spawn_options| options.each do |option, value| spawn_options[option] = value if include_spawn_option?(option, value) end end end
def valid_option?(option)
- Api: - private
Returns:
-
(Boolean)
- true if the given option is a valid option
Parameters:
-
option
(Symbol
) -- the option to be tested
def valid_option?(option) ALL_OPTIONS.include?(option) || option.is_a?(Integer) || option.respond_to?(:fileno) end