Class: ProcessExecuter::Options::SpawnOptions
- Defined in:
- lib/process_executer/options/spawn_options.rb
Overview
Defines and validates options accepted by Process.spawn
Allows subclasses to add additional options that are not passed to Process.spawn
.
Provides a method (#spawn_options) to retrieve only those options directly applicable to Process.spawn.
Direct Known Subclasses
Constant Summary collapse
- SPAWN_OPTIONS =
Options that are passed to Process.spawn
They are not passed if the value is :not_set
[ OptionDefinition.new(:unsetenv_others, default: :not_set), OptionDefinition.new(:pgroup, default: :not_set), OptionDefinition.new(:new_pgroup, default: :not_set), OptionDefinition.new(:rlimit_resourcename, default: :not_set), OptionDefinition.new(:umask, default: :not_set), OptionDefinition.new(:close_others, default: :not_set), OptionDefinition.new(:chdir, default: :not_set) ].freeze
Instance Method Summary collapse
-
#redirection?(option_key) ⇒ Boolean
private
Determine if the given option key indicates a redirection option.
-
#spawn_options ⇒ Hash
Returns the options to be passed to Process.spawn.
-
#std_redirection?(option_key, symbol, fileno) ⇒ Boolean
private
Does option_key indicate a standard redirection such as stdin, stdout, or stderr.
-
#stderr_redirection?(option_key) ⇒ Boolean
private
Determine if the given option key indicates a redirection option for stderr.
-
#stderr_redirection_destination ⇒ Symbol, ...
private
Determine redirection destination for stderr if it exists.
-
#stderr_redirection_source ⇒ Symbol, ...
private
Determine the option key that indicates a redirection option for stderr.
-
#stdout_redirection?(option_key) ⇒ Boolean
private
Determine if the given option key indicates a redirection option for stdout.
-
#stdout_redirection_destination ⇒ Symbol, ...
private
Return the redirection destination for stdout.
-
#stdout_redirection_source ⇒ Symbol, ...
private
Determine the option key that indicates a redirection option for stdout.
Methods inherited from Base
#allowed_options, #each_with_object, #initialize, #inspect, #merge, #merge!, #to_h, #to_s
Constructor Details
This class inherits a constructor from ProcessExecuter::Options::Base
Instance Method Details
#redirection?(option_key) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Determine if the given option key indicates a redirection option
57 58 59 60 |
# File 'lib/process_executer/options/spawn_options.rb', line 57 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 |
#spawn_options ⇒ Hash
Returns the options to be passed to Process.spawn
Any options added by subclasses that are not part of the SPAWN_OPTIONS or are not a redirection option will not be included in the returned hash.
45 46 47 48 49 50 51 |
# File 'lib/process_executer/options/spawn_options.rb', line 45 def {}.tap do || .each do |option_key, value| [option_key] = value if include_spawn_option?(option_key, value) end end end |
#std_redirection?(option_key, symbol, fileno) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Does option_key indicate a standard redirection such as stdin, stdout, or stderr
68 69 70 71 |
# File 'lib/process_executer/options/spawn_options.rb', line 68 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 |
#stderr_redirection?(option_key) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Determine if the given option key indicates a redirection option for stderr
97 |
# File 'lib/process_executer/options/spawn_options.rb', line 97 def stderr_redirection?(option_key) = std_redirection?(option_key, :err, 2) |
#stderr_redirection_destination ⇒ Symbol, ...
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Determine redirection destination for stderr if it exists
109 110 111 |
# File 'lib/process_executer/options/spawn_options.rb', line 109 def stderr_redirection_destination (key = stderr_redirection_source) ? [key] : nil end |
#stderr_redirection_source ⇒ Symbol, ...
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Determine the option key that indicates a redirection option for stderr
102 103 104 |
# File 'lib/process_executer/options/spawn_options.rb', line 102 def stderr_redirection_source .keys.find { |option_key| option_key if stderr_redirection?(option_key) } end |
#stdout_redirection?(option_key) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Determine if the given option key indicates a redirection option for stdout
77 |
# File 'lib/process_executer/options/spawn_options.rb', line 77 def stdout_redirection?(option_key) = std_redirection?(option_key, :out, 1) |
#stdout_redirection_destination ⇒ Symbol, ...
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return the redirection destination for stdout
89 90 91 |
# File 'lib/process_executer/options/spawn_options.rb', line 89 def stdout_redirection_destination (key = stdout_redirection_source) ? [key] : nil end |
#stdout_redirection_source ⇒ Symbol, ...
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Determine the option key that indicates a redirection option for stdout
82 83 84 |
# File 'lib/process_executer/options/spawn_options.rb', line 82 def stdout_redirection_source .keys.find { |option_key| option_key if stdout_redirection?(option_key) } end |