Permalink
Browse files

push some options munging to an alternate constructor

  • Loading branch information...
1 parent a217071 commit af1c8665cd9b5157a22c1f3dd3ddd4cbde31f9a1 @tenderlove tenderlove committed May 30, 2014
Showing with 19 additions and 13 deletions.
  1. +19 −13 actionpack/lib/action_dispatch/routing/mapper.rb
@@ -65,15 +65,27 @@ class Mapping #:nodoc:
attr_reader :requirements, :conditions, :defaults
attr_reader :to, :default_controller, :default_action, :as, :anchor
- def initialize(scope, path, options)
- @requirements, @conditions = {}, {}
+ def self.build(scope, path, options)
+ options = scope[:options].merge(options) if scope[:options]
+
+ options.delete :only
+ options.delete :except
+ options.delete :shallow_path
+ options.delete :shallow_prefix
+ options.delete :shallow
- @defaults = (scope[:defaults] || {}).merge options.delete(:defaults) || {}
+ defaults = (scope[:defaults] || {}).merge options.delete(:defaults) || {}
+
+ new scope, path, defaults, options
+ end
+
+ def initialize(scope, path, defaults, options)
+ @requirements, @conditions = {}, {}
+ @defaults = defaults
- options = scope[:options].merge(options) if scope[:options]
@to = options.delete :to
- @default_controller = options[:controller] || scope[:controller]
- @default_action = options[:action] || scope[:action]
+ @default_controller = options.delete(:controller) || scope[:controller]
+ @default_action = options.delete(:action) || scope[:action]
@as = options.delete :as
@anchor = options.delete :anchor
@@ -1516,13 +1528,7 @@ def add_route(action, options) # :nodoc:
options[:as] = name_for_action(options[:as], action)
end
- options.delete :only
- options.delete :except
- options.delete :shallow_path
- options.delete :shallow_prefix
- options.delete :shallow
-
- mapping = Mapping.new(@scope, URI.parser.escape(path), options)
+ mapping = Mapping.build(@scope, URI.parser.escape(path), options)
app, conditions, requirements, defaults, as, anchor = mapping.to_route
@set.add_route(app, conditions, requirements, defaults, as, anchor)
end

0 comments on commit af1c866

Please sign in to comment.