module Neo4j::Core::Instrumentable::ClassMethods
Public Instance Methods
instrument(name, label, arguments) { |a, start, finish, id, payload| ... }
click to toggle source
# File lib/neo4j/core/instrumentable.rb 15 def instrument(name, label, arguments) 16 # defining class methods 17 klass = class << self; self; end 18 klass.instance_eval do 19 define_method("subscribe_to_#{name}") do |&b| 20 ActiveSupport::Notifications.subscribe(label) do |a, start, finish, id, payload| 21 b.call yield(a, start, finish, id, payload) 22 end 23 end 24 25 define_method("instrument_#{name}") do |*args, &b| 26 hash = arguments.each_with_index.each_with_object({}) do |(argument, i), result| 27 result[argument.to_sym] = args[i] 28 end 29 ActiveSupport::Notifications.instrument(label, hash) { b.call } 30 end 31 end 32 end