Module: Ext::Forward
- Extended by:
- Equipment
- Defined in:
- lib/ext/forward.rb
Overview
Forwarding is like redirecting but internally. This won’t send another request to the browser. See Base#forward for options.
HINT : forwarding should be used rarely in apps. Use redirect on POST.
Added features
If $DBG is enabled :
-
Print errors in the console
-
Show the requested URI with the dispatched controller.
Workflows
these are simplified workflows that illustrate the difference between redirecting and forwarding.
Workflow with redirect
Http client -> YourApp::Controller1 -> Http client -> YourApp::Controller2 -> Http client
Workflow with forwarding
Http client -> YourApp::Controller1 -> YourApp::Controller2 -> Http client
Dependency
-
Equipment
TODO
-
Limit forwarding to X requests
Defined Under Namespace
Modules: Base Classes: Forwarder
Constant Summary
Constants included from Equipment
Equipment::DATA_PATH, Equipment::LIB_PATH
Instance Attribute Summary
Attributes included from Equipment
Class Method Summary collapse
-
.equip(app) ⇒ Object
:nodoc:.
Methods included from Equipment
dependencies, depends_on, equip, equip_all, global_extensions, included
Class Method Details
.equip(app) ⇒ Object
:nodoc:
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/ext/forward.rb', line 42 def self.equip(app) # :nodoc: super app.module_eval do def self.run(r=$stdin,e=ENV) puts "REQUEST: `#{e['REQUEST_URI']}`" if $DBG self::Controllers.M k, a = self::Controllers.D un("/#{e['PATH_INFO']}".gsub(%r!/+!,'/')) begin puts " --> #{k}" if $DBG k.new(r,e,(m=m||e['REQUEST_METHOD']||'GET')).Y.service(*a) rescue Forwarder => fw k, m, a = fw.controller, fw.method, fw.args if /NotFound$/ =~ k.name # facility for NotFound controller a = [e['PATH_INFO']] if a.empty? or not a.first m = 'get' end retry rescue => x STDERR.puts x.inspect if $DBG STDERR.puts x.backtrace.join("\n") if $DBG k, a, m = self::Controllers::ServerError, [k,m,x], 'GET' k.new(r,e,m).service(*a) end end end end |