Class: Rack::Recursive
- Inherits:
-
Object
- Object
- Rack::Recursive
- Defined in:
- lib/rack/recursive.rb
Overview
Rack::Recursive allows applications called down the chain to include data from other applications (by using rack['rack.recursive.include'][...]
or raise a ForwardRequest to redirect internally.
Instance Method Summary collapse
- #_call(env) ⇒ Object
- #call(env) ⇒ Object
- #include(env, path) ⇒ Object
-
#initialize(app) ⇒ Recursive
constructor
A new instance of Recursive.
Constructor Details
#initialize(app) ⇒ Recursive
Returns a new instance of Recursive.
35 36 37 |
# File 'lib/rack/recursive.rb', line 35 def initialize(app) @app = app end |
Instance Method Details
#_call(env) ⇒ Object
43 44 45 46 47 48 |
# File 'lib/rack/recursive.rb', line 43 def _call(env) @script_name = env[SCRIPT_NAME] @app.call(env.merge(RACK_RECURSIVE_INCLUDE => method(:include))) rescue ForwardRequest => req call(env.merge(req.env)) end |
#call(env) ⇒ Object
39 40 41 |
# File 'lib/rack/recursive.rb', line 39 def call(env) dup._call(env) end |
#include(env, path) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/rack/recursive.rb', line 50 def include(env, path) unless path.index(@script_name) == 0 && (path[@script_name.size] == ?/ || path[@script_name.size].nil?) raise ArgumentError, "can only include below #{@script_name}, not #{path}" end env = env.merge(PATH_INFO => path, SCRIPT_NAME => @script_name, REQUEST_METHOD => GET, "CONTENT_LENGTH" => "0", "CONTENT_TYPE" => "", RACK_INPUT => StringIO.new("")) @app.call(env) end |