Module: RailsAuditLog
- Defined in:
- lib/rails_audit_log.rb,
lib/rails_audit_log/engine.rb,
lib/rails_audit_log/version.rb,
app/concerns/rails_audit_log/auditable.rb,
app/concerns/rails_audit_log/controller.rb,
app/jobs/rails_audit_log/application_job.rb,
app/models/rails_audit_log/audit_log_entry.rb,
app/models/rails_audit_log/application_record.rb,
app/helpers/rails_audit_log/application_helper.rb,
app/controllers/rails_audit_log/application_controller.rb,
lib/generators/rails_audit_log/install/install_generator.rb
Defined Under Namespace
Modules: ApplicationHelper, Auditable, Controller, Generators
Classes: ApplicationController, ApplicationJob, ApplicationRecord, AuditLogEntry, Engine
Constant Summary
collapse
- VERSION =
"0.5.0"
Class Method Summary
collapse
Class Method Details
.actor ⇒ Object
22
23
24
|
# File 'lib/rails_audit_log.rb', line 22
def self.actor
Thread.current[:rails_audit_log_actor]
end
|
.actor=(actor) ⇒ Object
26
27
28
|
# File 'lib/rails_audit_log.rb', line 26
def self.actor=(actor)
Thread.current[:rails_audit_log_actor] = actor
end
|
.audit_log_reason(value) ⇒ Object
58
59
60
61
62
63
64
|
# File 'lib/rails_audit_log.rb', line 58
def self.audit_log_reason(value)
previous = self.reason
self.reason = value
yield
ensure
self.reason = previous
end
|
.disable ⇒ Object
42
43
44
45
46
47
48
|
# File 'lib/rails_audit_log.rb', line 42
def self.disable
previous = Thread.current[:rails_audit_log_disabled]
Thread.current[:rails_audit_log_disabled] = true
yield
ensure
Thread.current[:rails_audit_log_disabled] = previous
end
|
.enabled? ⇒ Boolean
38
39
40
|
# File 'lib/rails_audit_log.rb', line 38
def self.enabled?
!Thread.current[:rails_audit_log_disabled]
end
|
.reason ⇒ Object
50
51
52
|
# File 'lib/rails_audit_log.rb', line 50
def self.reason
Thread.current[:rails_audit_log_reason]
end
|
.reason=(value) ⇒ Object
54
55
56
|
# File 'lib/rails_audit_log.rb', line 54
def self.reason=(value)
Thread.current[:rails_audit_log_reason] = value
end
|
14
15
16
|
# File 'lib/rails_audit_log.rb', line 14
def self.request_metadata
Thread.current[:rails_audit_log_request_metadata]
end
|
18
19
20
|
# File 'lib/rails_audit_log.rb', line 18
def self.request_metadata=(value)
Thread.current[:rails_audit_log_request_metadata] = value
end
|
.version_at(record, time) ⇒ Object
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
# File 'lib/rails_audit_log.rb', line 66
def self.version_at(record, time)
entry = AuditLogEntry
.where(item_type: record.class.name, item_id: record.id)
.where(created_at: ..time)
.order(created_at: :desc, id: :desc)
.first
return nil if entry.nil? || entry.event == "destroy"
klass = record.class
to_attrs = (entry.object_changes || {}).transform_values { |v| v[1] }
attrs = entry.object.present? ? entry.object.merge(to_attrs) : to_attrs
instance = klass.new
instance.assign_attributes(attrs.except("id"))
instance.id = attrs.fetch("id") { entry.item_id }
instance
end
|
.with_actor(actor) ⇒ Object
30
31
32
33
34
35
36
|
# File 'lib/rails_audit_log.rb', line 30
def self.with_actor(actor)
previous = self.actor
self.actor = actor
yield
ensure
self.actor = previous
end
|