1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

fewer operations on the options hash

since we pass `as` down, then we won't have to do an insert / delete
dance with the options hash
This commit is contained in:
Aaron Patterson 2014-08-13 18:34:21 -07:00
parent d4981c393b
commit 3b908cba28
2 changed files with 11 additions and 11 deletions

View file

@ -63,7 +63,7 @@ module ActionDispatch
attr_reader :requirements, :conditions, :defaults
attr_reader :to, :default_controller, :default_action, :as, :anchor
def self.build(scope, set, path, options)
def self.build(scope, set, path, as, options)
options = scope[:options].merge(options) if scope[:options]
options.delete :only
@ -74,10 +74,10 @@ module ActionDispatch
defaults = (scope[:defaults] || {}).merge options.delete(:defaults) || {}
new scope, set, path, defaults, options
new scope, set, path, defaults, as, options
end
def initialize(scope, set, path, defaults, options)
def initialize(scope, set, path, defaults, as, options)
@requirements, @conditions = {}, {}
@defaults = defaults
@set = set
@ -85,7 +85,7 @@ module ActionDispatch
@to = options.delete :to
@default_controller = options.delete(:controller) || scope[:controller]
@default_action = options.delete(:action) || scope[:action]
@as = options.delete :as
@as = as
@anchor = options.delete :anchor
formatted = options.delete :format
@ -1544,13 +1544,13 @@ module ActionDispatch
action = nil
end
if !options.fetch(:as, true) # if it's set to nil or false
options.delete(:as)
else
options[:as] = name_for_action(options[:as], action)
end
as = if !options.fetch(:as, true) # if it's set to nil or false
options.delete(:as)
else
name_for_action(options.delete(:as), action)
end
mapping = Mapping.build(@scope, @set, URI.parser.escape(path), options)
mapping = Mapping.build(@scope, @set, URI.parser.escape(path), as, options)
app, conditions, requirements, defaults, as, anchor = mapping.to_route
@set.add_route(app, conditions, requirements, defaults, as, anchor)
end

View file

@ -38,7 +38,7 @@ module ActionDispatch
def test_mapping_requirements
options = { :controller => 'foo', :action => 'bar', :via => :get }
m = Mapper::Mapping.build({}, FakeSet.new, '/store/:name(*rest)', options)
m = Mapper::Mapping.build({}, FakeSet.new, '/store/:name(*rest)', nil, options)
_, _, requirements, _ = m.to_route
assert_equal(/.+?/, requirements[:rest])
end