Class: ObjectsFramework::ObjectHandler

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

Class Method Summary collapse

Class Method Details

.run_methods(request, response, context) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/objectsframework/object_handler.rb', line 3

def self.run_methods(request,response,context)
  path = request.path
  parts = path.split("/")
  if(path == "/" && !context.config[:root].nil?)
    klass = Object.const_get(context.config[:root]).new.set_instance_variables(request,response).send(request.request_method.downcase!+"_"+context.config[:index_method])
    return
  end

  begin
    klass = Object.const_get(parts[1].capitalize).new.set_instance_variables(request,response)
    if(parts[3].nil?)        
      if(path[path.length-1] == "/" || parts.length == 2)
        klass.send(request.request_method.downcase!+"_index");
      else
        klass.send(request.request_method.downcase!+"_"+parts[2])
      end
    else
      klass.send(request.request_method.downcase!+"_"+parts[2],parts[3..parts.length])
    end
  rescue Exception => e
    response.status =  404
    response.write "<h1>404 Not Found</h1><hr/><i>Ruby Rack Server powered by ObjectsFramework <br/><pre>#{e.to_s}</pre></i>"
  end

end