Class: Rack::Doco

Inherits:
Object
  • Object
show all
Defined in:
lib/doco.rb

Constant Summary collapse

F =
::File

Instance Method Summary collapse

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, options={})
  @app = app
  @url = (options[:url] || "/").chomp("/")
  @root = options[: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.expand_path(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