Class: Vizsla::Patches
- Inherits:
-
Object
- Object
- Vizsla::Patches
- Includes:
- Helpers
- Defined in:
- lib/vizsla/patches.rb
Class Method Summary collapse
Methods included from Helpers
Class Method Details
.handle_event(handler_name, event_data) ⇒ Object
37 38 39 40 |
# File 'lib/vizsla/patches.rb', line 37 def handle_event(handler_name, event_data) handler = self.get_instance_variable "@#{handler_name}_event_handler" hanlder.call event_data unless hanlder.nil? end |
.patch_postgres(&block) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/vizsla/patches.rb', line 8 def patch_postgres(&block) @postgres_event_handler = block ::PG::Connection.class_eval do alias_method :exec_without_profiling, :exec def exec(*args, &blk) return exec_without_profiling(*args, &blk) start_time = Time.now result = exec_without_profiling(*args, &blk) end_time = Time.now event_data = [ 'sql.postgres_exec', start_time, end_time, { sql: args[0] } ] ::Vizsla::Patches.handle_event :postgres, event_data result end end end |