Class: Ukiryu::Options::Base Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/ukiryu/options/base.rb

Overview

This class is abstract.

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

Instance Method Details

#command_defHash?

Get the command definition

Returns:

  • (Hash, nil)

    the command definition from the profile



83
84
85
# File 'lib/ukiryu/options/base.rb', line 83

def command_def
  self.class.command_def
end

#command_nameSymbol

Get the command name

Returns:

  • (Symbol)

    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.

Examples:

Batch setting options

options.set(inputs: ["image.png"], resize: "50%")
options.output = "output.jpg"

Parameters:

  • params (Hash)

    hash of option names to values

Returns:

  • (self)

    returns self for method chaining



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

Parameters:

  • shell_type (Symbol) (defaults to: :bash)

    the shell type (:bash, :zsh, :fish, :powershell, etc.)

Returns:

  • (String)

    the formatted shell command (without executable)

Raises:

  • (NotImplementedError)


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

Returns:

  • (Boolean)

    true if valid, false otherwise



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

Returns:

  • (Boolean)

    true if valid

Raises:



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_errorsArray<String>

Get validation errors without raising exceptions

Returns:

  • (Array<String>)

    list of error messages



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