Class: Ukiryu::Models::ImplementationIndex

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

Overview

ImplementationIndex model for routing to specific tool implementations.

The ImplementationIndex defines which implementations exist for a tool, how to detect them, their version schemes, and version-to-file routing.

Examples:

index = ImplementationIndex.new(
  name: :gzip,
  interface: :gzip,
  interface_version: "1.0",
  implementations: [
    {
      name: :gnu,
      detection: { command: ["--version"], pattern: "GNU gzip (.+)" },
      version_scheme: :semantic,
      versions: [{ equals: "1.12.0", file: "gnu/1.12.yaml" }],
      default: "gnu/1.12.yaml"
    }
  ]
)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, interface:, implementations:, interface_version: '1.0') ⇒ ImplementationIndex

Returns a new instance of ImplementationIndex.

Parameters:

  • name (Symbol)

    Tool identifier

  • interface (Symbol)

    Interface this tool implements

  • interface_version (String) (defaults to: '1.0')

    Interface version (default: “1.0”)

  • implementations (Array<Hash>)

    Implementation definitions



40
41
42
43
44
45
46
# File 'lib/ukiryu/models/implementation_index.rb', line 40

def initialize(name:, interface:, implementations:, interface_version: '1.0')
  @name = name
  @interface = interface
  @interface_version = interface_version
  @implementations = implementations.map { |impl| symbolize_hash(impl) }
  freeze
end

Instance Attribute Details

#implementationsArray<Hash>

Implementation definitions

Returns:

  • (Array<Hash>)

    the current value of implementations



33
34
35
# File 'lib/ukiryu/models/implementation_index.rb', line 33

def implementations
  @implementations
end

#interfaceSymbol

Interface this tool implements

Returns:

  • (Symbol)

    the current value of interface



33
34
35
# File 'lib/ukiryu/models/implementation_index.rb', line 33

def interface
  @interface
end

#interface_versionString

Interface version

Returns:

  • (String)

    the current value of interface_version



33
34
35
# File 'lib/ukiryu/models/implementation_index.rb', line 33

def interface_version
  @interface_version
end

#nameSymbol

Tool identifier

Returns:

  • (Symbol)

    the current value of name



33
34
35
# File 'lib/ukiryu/models/implementation_index.rb', line 33

def name
  @name
end

Class Method Details

.from_hash(data) ⇒ ImplementationIndex

Create ImplementationIndex from hash

Parameters:

  • data (Hash)

    Index data

Returns:



78
79
80
81
82
83
84
85
# File 'lib/ukiryu/models/implementation_index.rb', line 78

def self.from_hash(data)
  new(
    name: data[:name],
    interface: data[:interface],
    interface_version: data[:interface_version] || '1.0',
    implementations: data[:implementations] || []
  )
end

.from_yaml(path) ⇒ ImplementationIndex

Load ImplementationIndex from YAML file

Parameters:

  • path (String)

    Path to index YAML file

Returns:



67
68
69
70
71
72
# File 'lib/ukiryu/models/implementation_index.rb', line 67

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

#implementation(impl_name) ⇒ Hash?

Get an implementation by name

Parameters:

  • impl_name (Symbol)

    Implementation name

Returns:

  • (Hash, nil)

    Implementation or nil



52
53
54
# File 'lib/ukiryu/models/implementation_index.rb', line 52

def implementation(impl_name)
  @implementations.find { |impl| impl[:name] == impl_name }
end

#implementation_namesArray<Symbol>

Get all implementation names

Returns:

  • (Array<Symbol>)

    Implementation names



59
60
61
# File 'lib/ukiryu/models/implementation_index.rb', line 59

def implementation_names
  @implementations.map { |impl| impl[:name] }
end

#inspectString

Inspect representation

Returns:

  • (String)


97
98
99
# File 'lib/ukiryu/models/implementation_index.rb', line 97

def inspect
  "#<Ukiryu::Models::ImplementationIndex #{self} implementations=#{@implementations.length}>"
end

#to_sString

String representation

Returns:

  • (String)


90
91
92
# File 'lib/ukiryu/models/implementation_index.rb', line 90

def to_s
  "#{@name} (implements #{@interface}/#{@interface_version})"
end