Class: VelocityAudited::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,
  origin: :origin,
  user_agent: :user_agent,
  uid: :uid,
  client: :client,
  request_id: :request_id
}

Instance Method Summary collapse

Instance Method Details

#around(controller) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/audited/sweeper.rb', line 18

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

#clientObject



51
52
53
# File 'lib/audited/sweeper.rb', line 51

def client
  controller.try(:request).try(:headers)['client']
end

#controllerObject



59
60
61
# File 'lib/audited/sweeper.rb', line 59

def controller
  store[:current_controller]
end

#controller=(value) ⇒ Object



63
64
65
# File 'lib/audited/sweeper.rb', line 63

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

#current_userObject



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

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

#originObject



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

def origin
  controller.try(:request).try(:headers)['Origin']
end

#remote_ipObject



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

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

#request_idObject



55
56
57
# File 'lib/audited/sweeper.rb', line 55

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

#request_uuidObject



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

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

#uidObject



47
48
49
# File 'lib/audited/sweeper.rb', line 47

def uid
  controller.try(:request).try(:headers)['uid']
end

#user_agentObject



43
44
45
# File 'lib/audited/sweeper.rb', line 43

def user_agent
  controller.try(:request).try(:headers)['User-Agent']
end