Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Object
- def self.measure(method, category_name=nil)
- alias_method "#{method}_unmeasured", method
- define_method method do |*args|
- cat_name = if category_name.respond_to?(:call)
- # If proc eval in current context and pass args
- self.instance_exec args, &category_name
- elsif category_name && category_name.respond_to?(:to_s)
- # Stringify that thing you gave me
- category_name.to_s
- else
- # Try to be smart
- args.first.try(:to_s)
- end
- ActiveSupport::Notifications.instrument(
- "#{self.class.name}.#{method.to_s}",
- :name => cat_name
- ) do
- send "#{method}_unmeasured", *args
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement