Sha256: 7a2f12cd8160d3023c46550da77dbe119062e2c4cbbd49083ab2e43fd3272c48
Contents?: true
Size: 1.4 KB
Versions: 16
Compression:
Stored size: 1.4 KB
Contents
# frozen_string_literal: true 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") if respond_to?(:before_create) before_create do Sapience.metrics.increment(self.class.const_get(:SAPIENCE_MODEL_CREATE_METRICS_KEY)) end end if respond_to?(:before_update) before_update do Sapience.metrics.increment(self.class.const_get(:SAPIENCE_MODEL_UPDATE_METRICS_KEY)) end end if respond_to?(:before_destroy) before_destroy do Sapience.metrics.increment(self.class.const_get(:SAPIENCE_MODEL_DESTROY_METRICS_KEY)) end end end end module ClassMethods def tableized_name @tableized_name ||= name.tableize.singularize.tr("/", ".") end end def tableized_name self.class.tableized_name end end end end end
Version data entries
16 entries across 16 versions & 1 rubygems