Class: Ukiryu::Models::ToolDefinition

Inherits:
Lutaml::Model::Serializable
  • Object
show all
Defined in:
lib/ukiryu/models/tool_definition.rb

Overview

Tool definition loaded from YAML profile

Examples:

tool = ToolDefinition.from_yaml(yaml_string)
profile = tool.compatible_profile

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#self_uriString? (readonly)

Get the self URI

Returns:

  • (String, nil)

    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

Parameters:

  • platform (Symbol)

    the platform

Returns:

  • (Boolean)

    true if available



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

Parameters:

  • platform (Symbol) (defaults to: nil)

    the platform

  • shell (Symbol) (defaults to: nil)

    the shell

Returns:



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

Parameters:

  • interface_name (String, Symbol)

    the interface name

Returns:

  • (Boolean)

    true if implements



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

Parameters:

  • interface_names (Array<Symbol>)

    the interface names to check

Returns:

  • (Boolean)

    true if 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

#interfacesArray<String>

Get all interfaces this tool implements

Returns:

  • (Array<String>)

    array of interface names



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.

Returns:

  • (self)

    returns self for chaining



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_versionString?

Get the schema version

Returns:

  • (String, nil)

    the schema version (e.g., “1.0”, “1.1”, “1.2”)



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

Parameters:

  • version (String)

    the version to check

Returns:

  • (Boolean)

    true if this is the schema version



150
151
152
# File 'lib/ukiryu/models/tool_definition.rb', line 150

def schema_version?(version)
  ukiryu_schema == version
end