Class: Ukiryu::ToolMetadata

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.from_hash(hash, tool_name:, register_path: nil) ⇒ ToolMetadata

Class method to create from YAML hash Extracts only metadata fields from a full tool profile

Parameters:

  • hash (Hash)

    the YAML profile hash

  • tool_name (String)

    the tool name

  • register_path (String) (defaults to: nil)

    the register path

Returns:



135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/ukiryu/models/tool_metadata.rb', line 135

def self.from_hash(hash, tool_name:, register_path: nil)
  implements_val = hash['implements']
  interface, version = parse_implements(implements_val)

  new(
    name: tool_name,
    version: hash['version'],
    display_name: hash['display_name'],
    implements: interface,
    implements_version: version,
    homepage: hash['homepage'],
    description: hash['description'],
    aliases: hash['aliases'] || [],
    tool_name: tool_name,
    register_path: register_path,
    default_command: hash['default_command'],
    may_provide: hash['may_provide'] || [],
    backed_by: hash['backed_by']
  )
end

.parse_implements(implements_value) ⇒ Array<String, nil>

Parse implements field in format “interface@version” or “interface”

Parameters:

  • implements_value (String, nil)

    the implements value from YAML

Returns:

  • (Array<String, nil>)

    interface and version



118
119
120
121
122
123
124
125
126
# File 'lib/ukiryu/models/tool_metadata.rb', line 118

def self.parse_implements(implements_value)
  return [nil, nil] unless implements_value

  if implements_value.to_s.include?('@')
    implements_value.to_s.split('@', 2)
  else
    [implements_value.to_s, nil]
  end
end

Instance Method Details

#aliasesArray<String>

Get aliases, ensuring it’s always an array

Returns:

  • (Array<String>)

    the aliases as an array



89
90
91
# File 'lib/ukiryu/models/tool_metadata.rb', line 89

def aliases
  Array(@aliases || [])
end

#backing_toolSymbol?

Get backed_by as symbol

Returns:

  • (Symbol, nil)

    backed_by as symbol



96
97
98
# File 'lib/ukiryu/models/tool_metadata.rb', line 96

def backing_tool
  backed_by&.to_sym
end

#default_commandSymbol?

Get the primary command name for this tool Returns the default_command from YAML if set, otherwise the implements value, otherwise falls back to the tool name

Returns:

  • (Symbol, nil)

    the default command name



68
69
70
# File 'lib/ukiryu/models/tool_metadata.rb', line 68

def default_command
  @default_command&.to_sym || implements&.to_sym || name&.to_sym
end

#implements?(interface_name, version: nil) ⇒ Boolean

Check if this metadata matches an interface

Parameters:

  • interface_name (Symbol, String)

    the interface to check

  • version (String, nil) (defaults to: nil)

    optional version to match

Returns:

  • (Boolean)

    true if this tool implements the interface (and version if specified)



51
52
53
54
55
56
57
58
59
60
61
# File 'lib/ukiryu/models/tool_metadata.rb', line 51

def implements?(interface_name, version: nil)
  return false unless implements

  matches_interface = implements.to_sym == interface_name.to_sym || implements == interface_name.to_s

  if version
    matches_interface && implements_version == version
  else
    matches_interface
  end
end

#implements_refString?

Get the full implements reference (interface@version)

Returns:

  • (String, nil)

    the implements reference



40
41
42
43
44
# File 'lib/ukiryu/models/tool_metadata.rb', line 40

def implements_ref
  return nil unless implements && implements_version

  "#{implements}@#{implements_version}"
end

#inspectString

Inspect

Returns:

  • (String)

    inspection string



110
111
112
# File 'lib/ukiryu/models/tool_metadata.rb', line 110

def inspect
  "#<#{self.class.name} name=#{name.inspect} version=#{version.inspect} implements=#{implements.inspect}>"
end

#may_provide_listArray<Symbol>

Get may_provide as symbols

Returns:

  • (Array<Symbol>)

    may_provide list as symbols



75
76
77
# File 'lib/ukiryu/models/tool_metadata.rb', line 75

def may_provide_list
  Array(may_provide).map(&:to_sym)
end

#nameString, ...

Returns:

  • (String)

    tool name

  • (String)

    tool version

  • (String, nil)

    display name

  • (String, nil)

    interface this tool implements

  • (String, nil)

    interface version

  • (String, nil)

    homepage URL

  • (String, nil)

    description

  • (Array<String>)

    aliases

  • (String)

    tool name (may differ from name)

  • (String, nil)

    register path

  • (Symbol, nil)

    default command

  • (Array<Symbol>)

    list of tools this may provide

  • (Symbol, nil)

    parent tool this is backed by



23
# File 'lib/ukiryu/models/tool_metadata.rb', line 23

attribute :name, :string

#to_sString

String representation

Returns:

  • (String)

    description string



103
104
105
# File 'lib/ukiryu/models/tool_metadata.rb', line 103

def to_s
  "#{display_name || name} v#{version}"
end

#tool_nameString

Get tool_name, defaulting to name if not set

Returns:

  • (String)

    the tool name



82
83
84
# File 'lib/ukiryu/models/tool_metadata.rb', line 82

def tool_name
  @tool_name || name
end