Class: Seatbelt::Terminal

Inherits:
Object
  • Object
show all
Defined in:
lib/seatbelt/core/terminal.rb

Overview

Public: Interface between API class and Implementation class. Calls the implementation of an API method with passed arguments and block.

Class Method Summary collapse

Class Method Details

.call(action, klass, arity, *args, &block) ⇒ Object

Public: calls the implementation of an API method with passed arguments and block. Before sending the method message to the receiver, it defines the receivers proxy scope depending on klass (see below).

action - The API method name to be called klass - The API class name on which the API method is declared arity - Number of required arguments *args - An argument list passed to the implementation method &block - An optional block passed to the implementation method.

Returns the return value of the implementation method.



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/seatbelt/core/terminal.rb', line 38

def self.call(action, klass, arity, *args, &block)
  raise Seatbelt::Errors::MethodNotImplementedError if luggage.empty?
  scope               = klass.class.eql?(Class) ? :class : :instance
  klass_namespace     = scope.eql?(:class) ? klass.name : klass.class.name

  eigenmethod = klass.eigenmethods.detect do |meth|
    meth.implemented_as.eql?(action)
  end

  unless eigenmethod
    raise Seatbelt::Errors::MethodNotImplementedError
  end

  if (not eigenmethod.delegated) && (not eigenmethod.arity.eql?(arity))
    raise Seatbelt::Errors::ArgumentMissmatchError
  end

  eigenmethod.call(*args, &block)
end

.for_scope_and_namespace(scope, namespace) ⇒ Object



19
20
21
22
23
# File 'lib/seatbelt/core/terminal.rb', line 19

def self.for_scope_and_namespace(scope, namespace)
  Terminal.luggage.select do |package|
    package.scope_level.eql?(scope) && package.namespace.eql?(namespace)
  end
end

.luggageObject

Public: The implementation methods config store.

Returns implementation methods config store.



15
16
17
# File 'lib/seatbelt/core/terminal.rb', line 15

def self.luggage
  @luggage ||= []
end

.luggage=(luggage_pack) ⇒ Object

The implementation methods config store.



8
9
10
# File 'lib/seatbelt/core/terminal.rb', line 8

def self.luggage=(luggage_pack)
  @luggage = luggage_pack
end