Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #7321 from bogdan/refactor_routes_set

RouteSet: refactor internals
  • Loading branch information...
commit f2557112a5d87fc815aa577583dbcd9774848d11 2 parents 09d2671 + 79a0c8c
@spastorino spastorino authored
Showing with 7 additions and 10 deletions.
  1. +7 −10 actionpack/lib/action_dispatch/routing/route_set.rb
View
17 actionpack/lib/action_dispatch/routing/route_set.rb
@@ -226,7 +226,7 @@ def optimized_helper(route)
attr_accessor :formatter, :set, :named_routes, :default_scope, :router
attr_accessor :disable_clear_and_finalize, :resources_path_names
- attr_accessor :default_url_options, :request_class, :valid_conditions
+ attr_accessor :default_url_options, :request_class
alias :routes :set
@@ -238,13 +238,7 @@ def initialize(request_class = ActionDispatch::Request)
self.named_routes = NamedRouteCollection.new
self.resources_path_names = self.class.default_resources_path_names.dup
self.default_url_options = {}
-
self.request_class = request_class
- @valid_conditions = { :controller => true, :action => true }
- request_class.public_instance_methods.each { |m|
- @valid_conditions[m] = true
- }
- @valid_conditions.delete(:id)
@append = []
@prepend = []
@@ -375,7 +369,7 @@ def add_route(app, conditions = {}, requirements = {}, defaults = {}, name = nil
raise ArgumentError, "Invalid route name: '#{name}'" unless name.blank? || name.to_s.match(/^[_a-z]\w*$/i)
path = build_path(conditions.delete(:path_info), requirements, SEPARATORS, anchor)
- conditions = build_conditions(conditions, valid_conditions, path.names.map { |x| x.to_sym })
+ conditions = build_conditions(conditions, path.names.map { |x| x.to_sym })
route = @set.add_route(app, path, conditions, defaults, name)
named_routes[name] = route if name && !named_routes[name]
@@ -412,7 +406,7 @@ def build_path(path, requirements, separators, anchor)
end
private :build_path
- def build_conditions(current_conditions, req_predicates, path_values)
+ def build_conditions(current_conditions, path_values)
conditions = current_conditions.dup
verbs = conditions[:request_method] || []
@@ -424,7 +418,10 @@ def build_conditions(current_conditions, req_predicates, path_values)
unless verbs.empty?
conditions[:request_method] = %r[^#{verbs.join('|')}$]
end
- conditions.delete_if { |k,v| !(req_predicates.include?(k) || path_values.include?(k)) }
+ conditions.keep_if do |k,v|
+ k == :action || k == :controller ||
+ @request_class.public_method_defined?(k) || path_values.include?(k)
+ end
conditions
end
Please sign in to comment.
Something went wrong with that request. Please try again.