Class: Ukiryu::Tools::Base Abstract
- Inherits:
-
Object
- Object
- Ukiryu::Tools::Base
- Includes:
- CommandBuilder
- Defined in:
- lib/ukiryu/tools/base.rb
Overview
Abstract base class for all tool-specific classes
This class provides the common interface that all tool classes inherit from. Tool-specific classes are dynamically generated by Tools::Generator.
Class Attribute Summary collapse
-
.platform_profile ⇒ Models::PlatformProfile
readonly
Get the platform profile model.
-
.tool_definition ⇒ Models::ToolDefinition
readonly
Get the tool definition model.
-
.tool_name ⇒ Symbol
readonly
Get the tool name symbol.
Class Method Summary collapse
-
.action_class_for(command_name) ⇒ Class
Get the action class for a specific command.
-
.action_for(command_name) ⇒ Class
Alias for action_class_for.
-
.available? ⇒ Boolean
Check if the tool is available on this system.
-
.options_class_for(command_name) ⇒ Class
Get the options class for a specific command.
-
.options_for(command_name) ⇒ Class
Alias for options_class_for (more idiomatic).
-
.response_class_for(command_name) ⇒ Class
Get the response class for a command.
-
.version ⇒ Version?
Get version information for this tool.
Instance Method Summary collapse
-
#action_class_for(command_name) ⇒ Class
Get the action class for a command.
-
#action_for(command_name) ⇒ Action::Base
Get a new action instance for a command.
-
#available? ⇒ Boolean
Check if the tool is available.
-
#execute(command_name, options, execution_timeout:) ⇒ Response::Base
Execute a command with options object.
-
#initialize ⇒ Base
constructor
Initialize the tool instance.
-
#name ⇒ String
Get the tool name from the tool definition.
-
#options_class_for(command_name) ⇒ Class
Get the options class for a command.
-
#options_for(command_name) ⇒ Options::Base
Get a new options instance for a command.
-
#platform_profile ⇒ Models::PlatformProfile
Get the platform profile (for backward compatibility).
-
#tool_definition ⇒ Models::ToolDefinition
Get the tool definition (for backward compatibility).
-
#tool_name ⇒ Symbol
Get the tool name for this instance.
-
#unavailability_reason ⇒ String?
Get the reason why the tool is not available.
-
#version ⇒ String?
Get version information.
Methods included from CommandBuilder
#build_env_vars, #detect_delimiter, #format_arg, #format_flag, #format_option
Constructor Details
Class Attribute Details
.platform_profile ⇒ Models::PlatformProfile (readonly)
Get the platform profile model
38 39 40 |
# File 'lib/ukiryu/tools/base.rb', line 38 def platform_profile @platform_profile end |
.tool_definition ⇒ Models::ToolDefinition (readonly)
Get the tool definition model
33 34 35 |
# File 'lib/ukiryu/tools/base.rb', line 33 def tool_definition @tool_definition end |
.tool_name ⇒ Symbol (readonly)
Get the tool name symbol
28 29 30 |
# File 'lib/ukiryu/tools/base.rb', line 28 def tool_name @tool_name end |
Class Method Details
.action_class_for(command_name) ⇒ Class
Get the action class for a specific command
71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/ukiryu/tools/base.rb', line 71 def action_class_for(command_name) command_name = command_name.to_sym @action_classes ||= {} return @action_classes[command_name] if @action_classes[command_name] # Get command from platform profile model command_def = @platform_profile.command(command_name.to_s) raise ArgumentError, "Unknown command: #{command_name}" unless command_def # Generate the action class using ClassGenerator action_class = Ukiryu::Tools::ClassGenerator.generate_action_class(self, command_name, command_def) @action_classes[command_name] = action_class action_class end |
.action_for(command_name) ⇒ Class
Alias for action_class_for
90 91 92 |
# File 'lib/ukiryu/tools/base.rb', line 90 def action_for(command_name) action_class_for(command_name) end |
.available? ⇒ Boolean
Check if the tool is available on this system
106 107 108 109 110 111 112 113 114 |
# File 'lib/ukiryu/tools/base.rb', line 106 def available? @available ||= begin # Check for compatible profile first return false unless platform_profile executable = Ukiryu::ExecutableFinder.find_executable(@tool_definition.name.to_s, @tool_definition) !executable.nil? end end |
.options_class_for(command_name) ⇒ Class
Get the options class for a specific command
44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/ukiryu/tools/base.rb', line 44 def (command_name) command_name = command_name.to_sym @options_classes ||= {} return @options_classes[command_name] if @options_classes[command_name] # Get command from platform profile model command_def = @platform_profile.command(command_name.to_s) raise ArgumentError, "Unknown command: #{command_name}" unless command_def # Generate the options class using ClassGenerator = Ukiryu::Tools::ClassGenerator.(self, command_name, command_def) @options_classes[command_name] = end |
.options_for(command_name) ⇒ Class
Alias for options_class_for (more idiomatic)
63 64 65 |
# File 'lib/ukiryu/tools/base.rb', line 63 def (command_name) (command_name) end |
.response_class_for(command_name) ⇒ Class
Get the response class for a command
120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/ukiryu/tools/base.rb', line 120 def response_class_for(command_name) command_name = command_name.to_sym @response_classes ||= {} return @response_classes[command_name] if @response_classes[command_name] # Get command from platform profile model command_def = @platform_profile.command(command_name.to_s) raise ArgumentError, "Unknown command: #{command_name}" unless command_def # Generate the response class using ClassGenerator response_class = Ukiryu::Tools::ClassGenerator.generate_response_class(self, command_name, command_def) @response_classes[command_name] = response_class response_class end |
.version ⇒ Version?
Get version information for this tool
97 98 99 100 101 |
# File 'lib/ukiryu/tools/base.rb', line 97 def version return nil unless available? new.version end |
Instance Method Details
#action_class_for(command_name) ⇒ Class
Get the action class for a command
201 202 203 |
# File 'lib/ukiryu/tools/base.rb', line 201 def action_class_for(command_name) self.class.action_for(command_name) end |
#action_for(command_name) ⇒ Action::Base
Get a new action instance for a command
193 194 195 |
# File 'lib/ukiryu/tools/base.rb', line 193 def action_for(command_name) self.class.action_for(command_name).new(self) end |
#available? ⇒ Boolean
Check if the tool is available
217 218 219 |
# File 'lib/ukiryu/tools/base.rb', line 217 def available? self.class.available? end |
#execute(command_name, options, execution_timeout:) ⇒ Response::Base
Execute a command with options object
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 |
# File 'lib/ukiryu/tools/base.rb', line 244 def execute(command_name, , execution_timeout:) command_name = command_name.to_sym # Get command from platform profile model command_def = self.class.platform_profile.command(command_name.to_s) raise ArgumentError, "Unknown command: #{command_name}" unless command_def # Convert options to hash params = if .is_a?(Hash) .transform_keys(&:to_sym) else Ukiryu::OptionsBuilder.to_hash() end # Build arguments args = build_args(command_def, params) # Find executable using ExecutableFinder executable = Ukiryu::ExecutableFinder.find_executable(self.class.tool_definition.name.to_s, self.class.tool_definition) # Get shell shell_sym = Ukiryu::Runtime.instance.shell # Build environment variables (including env var sets) env = build_execution_env(command_def, @platform_profile, params) # Execute with explicit timeout result = Ukiryu::Executor.execute( executable, args, env: env, timeout: execution_timeout, shell: shell_sym ) # Build response build_response(command_name, result) end |
#name ⇒ String
Get the tool name from the tool definition
155 156 157 |
# File 'lib/ukiryu/tools/base.rb', line 155 def name self.class.tool_definition.name end |
#options_class_for(command_name) ⇒ Class
Get the options class for a command
185 186 187 |
# File 'lib/ukiryu/tools/base.rb', line 185 def (command_name) self.class.(command_name) end |
#options_for(command_name) ⇒ Options::Base
Get a new options instance for a command
177 178 179 |
# File 'lib/ukiryu/tools/base.rb', line 177 def (command_name) self.class.(command_name).new end |
#platform_profile ⇒ Models::PlatformProfile
Get the platform profile (for backward compatibility)
169 170 171 |
# File 'lib/ukiryu/tools/base.rb', line 169 def platform_profile self.class.platform_profile end |
#tool_definition ⇒ Models::ToolDefinition
Get the tool definition (for backward compatibility)
162 163 164 |
# File 'lib/ukiryu/tools/base.rb', line 162 def tool_definition self.class.tool_definition end |
#tool_name ⇒ Symbol
Get the tool name for this instance
148 149 150 |
# File 'lib/ukiryu/tools/base.rb', line 148 def tool_name self.class.tool_name end |
#unavailability_reason ⇒ String?
Get the reason why the tool is not available
Returns nil if the tool is available, or a string explaining why not. This helps users understand issues like:
-
Tool not installed
-
Wrong version installed (e.g., impostor tool)
229 230 231 232 233 234 235 236 |
# File 'lib/ukiryu/tools/base.rb', line 229 def unavailability_reason return nil if available? return if executable.nil? return if version_mismatch? end |
#version ⇒ String?
Get version information
208 209 210 211 212 |
# File 'lib/ukiryu/tools/base.rb', line 208 def version return @version if defined?(@version) @version = detect_version end |