/
sweeper.rb
42 lines (34 loc) · 917 Bytes
/
sweeper.rb
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
34
35
36
37
38
39
40
41
42
# frozen_string_literal: true
module Audited
class Sweeper
STORED_DATA = {
current_remote_address: :remote_ip,
current_request_uuid: :request_uuid,
current_user: :current_user
}
delegate :store, to: ::Audited
def around(controller)
self.controller = controller
STORED_DATA.each { |k, m| store[k] = send(m) }
yield
ensure
self.controller = nil
STORED_DATA.keys.each { |k| store.delete(k) }
end
def current_user
lambda { controller.send(Audited.current_user_method) if controller.respond_to?(Audited.current_user_method, true) }
end
def remote_ip
controller.try(:request).try(:remote_ip)
end
def request_uuid
controller.try(:request).try(:uuid)
end
def controller
store[:current_controller]
end
def controller=(value)
store[:current_controller] = value
end
end
end