Class: Ukiryu::Definition::DefinitionMetadata
- Inherits:
-
Object
- Object
- Ukiryu::Definition::DefinitionMetadata
- Includes:
- Comparable
- Defined in:
- lib/ukiryu/definition/metadata.rb
Overview
Metadata about a discovered tool definition
This class encapsulates information about a tool definition that was discovered in the filesystem.
Instance Attribute Summary collapse
-
#name ⇒ String
readonly
The tool name.
-
#path ⇒ String
readonly
The path to the definition file.
-
#source_type ⇒ Symbol
readonly
The source type (user, system, bundled, register).
-
#version ⇒ String
readonly
The tool version.
Instance Method Summary collapse
-
#<=>(other) ⇒ Integer
Compare priorities for sorting.
-
#==(other) ⇒ Boolean
Compare two metadata objects.
-
#exists? ⇒ Boolean
Check if the definition file exists.
-
#hash ⇒ Integer
Hash code for hash keys.
-
#initialize(name:, version:, path:, source_type:) ⇒ DefinitionMetadata
constructor
Create a new definition metadata.
-
#inspect ⇒ String
Detailed inspection string.
-
#load_definition ⇒ Models::ToolDefinition
Get the tool definition by loading the YAML.
-
#mtime ⇒ Time?
Get the file modification time.
-
#priority ⇒ Integer
Source type priorities (lower = higher priority).
-
#to_s ⇒ String
Get a string representation.
Constructor Details
#initialize(name:, version:, path:, source_type:) ⇒ DefinitionMetadata
Create a new definition metadata
34 35 36 37 38 39 |
# File 'lib/ukiryu/definition/metadata.rb', line 34 def initialize(name:, version:, path:, source_type:) @name = name @version = version @path = File.(path) @source_type = source_type end |
Instance Attribute Details
#name ⇒ String (readonly)
The tool name
14 15 16 |
# File 'lib/ukiryu/definition/metadata.rb', line 14 def name @name end |
#path ⇒ String (readonly)
The path to the definition file
22 23 24 |
# File 'lib/ukiryu/definition/metadata.rb', line 22 def path @path end |
#source_type ⇒ Symbol (readonly)
The source type (user, system, bundled, register)
26 27 28 |
# File 'lib/ukiryu/definition/metadata.rb', line 26 def source_type @source_type end |
#version ⇒ String (readonly)
The tool version
18 19 20 |
# File 'lib/ukiryu/definition/metadata.rb', line 18 def version @version end |
Instance Method Details
#<=>(other) ⇒ Integer
Compare priorities for sorting
115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/ukiryu/definition/metadata.rb', line 115 def <=>(other) return 0 unless other.is_a?(DefinitionMetadata) # Compare by priority (lower number = higher priority) priority_comparison = priority <=> other.priority return priority_comparison unless priority_comparison.zero? # Same priority, compare by version (descending - higher version first) version_comparison = compare_versions(@version, other.version) return version_comparison unless version_comparison.zero? # Same version, compare by name @name <=> other.name end |
#==(other) ⇒ Boolean
Compare two metadata objects
81 82 83 84 85 86 87 88 |
# File 'lib/ukiryu/definition/metadata.rb', line 81 def ==(other) return false unless other.is_a?(DefinitionMetadata) @name == other.name && @version == other.version && @path == other.path && @source_type == other.source_type end |
#exists? ⇒ Boolean
Check if the definition file exists
52 53 54 |
# File 'lib/ukiryu/definition/metadata.rb', line 52 def exists? File.exist?(@path) end |
#hash ⇒ Integer
Hash code for hash keys
93 94 95 |
# File 'lib/ukiryu/definition/metadata.rb', line 93 def hash [@name, @version, @path, @source_type].hash end |
#inspect ⇒ String
Detailed inspection string
73 74 75 |
# File 'lib/ukiryu/definition/metadata.rb', line 73 def inspect "#<#{self.class.name} name=#{@name.inspect} version=#{@version.inspect} path=#{@path.inspect} source_type=#{@source_type.inspect}>" end |
#load_definition ⇒ Models::ToolDefinition
Get the tool definition by loading the YAML
45 46 47 |
# File 'lib/ukiryu/definition/metadata.rb', line 45 def load_definition Loader.load_from_file(@path) end |
#mtime ⇒ Time?
Get the file modification time
59 60 61 |
# File 'lib/ukiryu/definition/metadata.rb', line 59 def mtime File.mtime(@path) if exists? end |
#priority ⇒ Integer
Source type priorities (lower = higher priority)
100 101 102 103 104 105 106 107 108 109 |
# File 'lib/ukiryu/definition/metadata.rb', line 100 def priority case @source_type when :user then 1 when :bundled then 2 when :local_system then 3 when :system then 4 when :register then 5 else 999 end end |
#to_s ⇒ String
Get a string representation
66 67 68 |
# File 'lib/ukiryu/definition/metadata.rb', line 66 def to_s "#{@name}/#{@version} (#{@source_type}) - #{@path}" end |