class Seatbelt::Eigenmethod
Public: A configuration class that contains the implementation method directives and attributes.
Attributes
Public Instance Methods
# File lib/seatbelt/core/eigenmethod.rb, line 68 def [](attr) self.send(attr) end
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
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
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
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
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
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
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
# 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
# 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
# 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
Accessor of the api method implementation call object.
# File lib/seatbelt/core/eigenmethod.rb, line 100 def callee @callee end
# File lib/seatbelt/core/eigenmethod.rb, line 117 def code <<-RUBY def klass return instance_variable_get(:@klass) end private :klass RUBY end