Class: Rack::Doco
- Inherits:
-
Object
- Object
- Rack::Doco
- Defined in:
- lib/doco.rb
Constant Summary collapse
- F =
::File
Instance Method Summary collapse
- #_call(env) ⇒ Object
- #call(env) ⇒ Object
-
#initialize(app, options = {}) ⇒ Doco
constructor
A new instance of Doco.
Constructor Details
#initialize(app, options = {}) ⇒ Doco
Returns a new instance of Doco.
11 12 13 14 15 |
# File 'lib/doco.rb', line 11 def initialize(app, ={}) @app = app @url = ([:url] || "/").chomp("/") @root = [:root] || Dir.pwd end |
Instance Method Details
#_call(env) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/doco.rb', line 23 def _call(env) path = Utils.unescape(F.(env['PATH_INFO'])) result = if path.index(@url) == 0 && env["REQUEST_METHOD"] == "GET" route = path[@url.length..-1].split('/').reject {|i| i.empty? } route << "index" if route.empty? handle(route) end result.first == 404 ? @app.call(env) : result end |
#call(env) ⇒ Object
17 18 19 |
# File 'lib/doco.rb', line 17 def call(env) dup._call(env) end |