File: spawn_with_timeout_options.rb

package info (click to toggle)
ruby-process-executer 4.0.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 408 kB
  • sloc: ruby: 873; makefile: 4
file content (43 lines) | stat: -rw-r--r-- 1,200 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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
43
# frozen_string_literal: true

require_relative 'spawn_options'
require_relative 'option_definition'

module ProcessExecuter
  module Options
    # Defines options for {ProcessExecuter.spawn_with_timeout}
    #
    # @api public
    #
    class SpawnWithTimeoutOptions < SpawnOptions
      private

      # The options allowed for objects of this class
      # @return [Array<OptionDefinition>]
      # @api private
      def define_options
        [
          *super,
          OptionDefinition.new(:timeout_after, default: nil, validator: method(:validate_timeout_after))
        ].freeze
      end

      # Note an error if timeout_after is not nil or a non-negative real number
      #
      # @param _key [Symbol] the option key (not used)
      #
      # @param _value [Object] the option value (not used)
      #
      # @return [void]
      #
      # @api private
      #
      def validate_timeout_after(_key, _value)
        return if timeout_after.nil?
        return if timeout_after.is_a?(Numeric) && timeout_after.real? && !timeout_after.negative?

        errors << "timeout_after must be nil or a non-negative real number but was #{timeout_after.inspect}"
      end
    end
  end
end