aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib
diff options
context:
space:
mode:
authorSantiago Pastorino <santiago@wyeworks.com>2012-08-04 07:30:35 -0700
committerSantiago Pastorino <santiago@wyeworks.com>2012-08-04 07:30:35 -0700
commit96290d4faf5f9463bfbac08f10af5ac4753c715a (patch)
treec683df0c6411c054c5af25c487f43731428a2492 /actionpack/lib
parent1935cfd07fde9bc6f3c60547aa85279869eaf804 (diff)
parent9e03c6aab3bda076453a3ed1e9c6abd43a5e7599 (diff)
downloadrails-96290d4faf5f9463bfbac08f10af5ac4753c715a.tar.gz
rails-96290d4faf5f9463bfbac08f10af5ac4753c715a.tar.bz2
rails-96290d4faf5f9463bfbac08f10af5ac4753c715a.zip
Merge pull request #7262 from bogdan/refator_route_set
Refator route set
Diffstat (limited to 'actionpack/lib')
-rw-r--r--actionpack/lib/action_controller/metal/url_for.rb2
-rw-r--r--actionpack/lib/action_controller/test_case.rb2
-rw-r--r--actionpack/lib/action_dispatch/routing/route_set.rb33
3 files changed, 13 insertions, 24 deletions
diff --git a/actionpack/lib/action_controller/metal/url_for.rb b/actionpack/lib/action_controller/metal/url_for.rb
index e28c05cc2d..dd5ceb3478 100644
--- a/actionpack/lib/action_controller/metal/url_for.rb
+++ b/actionpack/lib/action_controller/metal/url_for.rb
@@ -27,7 +27,7 @@ module ActionController
:host => request.host,
:port => request.optional_port,
:protocol => request.protocol,
- :_path_segments => request.symbolized_path_parameters
+ :_recall => request.symbolized_path_parameters
).freeze
if _routes.equal?(env["action_dispatch.routes"])
diff --git a/actionpack/lib/action_controller/test_case.rb b/actionpack/lib/action_controller/test_case.rb
index 54a1b13c7c..bb693c6494 100644
--- a/actionpack/lib/action_controller/test_case.rb
+++ b/actionpack/lib/action_controller/test_case.rb
@@ -581,7 +581,7 @@ module ActionController
:only_path => true,
:action => action,
:relative_url_root => nil,
- :_path_segments => @request.symbolized_path_parameters)
+ :_recall => @request.symbolized_path_parameters)
url, query_string = @routes.url_for(options).split("?", 2)
diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb
index 6bb15ba3b6..62c921ff97 100644
--- a/actionpack/lib/action_dispatch/routing/route_set.rb
+++ b/actionpack/lib/action_dispatch/routing/route_set.rb
@@ -161,19 +161,12 @@ module ActionDispatch
end
private
- def url_helper_name(name, only_path)
- if only_path
- :"#{name}_path"
- else
- :"#{name}_url"
- end
- end
def define_named_route_methods(name, route)
- [true, false].each do |only_path|
- hash = route.defaults.merge(:use_route => name, :only_path => only_path)
- define_url_helper route, name, hash
- end
+ define_url_helper route, :"#{name}_path",
+ route.defaults.merge(:use_route => name, :only_path => true)
+ define_url_helper route, :"#{name}_url",
+ route.defaults.merge(:use_route => name, :only_path => false)
end
# Create a url helper allowing ordered parameters to be associated
@@ -190,11 +183,9 @@ module ActionDispatch
# foo_url(bar, baz, bang, :sort_by => 'baz')
#
def define_url_helper(route, name, options)
- selector = url_helper_name(name, options[:only_path])
-
@module.module_eval <<-END_EVAL, __FILE__, __LINE__ + 1
- remove_possible_method :#{selector}
- def #{selector}(*args)
+ remove_possible_method :#{name}
+ def #{name}(*args)
if #{optimize_helper?(route)} && args.size == #{route.required_parts.size} && !args.last.is_a?(Hash) && optimize_routes_generation?
options = #{options.inspect}
options.merge!(url_options) if respond_to?(:url_options)
@@ -206,7 +197,7 @@ module ActionDispatch
end
END_EVAL
- helpers << selector
+ helpers << name
end
# Clause check about when we need to generate an optimized helper.
@@ -476,10 +467,8 @@ module ActionDispatch
def use_recall_for(key)
if @recall[key] && (!@options.key?(key) || @options[key] == @recall[key])
- if named_route_exists?
- @options[key] = @recall.delete(key) if segment_keys.include?(key)
- else
- @options[key] = @recall.delete(key)
+ if !named_route_exists? || segment_keys.include?(key)
+ @options[key] = @recall.delete(key)
end
end
end
@@ -607,13 +596,13 @@ module ActionDispatch
options = default_url_options.merge(options || {})
user, password = extract_authentication(options)
- path_segments = options.delete(:_path_segments)
+ recall = options.delete(:_recall)
script_name = options.delete(:script_name).presence || _generate_prefix(options)
path_options = options.except(*RESERVED_OPTIONS)
path_options = yield(path_options) if block_given?
- path, params = generate(path_options, path_segments || {})
+ path, params = generate(path_options, recall || {})
params.merge!(options[:params] || {})
ActionDispatch::Http::URL.url_for(options.merge!({