Class: Taksi::Interface

Inherits:
Module
  • Object
show all
Defined in:
lib/taksi/interface.rb

Overview

A custom module that turns a class into a interface on taksi protocol

Defined Under Namespace

Modules: ClassMethods, InstanceMethods

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, version_pattern = nil, alternatives: nil) ⇒ Interface

Returns a new instance of Interface.



19
20
21
22
23
24
# File 'lib/taksi/interface.rb', line 19

def initialize(name, version_pattern = nil, alternatives: nil)
  @interface_name = name
  @version_pattern = ::Gem::Requirement.new(version_pattern)
  @alternatives = alternatives
  super()
end

Instance Attribute Details

#alternativesObject (readonly)

Returns the value of attribute alternatives.



7
8
9
# File 'lib/taksi/interface.rb', line 7

def alternatives
  @alternatives
end

#interface_nameObject (readonly)

Returns the value of attribute interface_name.



7
8
9
# File 'lib/taksi/interface.rb', line 7

def interface_name
  @interface_name
end

#version_patternObject (readonly)

Returns the value of attribute version_pattern.



7
8
9
# File 'lib/taksi/interface.rb', line 7

def version_pattern
  @version_pattern
end

Class Method Details

.find(name, version, alternative: nil) ⇒ Object

Finds for a interface by its name and the current version @raises`::Taksi::Registry::InterfaceNotFoundError`

Parameters:

  • name (String)
  • version (String)

    just like ‘0.2.1’

  • alternatives: (Array)

Returns:

  • Class the class of interface



15
16
17
# File 'lib/taksi/interface.rb', line 15

def self.find(name, version, alternative: nil)
  ::Taksi::Registry.find(name, version, alternative)
end

Instance Method Details

#included(klass) ⇒ Object



26
27
28
29
30
31
32
33
# File 'lib/taksi/interface.rb', line 26

def included(klass)
  klass.extend(ClassMethods)
  klass.include(InstanceMethods)

  klass.initiate(self)

  ::Taksi::Registry.add(klass, interface_name)
end