Permalink
Browse files

First commit

  • Loading branch information...
0 parents commit 189bda9ef904bec04d1a87283a13c90a53527250 @alejopelaez committed Oct 21, 2010
Showing with 106 additions and 0 deletions.
  1. 0 README
  2. +8 −0 config.ru
  3. +16 −0 dsl.rb
  4. +60 −0 routes.rb
  5. +22 −0 ruteo.rb
No changes.
@@ -0,0 +1,8 @@
+use Rack::Reloader, 0
+use Rack::ContentLength
+
+require 'ruteo'
+
+app = RuteoApp.new
+
+run app
@@ -0,0 +1,16 @@
+module DSL
+ def self.included(base)
+ base.extend(ClassMethods)
+ base.class_eval do
+ @routes = Routes.new
+ end
+ end
+
+ attr_reader :routes
+
+ def get( path, opts={}, &block) routes.add(:get, path, opts, &block) end
+ def post( path, opts={}, &block) routes.add(:post, path, opts, &block) end
+ def put( path, opts={}, &block) routes.add(:put, path, opts, &block) end
+ def delete(path, opts={}, &block) routes.add(:delete, path, opts, &block) end
+
+end
@@ -0,0 +1,60 @@
+class Routes < Array
+ def add(method, path, options=nil, &action)
+ self << Route.new(method,path,options,&action)
+ end
+
+ # Este metodo mira si una ruta dada coinide con alguna
+ # de las rutas internas.
+ # Retorna la primer ruta que haga match.
+ def math(method, path)
+ return nil if self.empty?
+ method = method.to_s.downcase.strip.to_sym
+ routes = self.select{|i| i.method = method}
+ pahts = routes.map{|i| i.path}
+ path, values = Router.match(path,paths)
+ end
+end
+
+class Route
+ attr_accessor :pattern,:options,:action
+
+ def initialize(method, path, options, &action)
+ @pattern = Pattern.new(metodo,path)
+ @options = options
+ @action = action
+ end
+
+end
+
+# Clase que representa un patron de la forma
+# metodo /static1/static2/.../staticn/:opt1/:opt2...
+# Tiene la capacidad de hacer math con un path concreto
+# y devolver los parametros.
+class Pattern
+ attr_accessor :method, :path
+ def initialize(method, path)
+
+ end
+end
+
+# Clase encargada de hacer el mathing entre una ruta
+# y una lista de rutas.
+# Ademas retorna los valores encontrados.
+class Router
+ def self.match(path,paths)
+
+ end
+
+ def static_match
+ end
+
+ def values_mathc
+ end
+end
+
+# Clase que representa una uri, contiene las partes y
+# la extension del recurso solicitado.
+class Path
+end
+
+end
@@ -0,0 +1,22 @@
+class RuteoApp
+ def test(env)
+ [200, {"Content-Type" => "text/plain"}, "Funciona!!!"]
+ end
+
+ def test2(env)
+ [200, {"Content-Type" => "text/plain"}, "Confirmado, funciona!!!"]
+ end
+
+ def call(env)
+ path = env["PATH_INFO"][1..-1]
+ case
+ when path == ""
+ [200, {"Content-Type" => "text/plain"}, "Pagina de inicio"]
+ when (self.respond_to? path)
+ self.send( path, env )
+ else
+ [200, {"Content-Type" => "text/plain"}, "Not found!!"]
+ end
+ end
+
+end

0 comments on commit 189bda9

Please sign in to comment.