Class: Ukiryu::Models::ToolDefinition
- Inherits:
-
Lutaml::Model::Serializable
- Object
- Lutaml::Model::Serializable
- Ukiryu::Models::ToolDefinition
- Defined in:
- lib/ukiryu/models/tool_definition.rb
Overview
Tool definition loaded from YAML profile
Instance Attribute Summary collapse
-
#self_uri ⇒ String?
readonly
Get the self URI.
Instance Method Summary collapse
-
#available_on?(platform) ⇒ Boolean
Check if tool is available on a platform.
-
#compatible_profile(platform: nil, shell: nil) ⇒ PlatformProfile?
Get compatible profile for current platform/shell.
-
#implements?(interface_name) ⇒ Boolean
Check if tool implements an interface.
-
#implements_any?(*interface_names) ⇒ Boolean
Check if tool implements any of the given interfaces.
-
#interfaces ⇒ Array<String>
Get all interfaces this tool implements.
-
#resolve_inheritance! ⇒ self
Resolve profile inheritance.
-
#schema_version ⇒ String?
Get the schema version.
-
#schema_version?(version) ⇒ Boolean
Check if a specific schema version is specified.
Instance Attribute Details
#self_uri ⇒ String? (readonly)
Get the self URI
144 145 146 |
# File 'lib/ukiryu/models/tool_definition.rb', line 144 def self_uri @self_uri end |
Instance Method Details
#available_on?(platform) ⇒ Boolean
Check if tool is available on a platform
91 92 93 94 95 |
# File 'lib/ukiryu/models/tool_definition.rb', line 91 def available_on?(platform) return true if profiles.empty? profiles.any? { |p| p.is_a?(PlatformProfile) && p.supports_platform?(platform) } end |
#compatible_profile(platform: nil, shell: nil) ⇒ PlatformProfile?
Get compatible profile for current platform/shell
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/ukiryu/models/tool_definition.rb', line 44 def compatible_profile(platform: nil, shell: nil) platform ||= Ukiryu::Platform.detect shell ||= Ukiryu::Shell.detect return nil unless platform && shell return nil if profiles.nil? || profiles.empty? profiles.find do |p| p.is_a?(PlatformProfile) && p.compatible?(platform.to_sym, shell.to_sym) end end |
#implements?(interface_name) ⇒ Boolean
Check if tool implements an interface
60 61 62 63 64 65 |
# File 'lib/ukiryu/models/tool_definition.rb', line 60 def implements?(interface_name) # v2: implements is an array, check if it contains the interface # v1: implements is a string, check for equality interface_sym = interface_name.to_s.to_sym implements_any?(interface_sym) end |
#implements_any?(*interface_names) ⇒ Boolean
Check if tool implements any of the given interfaces
71 72 73 74 75 76 77 78 |
# File 'lib/ukiryu/models/tool_definition.rb', line 71 def implements_any?(*interface_names) return false if implements.nil? || implements.empty? interface_syms = interface_names.flatten.map(&:to_sym) implements_syms = implements.map(&:to_sym) (interface_syms & implements_syms).any? end |
#interfaces ⇒ Array<String>
Get all interfaces this tool implements
83 84 85 |
# File 'lib/ukiryu/models/tool_definition.rb', line 83 def interfaces implements || [] end |
#resolve_inheritance! ⇒ self
Resolve profile inheritance
Merges parent profile commands into child profiles that have ‘inherits` set. The child profile’s commands take precedence over parent commands.
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/ukiryu/models/tool_definition.rb', line 103 def resolve_inheritance! return self unless profiles profiles.each do |profile| next unless profile.inherits # Find parent profile by name parent_profile = profiles.find { |p| p.name == profile.inherits } next unless parent_profile # Merge parent commands into child (child takes precedence) parent_commands = parent_profile.commands || [] child_commands = profile.commands || [] # Create a map of child commands by name for quick lookup child_commands_map = child_commands.to_h { |c| [c.name, c] } # Add parent commands that don't exist in child merged_commands = child_commands.dup parent_commands.each do |parent_cmd| merged_commands << parent_cmd unless child_commands_map.key?(parent_cmd.name) end # Update profile commands and clear index so it rebuilds on next access profile.commands = merged_commands profile.clear_commands_index! end self end |
#schema_version ⇒ String?
Get the schema version
137 138 139 |
# File 'lib/ukiryu/models/tool_definition.rb', line 137 def schema_version ukiryu_schema end |
#schema_version?(version) ⇒ Boolean
Check if a specific schema version is specified
150 151 152 |
# File 'lib/ukiryu/models/tool_definition.rb', line 150 def schema_version?(version) ukiryu_schema == version end |