module AroundMethod::Core
Public Instance Methods
apply_around_method(method_name, wrapper_method)
click to toggle source
# File lib/around_method/core.rb, line 8 def apply_around_method(method_name, wrapper_method) renamed_original_method = "#{method_name}_inner" alias_method(renamed_original_method, method_name) with_method_added_hook_disabled do define_method(method_name) do original_method_proc = method(renamed_original_method) method(wrapper_method).call(&original_method_proc) end end end
around_method(method_name, wrapper_method)
click to toggle source
# File lib/around_method/core.rb, line 3 def around_method(method_name, wrapper_method) apply_around_method(method_name, wrapper_method) if method_defined?(method_name) around_method_wrapped[method_name] = wrapper_method end
around_method_wrapped()
click to toggle source
# File lib/around_method/core.rb, line 26 def around_method_wrapped @around_method_wrapped ||= {} end
disable_method_added_hook?()
click to toggle source
# File lib/around_method/core.rb, line 30 def disable_method_added_hook? @disable_method_added_hook end
enable_method_added_hook?()
click to toggle source
# File lib/around_method/core.rb, line 34 def enable_method_added_hook? !disable_method_added_hook? end
method_added(method_name)
click to toggle source
Calls superclass method
# File lib/around_method/core.rb, line 19 def method_added(method_name) if around_method_wrapped.has_key?(method_name) && enable_method_added_hook? apply_around_method(method_name, around_method_wrapped[method_name]) end super end
with_method_added_hook_disabled() { || ... }
click to toggle source
Allow AroundMethod's method_added
hook to be temporarily disabled, otherwise application will trigger an infinite loop.
# File lib/around_method/core.rb, line 40 def with_method_added_hook_disabled @disable_method_added_hook = true yield @disable_method_added_hook = false end