From b6ec5e2c14e30bbb8a8dc434da36fc976440f2ca Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Sat, 24 May 2014 19:07:26 -0700 Subject: eliminate dispatcher is_a checks --- actionpack/lib/action_dispatch/routing/mapper.rb | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'actionpack/lib/action_dispatch/routing') diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index c7f6ff620e..a6f17b9459 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -18,7 +18,7 @@ module ActionDispatch class Constraints #:nodoc: attr_reader :app, :constraints - def initialize(app, constraints, request) + def initialize(app, constraints, request, dispatcher_p) # Unwrap Constraints objects. I don't actually think it's possible # to pass a Constraints object to this constructor, but there were # multiple places that kept testing children of this object. I @@ -28,10 +28,7 @@ module ActionDispatch app = app.app end - # Unwrap any constraints so we can see what's inside for route generation. - # This allows the formatter to skip over any mounted applications or redirects - # that shouldn't be matched when using a url_for without a route name. - @dispatcher = app.is_a?(Routing::RouteSet::Dispatcher) + @dispatcher = dispatcher_p @app, @constraints, @request = app, constraints, request end @@ -223,12 +220,21 @@ module ActionDispatch end def app - endpoint = to.respond_to?(:call) ? to : dispatcher + # Unwrap any constraints so we can see what's inside for route generation. + # This allows the formatter to skip over any mounted applications or redirects + # that shouldn't be matched when using a url_for without a route name. + if to.respond_to?(:call) + dispatcher_p = false + endpoint = to + else + dispatcher_p = true + endpoint = dispatcher + end if blocks.any? - Constraints.new(endpoint, blocks, @set.request_class) + Constraints.new(endpoint, blocks, @set.request_class, dispatcher_p) else - Constraints.new(endpoint, blocks, @set.request_class) + Constraints.new(endpoint, blocks, @set.request_class, dispatcher_p) end end -- cgit v1.2.3