Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Restore `rake routes` [#3402 state:resolved]

  • Loading branch information...
commit a840c8afbf4e30b7bd9979e8cd70192c65be7a43 1 parent a0049a6
@josh josh authored
View
1  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( / . ? )
View
3  actionpack/lib/action_dispatch/routing/deprecated_mapper.rb
@@ -132,7 +132,6 @@ def connect(path, options = {})
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 @@ def connect(path, options = {})
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:
View
8 actionpack/lib/action_dispatch/routing/mapper.rb
@@ -252,9 +252,11 @@ def match(*args)
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 @@ def match(*args)
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
View
44 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
View
11 actionpack/lib/action_dispatch/routing/route_set.rb
@@ -47,11 +47,6 @@ def split_glob_param!(params)
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 @@ def routes_changed_at
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
View
9 railties/lib/rails/tasks/routes.rake
@@ -3,16 +3,13 @@ task :routes => :environment do
all_routes = ENV['CONTROLLER'] ? ActionController::Routing::Routes.routes.select { |route| route.defaults[:controller] == ENV['CONTROLLER'] } : ActionController::Routing::Routes.routes
routes = all_routes.collect do |route|
name = ActionController::Routing::Routes.named_routes.routes.index(route).to_s
- verb = route.conditions[:method].to_s.upcase
- segs = route.segments.inject("") { |str,s| str << s.to_s }
- segs.chop! if segs.length > 1
reqs = route.requirements.empty? ? "" : route.requirements.inspect
- {:name => name, :verb => verb, :segs => segs, :reqs => reqs}
+ {:name => name, :verb => route.verb.to_s, :path => route.path, :reqs => reqs}
end
name_width = routes.collect {|r| r[:name]}.collect {|n| n.length}.max
verb_width = routes.collect {|r| r[:verb]}.collect {|v| v.length}.max
- segs_width = routes.collect {|r| r[:segs]}.collect {|s| s.length}.max
+ path_width = routes.collect {|r| r[:path]}.collect {|s| s.length}.max
routes.each do |r|
- puts "#{r[:name].rjust(name_width)} #{r[:verb].ljust(verb_width)} #{r[:segs].ljust(segs_width)} #{r[:reqs]}"
+ puts "#{r[:name].rjust(name_width)} #{r[:verb].ljust(verb_width)} #{r[:path].ljust(path_width)} #{r[:reqs]}"
end
end

1 comment on commit a840c8a

@jpartogi

I think this changeset cause this error:
vendor/plugins/rack-mount/lib/rack/mount/route.rb:34:in initialize': app must be a valid rack application and respond to call (ArgumentError)
from vendor/plugins/rack-mount/lib/rack/mount/generation/route.rb:9:in
initialize'
from vendor/plugins/rack-mount/lib/rack/mount/recognition/route.rb:9:in initialize'
from vendor/plugins/rack-mount/lib/rack/mount/mixover.rb:25:in
new'
from vendor/plugins/rack-mount/lib/rack/mount/route_set.rb:46:in add_route'
from vendor/plugins/rack-mount/lib/rack/mount/generation/route_set.rb:17:in
add_route'
from vendor/plugins/rack-mount/lib/rack/mount/recognition/route_set.rb:19:in add_route'
from vendor/rails/actionpack/lib/action_dispatch/routing/route_set.rb:290:in
add_route'
from vendor/rails/actionpack/lib/action_dispatch/routing/deprecated_mapper.rb:147:in connect'
from vendor/rails/actionpack/lib/action_dispatch/routing/deprecated_mapper.rb:213:in
named_route'
from vendor/rails/activesupport/lib/active_support/option_merger.rb:22:in method_missing'
from vendor/rails/actionpack/lib/action_dispatch/routing/deprecated_mapper.rb:849:in
map_resource_routes'
from vendor/rails/actionpack/lib/action_dispatch/routing/deprecated_mapper.rb:801:in map_default_collection_actions'
from vendor/rails/actionpack/lib/action_dispatch/routing/deprecated_mapper.rb:731:in
block in map_resource'
from vendor/rails/activesupport/lib/active_support/core_ext/object/with_options.rb:22:in with_options'
from vendor/rails/actionpack/lib/action_dispatch/routing/deprecated_mapper.rb:723:in
map_resource'
from vendor/rails/actionpack/lib/action_dispatch/routing/deprecated_mapper.rb:642:in block in resources'
from vendor/rails/actionpack/lib/action_dispatch/routing/deprecated_mapper.rb:642:in
each'
from vendor/rails/actionpack/lib/action_dispatch/routing/deprecated_mapper.rb:642:in resources'
from config/routes.rb:2:in
block in '
from vendor/rails/actionpack/lib/action_dispatch/routing/route_set.rb:208:in `instance_exec'
from vendor/rails/actionpack/lib/action_dispatch/routing/route_s

I've already used your version of rack-mount. Is there anything missed?

Please sign in to comment.
Something went wrong with that request. Please try again.