Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

RouteSet: refactor internals #7321

Merged
merged 1 commit into from

3 participants

@bogdan

No need to build valid_conditions array.
We can get all the data in place.

@bogdan bogdan RouteSet: refactor internals
No need to build valid_conditions array.
We can get all the data in place.
79a0c8c
@bogdan

@rafaelfranca probably this is not so serious change to call heavy artillery

@spastorino spastorino merged commit f255711 into rails:master
@rafaelfranca

@bogdan haha, I'm not familiar with this code, and since I'm not a Rails Core member I prefer to call someone from the core to merge code from areas that I'm not familiar.

I don't want to receive claims later :smile:

@bogdan bogdan deleted the bogdan:refactor_routes_set branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 10, 2012
  1. @bogdan

    RouteSet: refactor internals

    bogdan authored
    No need to build valid_conditions array.
    We can get all the data in place.
This page is out of date. Refresh to see the latest.
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
Something went wrong with that request. Please try again.