Module: Tick::ClassMethods

Defined in:
lib/tick.rb

Instance Method Summary collapse

Instance Method Details

#tick(method_name, options = {}) ⇒ Object



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/tick.rb', line 89

def tick(method_name, options = {})
  if Tick.enabled
    alias_method "#{method_name}_without_tick", method_name  
    define_method method_name do
      result = nil 
      if Tick.enabled #user may turn off tick at runtime
        sec = Benchmark.realtime  { result = self.send("#{method_name}_without_tick") } 
        desc = nil 
        if options[:message].kind_of?(Proc) 
          desc = options[:message].call(self.class.name, method_name)
        else
          desc = options[:message] || Tick.desc_message.call(self.class.name, method_name)
        end

        time = Tick.time_message.call(sec)
        _log_benchmark(desc, time)
      else  
        result = self.send("#{method_name}_without_tick")
      end
      
      result
    end
  end
end