Module: Ukiryu::Tool::Loader Private
- Defined in:
- lib/ukiryu/tool/loader.rb
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Handles loading of tools using the ImplementationIndex architecture
This module extracts the complex loading pipeline from the main Tool class:
-
Load ImplementationIndex from register
-
Load Interface definition
-
Detect implementation and version
-
Load ImplementationVersion
-
Convert to ToolDefinition for compatibility
Class Method Summary collapse
-
.detect_implementation_and_version(index, tool_name, options = {}) ⇒ Hash?
private
Detect implementation and version from ImplementationIndex.
-
.find_implementation_for_platform(index, tool_name, target_platform, options = {}) ⇒ Hash?
private
Find an implementation that supports the target platform.
-
.load_with_implementation_index(name, options = {}) ⇒ Tool?
private
Load a tool using the new ImplementationIndex architecture.
Class Method Details
.detect_implementation_and_version(index, tool_name, options = {}) ⇒ Hash?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Detect implementation and version from ImplementationIndex
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/ukiryu/tool/loader.rb', line 67 def detect_implementation_and_version(index, tool_name, = {}) target_platform = [:platform] current_platform = Platform.detect # If platform is overridden to a different platform, skip detection # and find an implementation that supports the target platform if target_platform && target_platform.to_sym != current_platform return find_implementation_for_platform(index, tool_name, target_platform, ) end # Normal detection: try each implementation in order index.implementations.each do |impl| result = try_implementation(impl, tool_name, ) return result if result end # If no implementation matched, use the first one's default fallback_to_default(index) end |
.find_implementation_for_platform(index, tool_name, target_platform, options = {}) ⇒ Hash?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Find an implementation that supports the target platform
94 95 96 97 98 99 100 101 102 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/tool/loader.rb', line 94 def find_implementation_for_platform(index, tool_name, target_platform, = {}) target_platform = target_platform.to_sym if target_platform.is_a?(String) target_shell = ([:shell] || Shell.detect).to_sym # Try each implementation and check if it has a profile for the target platform index.implementations.each do |impl| impl_name = impl[:name] || impl['name'] versions = impl[:versions] || impl['versions'] # Check each version file for platform compatibility versions.each do |version_spec| file = version_spec[:file] || version_spec['file'] next unless file # Load the implementation version to check profiles impl_version = Register.load_implementation_version( tool_name, impl_name, file, ) next unless impl_version # Check if any execution profile supports the target platform/shell profile = impl_version.compatible_profile(platform: target_platform, shell: target_shell) if profile # Found a compatible implementation return { implementation_name: impl_name, version: impl_version.version, file: file } end end end # No implementation supports the target platform nil end |
.load_with_implementation_index(name, options = {}) ⇒ Tool?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Load a tool using the new ImplementationIndex architecture
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/ukiryu/tool/loader.rb', line 22 def load_with_implementation_index(name, = {}) require_relative '../version_scheme_resolver' # Try to load ImplementationIndex index = Register.load_implementation_index(name, ) return nil unless index # Load Interface interface = Register.load_interface(index.interface, ) return nil unless interface # Detect implementation and version impl_spec = detect_implementation_and_version(index, name, ) return nil unless impl_spec # Load ImplementationVersion impl_version = Register.load_implementation_version( name, impl_spec[:implementation_name], impl_spec[:file], ) return nil unless impl_version # Convert to old ToolDefinition format for compatibility tool_definition = convert_to_tool_definition( name, interface, impl_version, impl_spec[:implementation_name], impl_spec[:version], # Pass detected version ) return nil unless tool_definition # Create tool instance Tool.new(tool_definition, ) end |