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

set route precedence at allocation time

This way we can make the Route object a read-only data structure.
This commit is contained in:
Aaron Patterson 2015-08-20 15:34:18 -07:00
parent 7354ef146e
commit 867810cdfa
2 changed files with 6 additions and 8 deletions

View file

@ -1,13 +1,11 @@
module ActionDispatch
module Journey # :nodoc:
class Route # :nodoc:
attr_reader :app, :path, :defaults, :name
attr_reader :app, :path, :defaults, :name, :precedence
attr_reader :constraints
alias :conditions :constraints
attr_accessor :precedence
module VerbMatchers
VERBS = %w{ DELETE GET HEAD OPTIONS LINK PATCH POST PUT TRACE UNLINK }
VERBS.each do |v|
@ -51,13 +49,13 @@ module ActionDispatch
def self.build(name, app, path, constraints, required_defaults, defaults)
request_method_match = verb_matcher(constraints.delete(:request_method))
new name, app, path, constraints, required_defaults, defaults, request_method_match
new name, app, path, constraints, required_defaults, defaults, request_method_match, 0
end
##
# +path+ is a path constraint.
# +constraints+ is a hash of constraints to be applied to this route.
def initialize(name, app, path, constraints, required_defaults, defaults, request_method_match)
def initialize(name, app, path, constraints, required_defaults, defaults, request_method_match, precedence)
@name = name
@app = app
@path = path
@ -70,7 +68,7 @@ module ActionDispatch
@required_parts = nil
@parts = nil
@decorated_ast = nil
@precedence = 0
@precedence = precedence
@path_formatter = @path.build_formatter
end

View file

@ -150,9 +150,9 @@ module ActionDispatch
conditions,
required_defaults,
defaults,
request_method)
request_method,
precedence)
route.precedence = precedence
route
end