Sha256: 9ade3ead4b4a4dfc0e9470771ac4b8426945086e526530a14817d239c0aa6925
Contents?: true
Size: 1.28 KB
Versions: 12
Compression:
Stored size: 1.28 KB
Contents
module Sapience module Extensions module ActiveRecord module ModelMetrics def self.included(base) # rubocop:disable AbcSize base.extend(ClassMethods) base.class_eval do const_set(:SAPIENCE_MODEL_CREATE_METRICS_KEY, "model.#{tableized_name}.create") const_set(:SAPIENCE_MODEL_UPDATE_METRICS_KEY, "model.#{tableized_name}.update") const_set(:SAPIENCE_MODEL_DESTROY_METRICS_KEY, "model.#{tableized_name}.destroy") before_create do Sapience.metrics.increment(self.class.const_get(:SAPIENCE_MODEL_CREATE_METRICS_KEY)) end if respond_to?(:before_create) before_update do Sapience.metrics.increment(self.class.const_get(:SAPIENCE_MODEL_UPDATE_METRICS_KEY)) end if respond_to?(:before_update) before_destroy do Sapience.metrics.increment(self.class.const_get(:SAPIENCE_MODEL_DESTROY_METRICS_KEY)) end if respond_to?(:before_destroy) end end module ClassMethods def tableized_name @tableized_name ||= name.tableize.singularize.gsub("/", ".") end end def tableized_name self.class.tableized_name end end end end end
Version data entries
12 entries across 12 versions & 1 rubygems