Skip to content

Instantly share code, notes, and snippets.

@mbklein
Created April 17, 2018 19:55
Show Gist options
  • Save mbklein/7313d1212ab9f046c9d544aeec67728c to your computer and use it in GitHub Desktop.
Save mbklein/7313d1212ab9f046c9d544aeec67728c to your computer and use it in GitHub Desktop.
require 'active_fedora/base'
require 'singleton'
class CallCounter
include Singleton
attr_reader :result
def initialize
@result = {}
@mutex = Mutex.new
end
def count(klass, id, method)
@mutex.synchronize do
@result[method] ||= {}
@result[method][klass] ||= {}
@result[method][klass][id] ||= 0
@result[method][klass][id] += 1
end
end
end
module ActiveFedora
class Base
[:update_index, :save, :save!, :update, :update!, :delete].each do |method|
alias_method "_#{method}".to_sym, method
define_method method do |*args|
self.send("_#{method}".to_sym, *args).tap do
CallCounter.instance.count(self.class.name, self.id, method)
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment