Class: Ukiryu::Options::Base Abstract
- Inherits:
-
Object
- Object
- Ukiryu::Options::Base
- Defined in:
- lib/ukiryu/options/base.rb
Overview
Abstract base class for all option classes
This class provides common functionality for all dynamically generated option classes, including batch setting via .set() and execution via .run().
Instance Method Summary collapse
-
#command_def ⇒ Hash?
Get the command definition.
-
#command_name ⇒ Symbol
Get the command name.
-
#set(params) ⇒ self
Set multiple options at once.
-
#to_shell(shell_type: :bash) ⇒ String
Convert options to shell command string.
-
#valid? ⇒ Boolean
Check if options are valid without raising errors.
-
#validate! ⇒ Boolean
Validate the options.
-
#validation_errors ⇒ Array<String>
Get validation errors without raising exceptions.
Instance Method Details
#command_def ⇒ Hash?
Get the command definition
83 84 85 |
# File 'lib/ukiryu/options/base.rb', line 83 def command_def self.class.command_def end |
#command_name ⇒ Symbol
Get the command name
90 91 92 |
# File 'lib/ukiryu/options/base.rb', line 90 def command_name self.class.command_name end |
#set(params) ⇒ self
Set multiple options at once
This method allows batch assignment of options. Each key in the params hash should correspond to an attribute name.
23 24 25 26 27 28 29 |
# File 'lib/ukiryu/options/base.rb', line 23 def set(params) params.each do |key, value| setter = "#{key}=" send(setter, value) if respond_to?(setter) end self end |
#to_shell(shell_type: :bash) ⇒ String
Convert options to shell command string
76 77 78 |
# File 'lib/ukiryu/options/base.rb', line 76 def to_shell(shell_type: :bash) raise NotImplementedError, 'Subclasses must implement to_shell' end |
#valid? ⇒ Boolean
Check if options are valid without raising errors
54 55 56 57 58 59 |
# File 'lib/ukiryu/options/base.rb', line 54 def valid? validate! true rescue Ukiryu::Errors::ValidationError false end |
#validate! ⇒ Boolean
Validate the options
Performs comprehensive validation using constraint-based validation. This includes:
-
Type checking using TypeConstraint
-
Required argument checking using RequiredConstraint
-
Value constraints (min, max, range) using RangeConstraint
-
Enum value validation using EnumConstraint
-
Option dependencies using DependencyConstraint
43 44 45 46 47 48 49 |
# File 'lib/ukiryu/options/base.rb', line 43 def validate! command_def = self.class.command_def return true unless command_def validator = Validation::Validator.new(self, command_def) validator.validate! end |
#validation_errors ⇒ Array<String>
Get validation errors without raising exceptions
64 65 66 67 68 69 70 |
# File 'lib/ukiryu/options/base.rb', line 64 def validation_errors command_def = self.class.command_def return [] unless command_def validator = Validation::Validator.new(self, command_def) validator.errors end |