Class: Audited::Sweeper

Inherits:
Object
  • Object
show all
Defined in:
lib/audited/sweeper.rb

Constant Summary collapse

STORED_DATA =
{
  current_remote_address: :remote_ip,
  current_request_uuid: :request_uuid,
  current_user: :current_user
}

Instance Method Summary collapse

Instance Method Details

#around(controller) ⇒ Object


11
12
13
14
15
16
17
18
# File 'lib/audited/sweeper.rb', line 11

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

#controllerObject


32
33
34
# File 'lib/audited/sweeper.rb', line 32

def controller
  store[:current_controller]
end

#controller=(value) ⇒ Object


36
37
38
# File 'lib/audited/sweeper.rb', line 36

def controller=(value)
  store[:current_controller] = value
end

#current_userObject


20
21
22
# File 'lib/audited/sweeper.rb', line 20

def current_user
  lambda { controller.send(Audited.current_user_method) if controller.respond_to?(Audited.current_user_method, true) }
end

#remote_ipObject


24
25
26
# File 'lib/audited/sweeper.rb', line 24

def remote_ip
  controller.try(:request).try(:remote_ip)
end

#request_uuidObject


28
29
30
# File 'lib/audited/sweeper.rb', line 28

def request_uuid
  controller.try(:request).try(:uuid)
end