Class: CallLogger::MethodWrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/call_logger/method_wrapper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(extended_class, owner_class) ⇒ MethodWrapper

Returns a new instance of MethodWrapper.



5
6
7
8
# File 'lib/call_logger/method_wrapper.rb', line 5

def initialize(extended_class, owner_class)
  @extended_class = extended_class
  @owner_class = owner_class
end

Instance Attribute Details

#extended_classObject (readonly)

Returns the value of attribute extended_class.



3
4
5
# File 'lib/call_logger/method_wrapper.rb', line 3

def extended_class
  @extended_class
end

#owner_classObject (readonly)

Returns the value of attribute owner_class.



3
4
5
# File 'lib/call_logger/method_wrapper.rb', line 3

def owner_class
  @owner_class
end

Instance Method Details

#wrap_multiple(methods) ⇒ Object



21
22
23
# File 'lib/call_logger/method_wrapper.rb', line 21

def wrap_multiple(methods)
  extended_class.prepend(build_module(methods))
end

#wrap_single(method) ⇒ Object



10
11
12
13
14
15
16
17
18
19
# 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