Permalink
Browse files

even thinner routes

  • Loading branch information...
1 parent c1dcf7f commit cf698358fae4321530f05d01856e8b96adc570fe @joshbuddy committed Oct 2, 2011
Showing with 64 additions and 67 deletions.
  1. +2 −0 lib/http_router.rb
  2. +29 −0 lib/http_router/generation_helper.rb
  3. +4 −66 lib/http_router/route.rb
  4. +29 −1 lib/http_router/route_helper.rb
View
@@ -9,6 +9,7 @@
require 'http_router/route'
require 'http_router/generator'
require 'http_router/route_helper'
+require 'http_router/generation_helper'
require 'http_router/regex_route_generation'
require 'http_router/rack'
require 'http_router/util'
@@ -99,6 +100,7 @@ def extend_route(&blk)
def route_class
@extended_route_class ||= begin
@route_class.send(:include, RouteHelper)
+ @route_class.send(:include, GenerationHelper)
@route_class
end
end
@@ -0,0 +1,29 @@
+class HttpRouter
+ module GenerationHelper
+ def max_param_count
+ @generator.max_param_count
+ end
+
+ def url(*args)
+ @generator.url(*args)
+ rescue InvalidRouteException
+ nil
+ end
+
+ def url_ns(*args)
+ @generator.url_ns(*args)
+ rescue InvalidRouteException
+ nil
+ end
+
+ def path(*args)
+ @generator.path(*args)
+ rescue InvalidRouteException
+ nil
+ end
+
+ def param_names
+ @generator.param_names
+ end
+ end
+end
View
@@ -4,45 +4,9 @@ class HttpRouter
class Route
VALID_HTTP_VERBS = %w{GET POST PUT DELETE HEAD OPTIONS TRACE}
- attr_reader :default_values, :router, :match_partially, :other_hosts, :paths, :request_methods
- attr_accessor :match_partially, :router, :host, :user_agent, :name, :ignore_trailing_slash,
- :path_for_generation, :path_validation_regex, :generator, :scheme, :original_path
-
- def add_default_values(hash)
- @default_values ||= {}
- @default_values.merge!(hash)
- end
-
- def dest
- @dest
- end
-
- def dest=(d)
- @dest = d
- end
-
- def add_match_with(matchers)
- @match_with ||= {}
- @match_with.merge!(matchers)
- end
-
- def add_other_host(hosts)
- (@other_hosts ||= []).concat(hosts)
- end
-
- def add_path(path)
- (@paths ||= []) << path
- end
-
- def add_request_method(methods)
- @request_methods ||= Set.new
- methods = [methods] unless methods.is_a?(Array)
- methods.each do |method|
- method = method.to_s.upcase
- raise unless VALID_HTTP_VERBS.include?(method)
- @request_methods << method
- end
- end
+ attr_reader :default_values, :router, :match_partially, :other_hosts, :paths, :request_methods, :name
+ attr_accessor :match_partially, :router, :host, :user_agent, :ignore_trailing_slash,
+ :path_for_generation, :path_validation_regex, :generator, :scheme, :original_path, :dest
def clone(new_router)
r = super()
@@ -58,35 +22,9 @@ def matches_with(var_name)
@match_with && @match_with[:"#{var_name}"]
end
- def max_param_count
- @generator.max_param_count
- end
-
- def url(*args)
- @generator.url(*args)
- rescue InvalidRouteException
- nil
- end
-
- def url_ns(*args)
- @generator.url_ns(*args)
- rescue InvalidRouteException
- nil
- end
-
- def path(*args)
- @generator.path(*args)
- rescue InvalidRouteException
- nil
- end
-
def name=(name)
@name = name
- @router.named_routes[name] << self
- end
-
- def param_names
- @generator.param_names
+ router.named_routes[name] << self
end
end
end
@@ -16,13 +16,41 @@ def path=(path)
def name(name = nil)
if name
- @name = name
+ self.name = name
self
else
@name
end
end
+ def add_default_values(hash)
+ @default_values ||= {}
+ @default_values.merge!(hash)
+ end
+
+ def add_match_with(matchers)
+ @match_with ||= {}
+ @match_with.merge!(matchers)
+ end
+
+ def add_other_host(hosts)
+ (@other_hosts ||= []).concat(hosts)
+ end
+
+ def add_path(path)
+ (@paths ||= []) << path
+ end
+
+ def add_request_method(methods)
+ @request_methods ||= Set.new
+ methods = [methods] unless methods.is_a?(Array)
+ methods.each do |method|
+ method = method.to_s.upcase
+ raise unless Route::VALID_HTTP_VERBS.include?(method)
+ @request_methods << method
+ end
+ end
+
def process_opts(opts)
if opts[:conditions]
opts.merge!(opts[:conditions])

4 comments on commit cf69835

When you plan to release this version? We are near to close doors for padrino 10.3, would be nice if we can integrate also your 10.3 version... if is very near to close and compat with us.

Collaborator

nesquena replied Oct 2, 2011

I think the nice new router is better off as a big feature for 10.4 at this point, 10.3 will likely be released tomorrow.

Owner

joshbuddy replied Oct 2, 2011

It shouldn't change the API or behaviour at all (at this point). Still working on getting it out.

Collaborator

nesquena replied Oct 2, 2011

Cool, nice work on this.

Please sign in to comment.