module Mongoid::AuditLog
Constants
- VERSION
Public Class Methods
current_modifier()
click to toggle source
# File lib/mongoid/audit_log.rb, line 71 def self.current_modifier Thread.current[:mongoid_audit_log_modifier] end
current_modifier=(modifier)
click to toggle source
# File lib/mongoid/audit_log.rb, line 75 def self.current_modifier=(modifier) Thread.current[:mongoid_audit_log_modifier] = modifier end
disable() { || ... }
click to toggle source
# File lib/mongoid/audit_log.rb, line 54 def self.disable already_recording = recording? Thread.current[:mongoid_audit_log_recording] = false if block_given? begin yield ensure Thread.current[:mongoid_audit_log_recording] = already_recording end end end
enable()
click to toggle source
# File lib/mongoid/audit_log.rb, line 50 def self.enable Thread.current[:mongoid_audit_log_recording] = true end
record(modifier = nil) { || ... }
click to toggle source
# File lib/mongoid/audit_log.rb, line 40 def self.record(modifier = nil) already_recording = recording? enable unless already_recording self.current_modifier = modifier yield ensure disable unless already_recording self.current_modifier = nil end
recording?()
click to toggle source
# File lib/mongoid/audit_log.rb, line 67 def self.recording? !!Thread.current[:mongoid_audit_log_recording] end
Public Instance Methods
audit_log_enabled?()
click to toggle source
# File lib/mongoid/audit_log.rb, line 35 def audit_log_enabled? !defined?(@audit_log_enabled) || @audit_log_enabled end
disable_audit_log()
click to toggle source
# File lib/mongoid/audit_log.rb, line 31 def disable_audit_log @audit_log_enabled = false end
enable_audit_log()
click to toggle source
# File lib/mongoid/audit_log.rb, line 27 def enable_audit_log @audit_log_enabled = true end
record_audit_log?()
click to toggle source
# File lib/mongoid/audit_log.rb, line 79 def record_audit_log? AuditLog.recording? && self.class.audit_log_enabled? end
Private Instance Methods
save_audit_log_entry(action)
click to toggle source
# File lib/mongoid/audit_log.rb, line 89 def save_audit_log_entry(action) unless action == :update && @_audit_log_changes.all.blank? Entry.create!( :action => action, :audited_type => self.class, :audited_id => id, :tracked_changes => @_audit_log_changes.all, :model_attributes => attributes.deep_dup, :document_path => traverse_association_chain ) end end
set_audit_log_changes()
click to toggle source
# File lib/mongoid/audit_log.rb, line 85 def set_audit_log_changes @_audit_log_changes = Changes.new(self).tap(&:read) end
traverse_association_chain(node = self, current_relation = nil)
click to toggle source
# File lib/mongoid/audit_log.rb, line 102 def traverse_association_chain(node = self, current_relation = nil) relation = node.embedded? ? node.association_name.to_s : nil list = node._parent ? traverse_association_chain(node._parent, relation) : [] list << { class_name: node.class.name, id: node.id, relation: current_relation } list end