Class: Henko::LogManager

Inherits:
Object
  • Object
show all
Defined in:
lib/henko/log_manager.rb

Class Method Summary collapse

Class Method Details

.audit_model(options = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/henko/log_manager.rb', line 6

def self.audit_model(options = {})
  record = options[:record]
  action = options[:action]

  return unless record && options

  changes         = record.changes.dup
  current_user_id = Henko::LogManager.user_id

  audit_log            = Henko::AuditLog.new
  audit_log.class_name = record.class.name
  audit_log.user_id    = current_user_id if current_user_id
  audit_log.action     = options[:action]
  audit_log.action_url = Henko::LogManager.action_url if Henko::LogManager.action_url
  audit_log.user_ip    = Henko::LogManager.user_ip if Henko::LogManager.user_ip

  audit_log.model_changes  = changes.to_json
  audit_log.model_snapshot = record.to_json

  audit_log.save

  return true
end