Module: ActionInterceptor::View
- Defined in:
- lib/action_interceptor/view.rb
Instance Method Summary collapse
-
#url_for(options = {}) ⇒ Object
Can’t reuse url_for from controller because the view’s super method is different.
-
#with_interceptor(&block) ⇒ Object
Executes the given block as if it was inside an interceptor.
-
#without_interceptor(&block) ⇒ Object
Executes the given block as if it was not inside an interceptor.
Instance Method Details
#url_for(options = {}) ⇒ Object
Can’t reuse url_for from controller because the view’s super method is different
6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/action_interceptor/view.rb', line 6 def url_for( = {}) url = super return url unless controller.use_interceptor @intercepted_url_hash ||= controller.is_interceptor ? \ intercepted_url_hash : current_url_hash uri = URI(url) new_query = URI.decode_www_form(uri.query || '') + \ @intercepted_url_hash.to_a uri.query = URI.encode_www_form(new_query) uri.to_s end |
#with_interceptor(&block) ⇒ Object
Executes the given block as if it was inside an interceptor
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/action_interceptor/view.rb', line 21 def with_interceptor(&block) previous_use_interceptor = controller.use_interceptor begin # Send the referer with intercepted requests # So we don't rely on the user's browser to do it for us controller.use_interceptor = true # Execute the block as if it was defined in this controller instance_exec &block rescue LocalJumpError => e # Silently ignore `return` errors in the block # and return the given value e.exit_value ensure controller.use_interceptor = previous_use_interceptor end end |
#without_interceptor(&block) ⇒ Object
Executes the given block as if it was not inside an interceptor
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/action_interceptor/view.rb', line 41 def without_interceptor(&block) previous_use_interceptor = controller.use_interceptor begin # Send the referer with intercepted requests # So we don't rely on the user's browser to do it for us controller.use_interceptor = false # Execute the block as if it was defined in this controller instance_exec &block rescue LocalJumpError => e # Silently ignore `return` errors in the block # and return the given value e.exit_value ensure controller.use_interceptor = previous_use_interceptor end end |