Class: ProcessExecuter::Options::Base
- Inherits:
-
Object
- Object
- ProcessExecuter::Options::Base
- Defined in:
- lib/process_executer/options/base.rb
Overview
Defines, validates, and holds a set of option values
Options are defined by subclasses by overriding the define_options
method.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#errors ⇒ Array<String>
readonly
private
The list of validation errors.
Instance Method Summary collapse
-
#allowed_options ⇒ Hash
All the allowed options as a hash whose keys are the option names.
-
#each_with_object(obj) {|option_key, option_value, obj| ... }
Iterate over each option with an object.
-
#initialize(**options) ⇒ Base
constructor
Create a new Options object.
-
#inspect ⇒ String
A string representation of the options.
-
#merge!(**other_options)
Merge the given options into the current options.
-
#to_h ⇒ Hash
A hash representation of the options.
-
#to_s ⇒ String
A string representation of the object that includes the options.
-
#with(**options_hash) ⇒ self.class
A shallow copy of self with options copied but not the values they reference.
Constructor Details
#initialize(**options) ⇒ Base
Create a new Options object
44 45 46 47 48 49 50 |
# File 'lib/process_executer/options/base.rb', line 44 def initialize(**) @options = .transform_values(&:default).merge() @errors = [] define_accessor_methods end |
Instance Attribute Details
#errors ⇒ Array<String> (readonly)
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.
The list of validation errors
Validators should add an error messages to this array.
159 160 161 |
# File 'lib/process_executer/options/base.rb', line 159 def errors @errors end |
Instance Method Details
#allowed_options ⇒ Hash
All the allowed options as a hash whose keys are the option names
The returned hash what is returned from define_options
but with the
option names as keys. The values are instances of OptionDefinition
.
The returned hash is frozen and cannot be modified.
64 65 66 67 68 69 |
# File 'lib/process_executer/options/base.rb', line 64 def @allowed_options ||= .each_with_object({}) do |option, hash| hash[option.name] = option end.freeze end |
#each_with_object(obj) {|option_key, option_value, obj| ... }
This method returns an undefined value.
Iterate over each option with an object
105 106 107 |
# File 'lib/process_executer/options/base.rb', line 105 def each_with_object(obj, &) @options.each_with_object(obj, &) end |
#inspect ⇒ String
A string representation of the options
85 86 87 |
# File 'lib/process_executer/options/base.rb', line 85 def inspect .inspect end |
#merge!(**other_options)
This method returns an undefined value.
Merge the given options into the current options
118 119 120 |
# File 'lib/process_executer/options/base.rb', line 118 def merge!(**) @options.merge!() end |
#to_h ⇒ Hash
A hash representation of the options
94 95 96 |
# File 'lib/process_executer/options/base.rb', line 94 def to_h @options.dup end |
#to_s ⇒ String
A string representation of the object that includes the options
76 77 78 |
# File 'lib/process_executer/options/base.rb', line 76 def to_s "#{super.to_s[0..-2]} #{inspect}>" end |
#with(**options_hash) ⇒ self.class
A shallow copy of self with options copied but not the values they reference
If any keyword arguments are given, the copy will be created with the respective option values updated.
139 140 141 |
# File 'lib/process_executer/options/base.rb', line 139 def with(**) self.class.new(**@options, **) end |