Class: Ukiryu::Models::ImplementationVersion

Inherits:
Object
  • Object
show all
Defined in:
lib/ukiryu/models/implementation_version.rb

Overview

ImplementationVersion model for a specific version of a tool implementation.

An ImplementationVersion contains the actual command definitions for a specific version of an implementation (e.g., GNU gzip 1.12).

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(implements:, version:, execution_profiles:, display_name: nil, aliases: [], version_detection: nil) ⇒ ImplementationVersion

Returns a new instance of ImplementationVersion.

Parameters:

  • implements (String)

    Interface this implements

  • version (String)

    Version string

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

    Human-readable name

  • aliases (Array<String>) (defaults to: [])

    Aliases for this implementation

  • execution_profiles (Array<Hash>)

    Execution profile definitions

  • version_detection (VersionDetection, nil) (defaults to: nil)

    Version detection configuration



27
28
29
30
31
32
33
34
35
# File 'lib/ukiryu/models/implementation_version.rb', line 27

def initialize(implements:, version:, execution_profiles:, display_name: nil, aliases: [], version_detection: nil)
  @implements = implements
  @version = version
  @display_name = display_name || "#{implements} #{version}"
  @aliases = Array(aliases).map(&:to_s)
  @execution_profiles = execution_profiles
  @version_detection = version_detection
  freeze
end

Instance Attribute Details

#aliasesArray<String>

Aliases for this implementation

Returns:

  • (Array<String>)

    the current value of aliases



18
19
20
# File 'lib/ukiryu/models/implementation_version.rb', line 18

def aliases
  @aliases
end

#display_nameString

Human-readable name

Returns:

  • (String)

    the current value of display_name



18
19
20
# File 'lib/ukiryu/models/implementation_version.rb', line 18

def display_name
  @display_name
end

#execution_profilesArray<ExecutionProfile>

Platform/shell profiles

Returns:



18
19
20
# File 'lib/ukiryu/models/implementation_version.rb', line 18

def execution_profiles
  @execution_profiles
end

#implementsString

Interface this implements (e.g., “gzip/1.0”)

Returns:

  • (String)

    the current value of implements



18
19
20
# File 'lib/ukiryu/models/implementation_version.rb', line 18

def implements
  @implements
end

#versionString

Version string

Returns:

  • (String)

    the current value of version



18
19
20
# File 'lib/ukiryu/models/implementation_version.rb', line 18

def version
  @version
end

#version_detectionVersionDetection

Version detection configuration

Returns:



18
19
20
# File 'lib/ukiryu/models/implementation_version.rb', line 18

def version_detection
  @version_detection
end

Class Method Details

.from_hash(data) ⇒ ImplementationVersion

Create ImplementationVersion from hash

Parameters:

  • data (Hash)

    Version data

Returns:



114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/ukiryu/models/implementation_version.rb', line 114

def self.from_hash(data)
  # Extract version_detection if present
  version_detection = if data[:version_detection] || data['version_detection']
                        vd_data = data[:version_detection] || data['version_detection']
                        VersionDetection.from_hash(vd_data)
                      end

  # Extract execution_profiles
  profiles_data = data[:execution_profiles] || data['execution_profiles'] || []

  new(
    implements: data[:implements],
    version: data[:version],
    display_name: data[:display_name],
    aliases: data[:aliases] || [],
    execution_profiles: profiles_data,
    version_detection: version_detection
  )
end

.from_yaml(path) ⇒ ImplementationVersion

Load ImplementationVersion from YAML file

Parameters:

  • path (String)

    Path to version YAML file

Returns:



103
104
105
106
107
108
# File 'lib/ukiryu/models/implementation_version.rb', line 103

def self.from_yaml(path)
  require 'psych'
  data = Psych.safe_load_file(path,
                              permitted_classes: [Symbol, String, Integer, Array, Hash, TrueClass, FalseClass])
  from_hash(data)
end

Instance Method Details

#compatible_profile(platform:, shell:) ⇒ Hash?

Get compatible profile for platform and shell

Parameters:

  • platform (Symbol, String)

    Target platform

  • shell (Symbol, String)

    Target shell

Returns:

  • (Hash, nil)

    Compatible profile or nil



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/ukiryu/models/implementation_version.rb', line 42

def compatible_profile(platform:, shell:)
  platform_str = platform.to_s
  shell_str = shell.to_s

  profile = @execution_profiles.find do |prof|
    platforms = Array(prof[:platforms] || prof[:platform]).map(&:to_s)
    shells = Array(prof[:shells] || prof[:shell]).map(&:to_s)

    platforms.include?(platform_str) && shells.include?(shell_str)
  end

  # Debug output for profile selection
  if ENV['UKIRYU_DEBUG_EXECUTABLE'] || (ENV['CI'] && defined?(Ukiryu::Platform) && Ukiryu::Platform.windows?)
    warn "[UKIRYU DEBUG compatible_profile] platform=#{platform_str}, shell=#{shell_str}"
    warn "[UKIRYU DEBUG compatible_profile] Found profile: #{profile ? (profile[:name] || profile['name']) : 'nil'}"
    if profile
      warn "[UKIRYU DEBUG compatible_profile] Profile inherits: #{profile[:inherits] || profile['inherits']}"
      warn "[UKIRYU DEBUG compatible_profile] Profile commands nil?: #{profile[:commands].nil?}"
      warn "[UKIRYU DEBUG compatible_profile] Profile commands empty?: #{(profile[:commands] || []).empty?}"
    end
  end

  return nil unless profile

  # Resolve profile inheritance at hash level
  # If profile has 'inherits', copy commands from parent profile
  inherits = profile[:inherits] || profile['inherits']
  if inherits
    parent_profile = @execution_profiles.find do |prof|
      prof_name = prof[:name] || prof['name']
      prof_name.to_s == inherits.to_s
    end

    if ENV['UKIRYU_DEBUG_EXECUTABLE'] || (ENV['CI'] && defined?(Ukiryu::Platform) && Ukiryu::Platform.windows?)
      warn "[UKIRYU DEBUG compatible_profile] Looking for parent '#{inherits}': #{parent_profile ? 'found' : 'not found'}"
    end

    if parent_profile && (profile[:commands].nil? || profile[:commands].empty?)
      # Copy parent's commands to child profile (without modifying original)
      parent_commands = parent_profile[:commands] || parent_profile['commands']
      # Return a new hash with inherited commands
      profile = profile.dup.merge(commands: parent_commands)
      warn "[UKIRYU DEBUG compatible_profile] Inherited #{parent_commands&.size || 0} commands from parent" if ENV['UKIRYU_DEBUG_EXECUTABLE'] || (ENV['CI'] && defined?(Ukiryu::Platform) && Ukiryu::Platform.windows?)
    end
  end

  profile
end

#inspectString

Inspect representation

Returns:

  • (String)


144
145
146
# File 'lib/ukiryu/models/implementation_version.rb', line 144

def inspect
  "#<Ukiryu::Models::ImplementationVersion #{self} profiles=#{@execution_profiles.length}>"
end

#profile(profile_name) ⇒ Hash?

Get profile by name

Parameters:

  • profile_name (Symbol)

    Profile name

Returns:

  • (Hash, nil)

    Profile or nil



95
96
97
# File 'lib/ukiryu/models/implementation_version.rb', line 95

def profile(profile_name)
  @execution_profiles.find { |p| p[:name] == profile_name }
end

#to_sString

String representation

Returns:

  • (String)


137
138
139
# File 'lib/ukiryu/models/implementation_version.rb', line 137

def to_s
  "#{@implements} #{@version}"
end