Module: Ramaze::Helper::Fnordmetric::ClassMethods
- Defined in:
- lib/ramaze/helper/fnordmetric.rb
Overview
Holds class methods
This is used to extend the calling controller so these methods are available at the class level Since helpers are only included, extending the calling controller is done via the ‘included’ hook.
Instance Method Summary collapse
-
#clock(method, event_name, args = {}) ⇒ Object
This method replaces the original controller method with a times call that yields the original method.
Instance Method Details
#clock(method, event_name, args = {}) ⇒ Object
This method replaces the original controller method with a times call that yields the original method. This allows to measure execution time for the method without manually modifying the method itself
287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 |
# File 'lib/ramaze/helper/fnordmetric.rb', line 287 def clock(method, event_name, args = {}) # Let's alias the original controller method to original_name original = "__fnordmetric_%s" % method # We merge the method name in the args that will be sent in the event args.merge!(:method => "#{self.name}##{method}") self.class_eval do # Let's create a shiny new method replacing the old one alias_method original, method private original define_method(method) { |*a| times(event_name, args) do send(original, *a) end } end Ramaze::Log.debug("Clo(a)cking enabled for %s (renamed as %s)" % [ method, original ]) end |