Class: Logisticed::Sweeper
- Inherits:
-
Object
- Object
- Logisticed::Sweeper
- Defined in:
- lib/logisticed/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
- #around(controller) ⇒ Object
- #controller ⇒ Object
- #controller=(value) ⇒ Object
- #current_user ⇒ Object
- #remote_ip ⇒ Object
- #request_uuid ⇒ Object
Instance Method Details
#around(controller) ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/logisticed/sweeper.rb', line 13 def around(controller) self.controller = controller # set store[:current_remote_address], store[:current_request_uuid], store[:current_user] STORED_DATA.each { |k, m| store[k] = send(m) } yield ensure self.controller = nil STORED_DATA.keys.each { |k| store.delete(k) } end |
#controller ⇒ Object
31 32 33 |
# File 'lib/logisticed/sweeper.rb', line 31 def controller store[:current_controller] end |
#controller=(value) ⇒ Object
35 36 37 |
# File 'lib/logisticed/sweeper.rb', line 35 def controller=(value) store[:current_controller] = value end |
#current_user ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/logisticed/sweeper.rb', line 23 def current_user lambda do if controller.respond_to?(Logisticed.current_user_method, true) controller.send(Logisticed.current_user_method) end end end |
#remote_ip ⇒ Object
39 40 41 |
# File 'lib/logisticed/sweeper.rb', line 39 def remote_ip controller.try(:request).try(:remote_ip) end |
#request_uuid ⇒ Object
43 44 45 |
# File 'lib/logisticed/sweeper.rb', line 43 def request_uuid controller.try(:request).try(:uuid) end |