class ProcessExecuter::Options::Base

@api public
options.option2 # => ‘value2’
options.option1 # => ‘value1’
options = MyOptions.new(options_hash)
options_hash = { options1: ‘value1’, option2: ‘value2’ }
end
end
]
ProcessExecuter::Options::OptionDefinition.new(:option2)
ProcessExecuter::Options::OptionDefinition.new(:option1),
*super,
[
# Call super to include options defined in the parent class
def define_options
class MyOptions < ProcessExecuter::Options::Base
@example Define an options class with two options
Options are defined by subclasses by overriding the ‘define_options` method.
Defines, validates, and holds a set of option values

def allowed_options

Returns:
  • (Hash) -
def allowed_options
  @allowed_options ||=
    define_options.each_with_object({}) do |option, hash|
      hash[option.name] = option
    end.freeze
end

def assert_no_unknown_options

Other tags:
    Api: - private

Raises:
  • (ArgumentError) - if the options hash contains any unknown options

Returns:
  • (void) -
def assert_no_unknown_options
  unknown_options = options.keys.reject { |key| valid_option?(key) }
  return if unknown_options.empty?
  # :nocov: SimpleCov on JRuby reports the last with the last argument line is not covered
  raise(
    ArgumentError,
    "Unknown option#{unknown_options.count > 1 ? 's' : ''}: #{unknown_options.join(', ')}"
  )
  # :nocov:
end

def define_accessor_methods

Other tags:
    Api: - private

Returns:
  • (void) -
def define_accessor_methods
  allowed_options.each_key do |option|
    define_singleton_method(option) do
      @options[option]
    end
  end
end

def define_options

Other tags:
    Api: - private

Returns:
  • (Array) -
def define_options
  [].freeze
end

def each_with_object(obj, &)

Returns:
  • (void) -

Other tags:
    Yield: -
def each_with_object(obj, &)
  @options.each_with_object(obj, &)
end

def initialize(**options)

Options Hash: (**options)
  • :timeout_after (Integer, Float, nil) --

Parameters:
  • options (Hash) -- Process.spawn options plus additional options listed below.
def initialize(**options)
  @options = allowed_options.transform_values(&:default).merge(options)
  @errors = []
  assert_no_unknown_options
  define_accessor_methods
  validate_options
end

def inspect

Returns:
  • (String) -
def inspect
  options.inspect
end

def merge!(**other_options)

Returns:
  • (void) -

Parameters:
  • other_options (Hash) -- the options to merge into the current options
def merge!(**other_options)
  @options.merge!(other_options)
end

def to_h

Returns:
  • (Hash) -
def to_h
  @options.dup
end

def to_s

Returns:
  • (String) -
def to_s
  "#{super.to_s[0..-2]} #{inspect}>"
end

def valid_option?(option)

Other tags:
    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)
  allowed_options.keys.include?(option)
end

def validate_options

Other tags:
    Api: - private

Raises:
  • (ArgumentError) - if any invalid option values are found

Returns:
  • (void) -
def validate_options
  options.each_key do |option_key|
    validator = allowed_options[option_key]&.validator
    instance_exec(&validator.to_proc) unless validator.nil?
  end
  raise ArgumentError, errors.join("\n") unless errors.empty?
end

def with(**options_hash)

Returns:
  • (self.class) -
def with(**options_hash)
  self.class.new(**@options, **options_hash)
end