aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorJoshua Peek <josh@joshpeek.com>2009-10-24 18:08:54 -0500
committerJoshua Peek <josh@joshpeek.com>2009-10-24 18:08:54 -0500
commita840c8afbf4e30b7bd9979e8cd70192c65be7a43 (patch)
tree82ca10172b498a604c051576f51e113eefe9a574 /actionpack
parenta0049a6b429c6de46537cc31bf7b3ca48b4c1b2c (diff)
downloadrails-a840c8afbf4e30b7bd9979e8cd70192c65be7a43.tar.gz
rails-a840c8afbf4e30b7bd9979e8cd70192c65be7a43.tar.bz2
rails-a840c8afbf4e30b7bd9979e8cd70192c65be7a43.zip
Restore `rake routes` [#3402 state:resolved]
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/lib/action_dispatch/routing.rb1
-rw-r--r--actionpack/lib/action_dispatch/routing/deprecated_mapper.rb3
-rw-r--r--actionpack/lib/action_dispatch/routing/mapper.rb8
-rw-r--r--actionpack/lib/action_dispatch/routing/route.rb44
-rw-r--r--actionpack/lib/action_dispatch/routing/route_set.rb11
5 files changed, 54 insertions, 13 deletions
diff --git a/actionpack/lib/action_dispatch/routing.rb b/actionpack/lib/action_dispatch/routing.rb
index 3803929847..b9c377db2c 100644
--- a/actionpack/lib/action_dispatch/routing.rb
+++ b/actionpack/lib/action_dispatch/routing.rb
@@ -262,6 +262,7 @@ module ActionDispatch
module Routing
autoload :DeprecatedMapper, 'action_dispatch/routing/deprecated_mapper'
autoload :Mapper, 'action_dispatch/routing/mapper'
+ autoload :Route, 'action_dispatch/routing/route'
autoload :RouteSet, 'action_dispatch/routing/route_set'
SEPARATORS = %w( / . ? )
diff --git a/actionpack/lib/action_dispatch/routing/deprecated_mapper.rb b/actionpack/lib/action_dispatch/routing/deprecated_mapper.rb
index f2a1f10fa7..0564ba9797 100644
--- a/actionpack/lib/action_dispatch/routing/deprecated_mapper.rb
+++ b/actionpack/lib/action_dispatch/routing/deprecated_mapper.rb
@@ -132,7 +132,6 @@ module ActionDispatch
path = optionalize_trailing_dynamic_segments(path, requirements, defaults)
glob = $1.to_sym if path =~ /\/\*(\w+)$/
path = ::Rack::Mount::Utils.normalize_path(path)
- path = ::Rack::Mount::Strexp.compile(path, requirements, %w( / . ? ))
if glob && !defaults[glob].blank?
raise ActionController::RoutingError, "paths cannot have non-empty default values"
@@ -145,7 +144,7 @@ module ActionDispatch
conditions[:request_method] = method if method
conditions[:path_info] = path if path
- @set.add_route(app, conditions, defaults, name)
+ @set.add_route(app, conditions, requirements, defaults, name)
end
def optionalize_trailing_dynamic_segments(path, requirements, defaults) #:nodoc:
diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb
index ab4193266a..d6d822842b 100644
--- a/actionpack/lib/action_dispatch/routing/mapper.rb
+++ b/actionpack/lib/action_dispatch/routing/mapper.rb
@@ -252,9 +252,11 @@ module ActionDispatch
constraints = (@scope[:constraints] || {}).merge(constraints)
options.each { |k, v| constraints[k] = v if v.is_a?(Regexp) }
- conditions[:path_info] = Rack::Mount::Strexp.compile(path, constraints, %w( / . ? ))
+ conditions[:path_info] = path
+ requirements = constraints.dup
- segment_keys = Rack::Mount::RegexpWithNamedGroups.new(conditions[:path_info]).names
+ path_regexp = Rack::Mount::Strexp.compile(path, constraints, SEPARATORS)
+ segment_keys = Rack::Mount::RegexpWithNamedGroups.new(path_regexp).names
constraints.reject! { |k, v| segment_keys.include?(k.to_s) }
conditions.merge!(constraints)
@@ -286,7 +288,7 @@ module ActionDispatch
end
app = Constraints.new(app, blocks) if blocks.any?
- @set.add_route(app, conditions, defaults, options[:as])
+ @set.add_route(app, conditions, requirements, defaults, options[:as])
self
end
diff --git a/actionpack/lib/action_dispatch/routing/route.rb b/actionpack/lib/action_dispatch/routing/route.rb
new file mode 100644
index 0000000000..8990e207c2
--- /dev/null
+++ b/actionpack/lib/action_dispatch/routing/route.rb
@@ -0,0 +1,44 @@
+module ActionDispatch
+ module Routing
+ class Route #:nodoc:
+ attr_reader :app, :conditions, :defaults, :name
+ attr_reader :path, :requirements
+
+ def initialize(app, conditions = {}, requirements = {}, defaults = {}, name = nil)
+ @app = app
+ @defaults = defaults
+ @name = name
+
+ @requirements = requirements.merge(defaults)
+ @requirements.delete(:controller) if @requirements[:controller].is_a?(Regexp)
+ @requirements.delete_if { |k, v|
+ v == Regexp.compile("[^#{SEPARATORS.join}]+")
+ }
+
+ if path = conditions[:path_info]
+ @path = path
+ conditions[:path_info] = ::Rack::Mount::Strexp.compile(path, requirements, SEPARATORS)
+ end
+
+ @conditions = conditions.inject({}) { |h, (k, v)|
+ h[k] = Rack::Mount::RegexpWithNamedGroups.new(v)
+ h
+ }
+ end
+
+ def verb
+ if verb = conditions[:verb]
+ verb.to_s.upcase
+ end
+ end
+
+ def segment_keys
+ @segment_keys ||= conditions[:path_info].names.compact.map { |key| key.to_sym }
+ end
+
+ def to_ary
+ [@app, @conditions, @defaults, @name]
+ end
+ end
+ end
+end
diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb
index 90d7c208a5..93617e826d 100644
--- a/actionpack/lib/action_dispatch/routing/route_set.rb
+++ b/actionpack/lib/action_dispatch/routing/route_set.rb
@@ -47,11 +47,6 @@ module ActionDispatch
end
end
- module RouteExtensions
- def segment_keys
- conditions[:path_info].names.compact.map { |key| key.to_sym }
- end
- end
# A NamedRouteCollection instance is a collection of named routes, and also
# maintains an anonymous module that can be used to install helpers for the
@@ -290,9 +285,9 @@ module ActionDispatch
routes_changed_at
end
- def add_route(app, conditions = {}, defaults = {}, name = nil)
- route = @set.add_route(app, conditions, defaults, name)
- route.extend(RouteExtensions)
+ def add_route(app, conditions = {}, requirements = {}, defaults = {}, name = nil)
+ route = Route.new(app, conditions, requirements, defaults, name)
+ @set.add_route(*route)
named_routes[name] = route if name
routes << route
route