Class: Webdrone::MethodLogger

Inherits:
Module
  • Object
show all
Defined in:
lib/webdrone/logg.rb

Class Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(methods = nil) ⇒ MethodLogger

Returns a new instance of MethodLogger.



9
10
11
# File 'lib/webdrone/logg.rb', line 9

def initialize(methods = nil)
  @methods = methods
end

Class Attribute Details

.last_timeObject

Returns the value of attribute last_time.



6
7
8
# File 'lib/webdrone/logg.rb', line 6

def last_time
  @last_time
end

.screenshotObject

Returns the value of attribute screenshot.



6
7
8
# File 'lib/webdrone/logg.rb', line 6

def screenshot
  @screenshot
end

Instance Method Details

#included(base) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/webdrone/logg.rb', line 13

def included(base)
  @methods ||= base.instance_methods(false)
  method_list = @methods
  base.class_eval do
    method_list.each do |method_name|
      original_method = instance_method(method_name)
      define_method method_name do |*args, &block|
        caller_location = Kernel.caller_locations[0]
        cl_path = caller_location.path
        cl_line = caller_location.lineno
        if @a0.conf.logger && Gem.path.none? { |path| cl_path.include? path }
          ini = ::Webdrone::MethodLogger.last_time ||= Time.new
          ::Webdrone::MethodLogger.screenshot = nil
          begin
            result = original_method.bind(self).call(*args, &block)
            fin = ::Webdrone::MethodLogger.last_time = Time.new
            @a0.logs.trace(ini, fin, cl_path, cl_line, base, method_name, args, result, nil, ::Webdrone::MethodLogger.screenshot)
            result
          rescue StandardError => exception
            fin = ::Webdrone::MethodLogger.last_time = Time.new
            @a0.logs.trace(ini, fin, cl_path, cl_line, base, method_name, args, nil, exception, ::Webdrone::MethodLogger.screenshot)
            raise exception
          end
        else
          original_method.bind(self).call(*args, &block)
        end
      end
    end
  end
end