module Decors::MethodAdded::Handler
Constants
- METHOD_CALLED_TOO_EARLY_HANDLER
Private Instance Methods
declared_decorators()
click to toggle source
# File lib/decors/method_added.rb, line 14 def declared_decorators @declared_decorators ||= [] end
handle_method_addition(clazz, method_name)
click to toggle source
method addition handling is the same for singleton and instance method
# File lib/decors/method_added.rb, line 19 def handle_method_addition(clazz, method_name) # @_ignore_additions allows to temporarily disable the hook return if @_ignore_additions || declared_decorators.empty? decorator_class, params, kparams, blk = declared_decorators.pop undecorated_method = clazz.instance_method(method_name) decorator = METHOD_CALLED_TOO_EARLY_HANDLER clazz.send(:define_method, method_name) do |*args, **kwargs, &block| decorator.call(self, *args, **kwargs, &block) end decorated_method = clazz.instance_method(method_name) @_ignore_additions = true decorator = decorator_class.new(clazz, undecorated_method, decorated_method, *params, **kparams, &blk) @_ignore_additions = false clazz.send(Decors::Utils.method_visibility(undecorated_method), method_name) end