summaryrefslogtreecommitdiff
path: root/app/models/audit_event.rb
blob: 0ed0dd98a5950437930ea3f5c64fd2079b615cb4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# == Schema Information
#
# Table name: audit_events
#
#  id          :integer          not null, primary key
#  author_id   :integer          not null
#  type        :string(255)      not null
#  entity_id   :integer          not null
#  entity_type :string(255)      not null
#  details     :text
#  created_at  :datetime
#  updated_at  :datetime
#

class AuditEvent < ActiveRecord::Base
  serialize :details, Hash

  belongs_to :user, foreign_key: :author_id

  validates :author_id, presence: true
  validates :entity_id, presence: true
  validates :entity_type, presence: true

  after_initialize :initialize_details

  def initialize_details
    self.details = {} if details.nil?
  end

  def author_name
    self.user.name
  end
end