Class: Ukiryu::ToolMetadata
- Inherits:
-
Lutaml::Model::Serializable
- Object
- Lutaml::Model::Serializable
- Ukiryu::ToolMetadata
- Defined in:
- lib/ukiryu/models/tool_metadata.rb
Class Method Summary collapse
-
.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.
-
.parse_implements(implements_value) ⇒ Array<String, nil>
Parse implements field in format “interface@version” or “interface”.
Instance Method Summary collapse
-
#aliases ⇒ Array<String>
Get aliases, ensuring it’s always an array.
-
#backing_tool ⇒ Symbol?
Get backed_by as symbol.
-
#default_command ⇒ Symbol?
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.
-
#implements?(interface_name, version: nil) ⇒ Boolean
Check if this metadata matches an interface.
-
#implements_ref ⇒ String?
Get the full implements reference (interface@version).
-
#inspect ⇒ String
Inspect.
-
#may_provide_list ⇒ Array<Symbol>
Get may_provide as symbols.
- #name ⇒ String, ...
-
#to_s ⇒ String
String representation.
-
#tool_name ⇒ String
Get tool_name, defaulting to name if not set.
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
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”
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
#aliases ⇒ Array<String>
Get aliases, ensuring it’s always an array
89 90 91 |
# File 'lib/ukiryu/models/tool_metadata.rb', line 89 def aliases Array(@aliases || []) end |
#backing_tool ⇒ Symbol?
Get 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_command ⇒ Symbol?
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
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
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_ref ⇒ String?
Get the full implements reference (interface@version)
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 |
#inspect ⇒ String
Inspect
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_list ⇒ Array<Symbol>
Get may_provide 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 |
#name ⇒ String, ...
23 |
# File 'lib/ukiryu/models/tool_metadata.rb', line 23 attribute :name, :string |
#to_s ⇒ String
String representation
103 104 105 |
# File 'lib/ukiryu/models/tool_metadata.rb', line 103 def to_s "#{display_name || name} v#{version}" end |
#tool_name ⇒ String
Get tool_name, defaulting to name if not set
82 83 84 |
# File 'lib/ukiryu/models/tool_metadata.rb', line 82 def tool_name @tool_name || name end |