class Seatbelt::Eigenmethod

Public: A configuration class that contains the implementation method directives and attributes.

Attributes

arity[RW]
delegated[RW]
implemented_as[RW]
method[RW]
method_implementation_type[RW]
namespace[RW]
receiver[W]
scope[RW]
scope=[RW]
scope_level[RW]

Public Instance Methods

[](attr) click to toggle source
# File lib/seatbelt/core/eigenmethod.rb, line 68
def [](attr)
  self.send(attr)
end
call(*args, &block) click to toggle source

Public: Calls the implementation method of an API method call.

*args - argument list for the implementation method. &block - A block if needed.

Returns the evaluated value.

# File lib/seatbelt/core/eigenmethod.rb, line 63
def call(*args, &block)
  return __send_class_level(*args, &block) if class_level?
  return __send_instance_level(*args, &block) if instance_level?
end
class_level?() click to toggle source

Implementation type at remote class (API class) side.

Returns true if a class method is implemented, otherwise false.

# File lib/seatbelt/core/eigenmethod.rb, line 38
def class_level?
  not self.instance_level?
end
class_method_implementation?() click to toggle source

Implementation type at the implementation class side.

Returns true if a class method is implemented, otherwise false.

# File lib/seatbelt/core/eigenmethod.rb, line 45
def class_method_implementation?
  self.method_implementation_type.eql?(:class)
end
init_klass_on_receiver(klass_object) click to toggle source

Creates the corrosponding class on the receiver and defines the proxy tunnel on the receivers proxy object.

klass_object - The API Class or an instance of the API class.

# File lib/seatbelt/core/eigenmethod.rb, line 82
def init_klass_on_receiver(klass_object)
  if instance_level?
  __generate_proxy_object(@callee, klass_object)
  end
  if class_level?
    if class_method_implementation?
       __generate_proxy_object(receiver, klass_object)
    else
      if method_implementation_type.eql?(:instance)
        @callee = callee.new if @callee.respond_to?(:new)
        @callee.instance_variable_set(:@proxy,Seatbelt::Proxy.new)
        __generate_proxy_object(callee, klass_object)
      end
    end
  end
end
instance_level?() click to toggle source

Implementation type at remote class (API class) side.

Returns true if an instance method is implemented, otherwise false.

# File lib/seatbelt/core/eigenmethod.rb, line 31
def instance_level?
  self.scope_level.eql?(:instance)
end
instance_method_implementation?() click to toggle source

Implementation type at the implementation class side.

Returns true if an instance method is implemented, otherwise false.

# File lib/seatbelt/core/eigenmethod.rb, line 52
def instance_method_implementation?
  not class_method_implementation?
end
receiver() click to toggle source

Public: The receiver of the implementation method. This is always an instance whether it defines a class method or instance method implementation.

Returns receivers instance.

# File lib/seatbelt/core/eigenmethod.rb, line 23
def receiver
  @receiver
end

Private Instance Methods

__generate_proxy_object(receiver_, klass_object) click to toggle source
# File lib/seatbelt/core/eigenmethod.rb, line 104
def __generate_proxy_object(receiver_, klass_object)
  runner = lambda do |receiver_scope|
    receiver_scope.send(:proxy_object).instance_variable_set(:@klass, klass_object)
    receiver_scope.send(:proxy_object).class_eval code
    receiver_scope.class.send(:define_method, :proxy) do
      return self.proxy_object
    end
    #p receiver_scope.send(:proxy_object)
    return receiver_scope
  end
  runner.call(receiver_)
end
__send_class_level(*args, &block) click to toggle source
# File lib/seatbelt/core/eigenmethod.rb, line 126
def __send_class_level(*args, &block)
  if class_method_implementation?
    object = receiver
  else
    object = callee
  end
  object.send(@method, *args, &block)
end
__send_instance_level(*args, &block) click to toggle source
# File lib/seatbelt/core/eigenmethod.rb, line 135
def __send_instance_level(*args, &block)
  if method.respond_to?(:bind)
    value = method.bind(callee).call(*args, &block)
  else
    value = callee.send(method, *args, &block)
  end
end
callee() click to toggle source

Accessor of the api method implementation call object.

# File lib/seatbelt/core/eigenmethod.rb, line 100
def callee
  @callee
end
code() click to toggle source
# File lib/seatbelt/core/eigenmethod.rb, line 117
    def code
      <<-RUBY
        def klass
          return instance_variable_get(:@klass)
        end
        private :klass
      RUBY
    end