123456789_123456789_123456789_123456789_123456789_

Class: Rack::Recursive

Relationships & Source Files
Inherits: Object
Defined in: lib/rack/recursive.rb

Overview

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.

Class Method Summary

Instance Method Summary

Constructor Details

.new(app) ⇒ Recursive

[ GitHub ]

  
# File 'lib/rack/recursive.rb', line 37

def initialize(app)
  @app = app
end

Instance Method Details

#_call(env)

[ GitHub ]

  
# File 'lib/rack/recursive.rb', line 45

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)

[ GitHub ]

  
# File 'lib/rack/recursive.rb', line 41

def call(env)
  dup._call(env)
end

#include(env, path)

[ GitHub ]

  
# File 'lib/rack/recursive.rb', line 52

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