From fe19d07138fe69e05ce8b17534c3c548a0a92575 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Sat, 15 Aug 2015 14:34:37 -0700 Subject: move route allocation to a factory method on the mapping object I would like to change the signature of the Route constructor. Since the mapping object has all the data required to construct a Route object, move the allocation to a factory method. --- actionpack/lib/action_dispatch/journey/routes.rb | 9 +-------- actionpack/lib/action_dispatch/routing/mapper.rb | 12 ++++++++++++ 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/actionpack/lib/action_dispatch/journey/routes.rb b/actionpack/lib/action_dispatch/journey/routes.rb index 4770b8b7cc..f7b009109e 100644 --- a/actionpack/lib/action_dispatch/journey/routes.rb +++ b/actionpack/lib/action_dispatch/journey/routes.rb @@ -61,14 +61,7 @@ module ActionDispatch end def add_route(name, mapping) - route = Route.new(name, - mapping.application, - mapping.path, - mapping.conditions, - mapping.required_defaults, - mapping.defaults) - - route.precedence = routes.length + route = mapping.make_route name, routes.length routes << route partition_route(route) clear_cache! diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index f82c3c0d34..a9dae77e51 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -143,6 +143,18 @@ module ActionDispatch @required_defaults = (split_options[:required_defaults] || []).map(&:first) end + def make_route(name, precedence) + route = Journey::Route.new(name, + application, + path, + conditions, + required_defaults, + defaults) + + route.precedence = precedence + route + end + def application app(@blocks) end -- cgit v1.2.3