lib/symbiont/public_trigger.rb in symbiont-ruby-0.4.0 vs lib/symbiont/public_trigger.rb in symbiont-ruby-0.5.0
- old
+ new
@@ -24,10 +24,49 @@
#
# @api private
# @since 0.1.0
def __actual_context__(method_name)
__directed_contexts__.find do |context|
- context.respond_to?(method_name, false)
+ begin
+ context.respond_to?(method_name, false)
+ rescue ::NoMethodError
+ # NOTE:
+ # this situation is caused when the context object does not respodond to
+ # #resond_to? method (BasicObject instances for example)
+
+ context_singleton = __extract_singleton_object__(context)
+
+ context_singleton.public_methods(false).include?(method_name) ||
+ context_singleton.superclass.public_instance_methods(false).include?(method_name)
+ end
end || super
+ end
+
+ # Returns a corresponding public method object of the actual context.
+ #
+ # @param method_name [String,Symbol] Method name
+ # @return [Method]
+ #
+ # @see [Symbiont::Trigger#method]
+ #
+ # @api private
+ # @since 0.5.0
+ def method(method_name)
+ __context__ = __actual_context__(method_name)
+
+ # NOTE:
+ # block is used cuz #__actual_context__can raise
+ # ::NoMethodError (ContextNoMethodError) too (and we should raise it)
+ begin
+ __context__.method(method_name)
+ rescue ::NoMethodError
+ # NOTE:
+ # this situation is caused when the context object does not respond
+ # to #method method (BasicObject instances for example). We can extract
+ # method objects via it's singleton class.
+
+ __context_singleton__ = __extract_singleton_object__(__context__)
+ __context_singleton__.superclass.public_instance_method(method_name).bind(__context__)
+ end
end
end
end