Created
April 17, 2018 19:55
-
-
Save mbklein/7313d1212ab9f046c9d544aeec67728c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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