class CallLogger::MethodWrapper
Attributes
extended_class[R]
owner_class[R]
Public Class Methods
new(extended_class, owner_class)
click to toggle source
# File lib/call_logger/method_wrapper.rb, line 5 def initialize(extended_class, owner_class) @extended_class = extended_class @owner_class = owner_class end
Public Instance Methods
wrap_multiple(methods)
click to toggle source
# File lib/call_logger/method_wrapper.rb, line 21 def wrap_multiple(methods) extended_class.prepend(build_module(methods)) end
wrap_single(method)
click to toggle source
# File lib/call_logger/method_wrapper.rb, line 10 def wrap_single(method) owner = @owner_class sep = separator extended_class.alias_method "#{method}_without_log", method extended_class.define_method method do |*args| owner.do_log("#{owner}#{sep}#{method}", args) do send("#{method}_without_log", *args) end end end
Private Instance Methods
build_module(methods)
click to toggle source
Calls superclass method
# File lib/call_logger/method_wrapper.rb, line 35 def build_module(methods) owner = @owner_class sep = separator Module.new do methods.each do |method| define_method method do |*args| owner.do_log("#{owner}#{sep}#{method}", args) do super(*args) end end end end end
separator()
click to toggle source
# File lib/call_logger/method_wrapper.rb, line 27 def separator if extended_class.singleton_class? '.' else '#' end end