Sha256: 66678a36d8828900832d4c1b6c5c099d6b3548fa99aa13b1dabe87d859b3a732

Contents?: true

Size: 543 Bytes

Versions: 8

Compression:

Stored size: 543 Bytes

Contents

module Olivander
  class ApplicationRecord < ActiveRecord::Base
    self.abstract_class = true

    def self.audited_as klazz
      # Rails.logger.debug "#{self.class.name} is audited as #{klazz.name}"
      @@audited_user_class = klazz

      belongs_to :created_by, class_name: klazz.name
      belongs_to :updated_by, class_name: klazz.name

      before_validation :set_audit_user
    end

    def set_audit_user
      self.created_by ||= @@audited_user_class.current
      self.updated_by = @@audited_user_class.current
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
five-two-nw-olivander-0.2.0.1 app/models/olivander/application_record.rb
five-two-nw-olivander-0.2.0.0 app/models/olivander/application_record.rb
five-two-nw-olivander-0.1.2.60 app/models/olivander/application_record.rb
five-two-nw-olivander-0.1.2.59 app/models/olivander/application_record.rb
five-two-nw-olivander-0.1.2.58 app/models/olivander/application_record.rb
five-two-nw-olivander-0.1.2.57 app/models/olivander/application_record.rb
five-two-nw-olivander-0.1.2.56 app/models/olivander/application_record.rb
five-two-nw-olivander-0.1.2.55 app/models/olivander/application_record.rb