Module: Overnight::MethodTimer

Defined in:
lib/overnight/mixins/method_timer.rb

Class Method Summary collapse

Class Method Details

.included(base_class) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/overnight/mixins/method_timer.rb', line 4

def self.included(base_class)
  methods = base_class.instance_methods(false) + base_class.private_instance_methods(false)
  base_class.class_eval do
    methods.each do |method_name|
      old_method = instance_method(method_name)
      define_method(method_name) do |*args, &block|
        logged_name = Overnight::MethodTimer.timer_name(base_class.name + "_" + method_name.to_s)
        OvernightService.start_timer(logged_name)
        result = old_method.bind(self).call(*args, &block)
        OvernightService.stop_timer(logged_name)
        return result
      end
    end
  end
end

.timer_name(name) ⇒ Object



20
21
22
# File 'lib/overnight/mixins/method_timer.rb', line 20

def self.timer_name(name)
  name.scan(/[A-Z][a-z_]*/).join("_").downcase.to_sym
end