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



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

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



34
35
36
# File 'lib/audited/sweeper.rb', line 34

def controller
  store[:current_controller]
end

#controller=(value) ⇒ Object



38
39
40
# File 'lib/audited/sweeper.rb', line 38

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

#current_userObject



22
23
24
# File 'lib/audited/sweeper.rb', line 22

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

#remote_ipObject



26
27
28
# File 'lib/audited/sweeper.rb', line 26

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

#request_uuidObject



30
31
32
# File 'lib/audited/sweeper.rb', line 30

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