Class: RHR::Server
- Inherits:
-
Object
- Object
- RHR::Server
- Defined in:
- lib/rhr/server.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize ⇒ Server
constructor
A new instance of Server.
Constructor Details
#initialize ⇒ Server
Returns a new instance of Server.
3 4 5 6 |
# File 'lib/rhr/server.rb', line 3 def initialize @files = Dir["**/*"] - ['Gemfile','Gemfile.lock','Rakefile'] @files -= @files.grep(/(^|\/)_/) end |
Instance Method Details
#call(env) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/rhr/server.rb', line 8 def call(env) path = env['PATH_INFO'] if template = find_template(path) if renderer = Tilt[template] request = Rack::Request.new(env) params = request.GET.merge(request.POST) body = renderer.new(template).render(nil, :request => request, :params => params) [200, {}, [body]] else Rack::File.new('.').call(env.merge('PATH_INFO' => template)) end else [404, {}, ['404 File not found']] end end |