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:

  1. Load ImplementationIndex from register

  2. Load Interface definition

  3. Detect implementation and version

  4. Load ImplementationVersion

  5. Convert to ToolDefinition for compatibility

Class Method Summary collapse

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

Parameters:

  • index (Models::ImplementationIndex)

    the implementation index

  • tool_name (String)

    the tool name for executable lookup

  • options (Hash) (defaults to: {})

    options including platform and shell

Returns:

  • (Hash, nil)

    hash with :implementation_name, :version, :file or nil



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, options = {})
  target_platform = options[: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, options)
  end

  # Normal detection: try each implementation in order
  index.implementations.each do |impl|
    result = try_implementation(impl, tool_name, options)
    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

Parameters:

  • index (Models::ImplementationIndex)

    the implementation index

  • tool_name (String)

    the tool name

  • target_platform (Symbol)

    the target platform

  • options (Hash) (defaults to: {})

    options including shell

Returns:

  • (Hash, nil)

    implementation spec or nil



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, options = {})
  target_platform = target_platform.to_sym if target_platform.is_a?(String)
  target_shell = (options[: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,
        options
      )
      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

Parameters:

  • name (String, Symbol)

    the tool name

  • options (Hash) (defaults to: {})

    loading options

Returns:

  • (Tool, nil)

    the tool instance or nil if not using new 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, options = {})
  require_relative '../version_scheme_resolver'

  # Try to load ImplementationIndex
  index = Register.load_implementation_index(name, options)
  return nil unless index

  # Load Interface
  interface = Register.load_interface(index.interface, options)
  return nil unless interface

  # Detect implementation and version
  impl_spec = detect_implementation_and_version(index, name, options)
  return nil unless impl_spec

  # Load ImplementationVersion
  impl_version = Register.load_implementation_version(
    name,
    impl_spec[:implementation_name],
    impl_spec[:file],
    options
  )
  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
    options
  )
  return nil unless tool_definition

  # Create tool instance
  Tool.new(tool_definition, options)
end