Sha256: e022ac4e0eab8b4dda6d8676bbe2db66d89747904df1ee582176dc7b16b5b34a
Contents?: true
Size: 890 Bytes
Versions: 1
Compression:
Stored size: 890 Bytes
Contents
module Samsara::Model extend ActiveSupport::Concern included do def self.is_audited? @is_audited || false end def self.is_audited @is_audited = true has_many :auditing_revisions, class_name: Samsara.revision_class_name, as: :subject after_create :audit_create after_update :audit_update, if: :changed? after_destroy :audit_destroy, if: :destroyed? end end def audit_create create_audit :create end def audit_update create_audit :update end def audit_destroy create_audit :destroy end def create_audit(action) return unless Samsara.active? Samsara.revision_class.new do |a| a.action = action a.subject = self a.context = Samsara.current_context a.modified_attributes = self.attributes a.original_attributes = self.changed_attributes end.save end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
samsara-0.0.2 | lib/samsara/model.rb |