Class: Rambo::Server

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

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Server

Returns a new instance of Server.



16
17
18
# File 'lib/rambo/server.rb', line 16

def initialize(options = {})
  @options = options
end

Instance Method Details

#call(env) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/rambo/server.rb', line 20

def call(env)
  begin
    Rambo::Env.new
  
    request = Request.new(env)
    response = Response.new
  
    ctl_string = (request.controller.downcase.gsub(/^[a-z]|\s+[a-z]/) { |a| a.upcase } + 'Controller')
    begin
      obj = Object.module_eval("::#{ctl_string}", __FILE__, __LINE__).new
    rescue Exception => e
      return [404, response.header, "<h1>Controller #{ctl_string} Not Found</h1>"]
    end
    obj.request = request
    obj.response = response
    
    obj.init if obj.respond_to? :init 
    
    #begin
      result = obj.send(request.action) unless obj.rendered?
    #rescue Exception => e
      #return [404, response.header, "<h1>Action #{request.action} Not Found</h1>"]
    #end
    response.body = result if result
    
    [response.status, response.header, response.body]
  rescue Exception => e
    puts e.message
    return [500, response.header, "<pre><b>#{e.message.gsub("<","&lt;")}</b>\n#{e.backtrace.join("\n")}</pre>"]
  end
end