Sha256: 04d08168583365e69c65fec3318ef3b9fe8a31e5fb016b6fe3faa09d265f3bca

Contents?: true

Size: 1.04 KB

Versions: 19

Compression:

Stored size: 1.04 KB

Contents

require 'active_support/notifications'

module Neo4j
  module Core
    module Instrumentable
      def self.included(base)
        base.send :include, InstanceMethods
        base.extend ClassMethods
      end

      module InstanceMethods
      end

      module ClassMethods
        def instrument(name, label, arguments, &block)
          # defining class methods
          klass = class << self; self; end
          klass.instance_eval do
            define_method("subscribe_to_#{name}") do |&b|
              ActiveSupport::Notifications.subscribe(label) do |a, start, finish, id, payload|
                b.call block.call(a, start, finish, id, payload)
              end
            end

            define_method("instrument_#{name}") do |*args, &b|
              hash = arguments.each_with_index.each_with_object({}) do |(argument, i), result|
                result[argument.to_sym] = args[i]
              end
              ActiveSupport::Notifications.instrument(label, hash) { b.call }
            end
          end
        end
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
neo4j-core-6.1.6 lib/neo4j/core/instrumentable.rb
neo4j-core-6.1.5 lib/neo4j/core/instrumentable.rb
neo4j-core-6.1.4 lib/neo4j/core/instrumentable.rb
neo4j-core-6.1.3 lib/neo4j/core/instrumentable.rb
neo4j-core-6.1.2 lib/neo4j/core/instrumentable.rb
neo4j-core-6.1.1 lib/neo4j/core/instrumentable.rb
neo4j-core-6.0.6 lib/neo4j/core/instrumentable.rb
neo4j-core-6.0.5 lib/neo4j/core/instrumentable.rb
neo4j-core-6.1.0 lib/neo4j/core/instrumentable.rb
neo4j-core-6.0.4 lib/neo4j/core/instrumentable.rb
neo4j-core-6.0.3 lib/neo4j/core/instrumentable.rb
neo4j-core-6.0.2 lib/neo4j/core/instrumentable.rb
neo4j-core-6.0.1 lib/neo4j/core/instrumentable.rb
neo4j-core-6.0.0 lib/neo4j/core/instrumentable.rb
neo4j-core-6.0.0.rc.1 lib/neo4j/core/instrumentable.rb
neo4j-core-6.0.0.alpha.6 lib/neo4j/core/instrumentable.rb
neo4j-core-6.0.0.alpha.5 lib/neo4j/core/instrumentable.rb
neo4j-core-6.0.0.alpha.2 lib/neo4j/core/instrumentable.rb
neo4j-core-6.0.0.alpha.1 lib/neo4j/core/instrumentable.rb