Class: Ukiryu::Models::ImplementationIndex
- Inherits:
-
Object
- Object
- Ukiryu::Models::ImplementationIndex
- 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.
Instance Attribute Summary collapse
-
#implementations ⇒ Array<Hash>
Implementation definitions.
-
#interface ⇒ Symbol
Interface this tool implements.
-
#interface_version ⇒ String
Interface version.
-
#name ⇒ Symbol
Tool identifier.
Class Method Summary collapse
-
.from_hash(data) ⇒ ImplementationIndex
Create ImplementationIndex from hash.
-
.from_yaml(path) ⇒ ImplementationIndex
Load ImplementationIndex from YAML file.
Instance Method Summary collapse
-
#implementation(impl_name) ⇒ Hash?
Get an implementation by name.
-
#implementation_names ⇒ Array<Symbol>
Get all implementation names.
-
#initialize(name:, interface:, implementations:, interface_version: '1.0') ⇒ ImplementationIndex
constructor
A new instance of ImplementationIndex.
-
#inspect ⇒ String
Inspect representation.
-
#to_s ⇒ String
String representation.
Constructor Details
#initialize(name:, interface:, implementations:, interface_version: '1.0') ⇒ ImplementationIndex
Returns a new instance of ImplementationIndex.
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
#implementations ⇒ Array<Hash>
Implementation definitions
33 34 35 |
# File 'lib/ukiryu/models/implementation_index.rb', line 33 def implementations @implementations end |
#interface ⇒ Symbol
Interface this tool implements
33 34 35 |
# File 'lib/ukiryu/models/implementation_index.rb', line 33 def interface @interface end |
#interface_version ⇒ String
Interface version
33 34 35 |
# File 'lib/ukiryu/models/implementation_index.rb', line 33 def interface_version @interface_version end |
#name ⇒ Symbol
Tool identifier
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
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
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
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_names ⇒ Array<Symbol>
Get all implementation names
59 60 61 |
# File 'lib/ukiryu/models/implementation_index.rb', line 59 def implementation_names @implementations.map { |impl| impl[:name] } end |
#inspect ⇒ String
Inspect representation
97 98 99 |
# File 'lib/ukiryu/models/implementation_index.rb', line 97 def inspect "#<Ukiryu::Models::ImplementationIndex #{self} implementations=#{@implementations.length}>" end |
#to_s ⇒ String
String representation
90 91 92 |
# File 'lib/ukiryu/models/implementation_index.rb', line 90 def to_s "#{@name} (implements #{@interface}/#{@interface_version})" end |