Module: Mongoid::AuditLog

Extended by:
ActiveSupport::Concern
Defined in:
lib/mongoid/audit_log.rb,
lib/mongoid/audit_log/entry.rb,
lib/mongoid/audit_log/config.rb,
lib/mongoid/audit_log/changes.rb,
lib/mongoid/audit_log/version.rb,
lib/mongoid/audit_log/embedded_changes.rb

Defined Under Namespace

Classes: Changes, EmbeddedChanges, Entry

Constant Summary collapse

VERSION =
"0.4.0"

Class Method Summary collapse

Class Method Details

.current_modifierObject


57
58
59
# File 'lib/mongoid/audit_log.rb', line 57

def self.current_modifier
  Thread.current[:mongoid_audit_log_modifier]
end

.current_modifier=(modifier) ⇒ Object


61
62
63
# File 'lib/mongoid/audit_log.rb', line 61

def self.current_modifier=(modifier)
  Thread.current[:mongoid_audit_log_modifier] = modifier
end

.disableObject


40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/mongoid/audit_log.rb', line 40

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

.enableObject


36
37
38
# File 'lib/mongoid/audit_log.rb', line 36

def self.enable
  Thread.current[:mongoid_audit_log_recording] = true
end

.record(modifier = nil) ⇒ Object


26
27
28
29
30
31
32
33
34
# File 'lib/mongoid/audit_log.rb', line 26

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?Boolean

Returns:

  • (Boolean)

53
54
55
# File 'lib/mongoid/audit_log.rb', line 53

def self.recording?
  !!Thread.current[:mongoid_audit_log_recording]
end