提交 0d2001f0 编写于 作者: J José Valim

Merge pull request #6121 from bogdan/routes

ActionPack routes: remove some useless code.
...@@ -99,12 +99,12 @@ def initialize ...@@ -99,12 +99,12 @@ def initialize
@module = Module.new do @module = Module.new do
protected protected
def handle_positional_args(args, options, route) def handle_positional_args(args, options, segment_keys)
inner_options = args.extract_options! inner_options = args.extract_options!
result = options.dup result = options.dup
if args.any? if args.any?
keys = route.segment_keys keys = segment_keys
if args.size < keys.size - 1 # take format into account if args.size < keys.size - 1 # take format into account
keys -= self.url_options.keys if self.respond_to?(:url_options) keys -= self.url_options.keys if self.respond_to?(:url_options)
keys -= options.keys keys -= options.keys
...@@ -161,34 +161,13 @@ def url_helper_name(name, only_path) ...@@ -161,34 +161,13 @@ def url_helper_name(name, only_path)
end end
end end
def hash_access_name(name, only_path)
if only_path
:"hash_for_#{name}_path"
else
:"hash_for_#{name}_url"
end
end
def define_named_route_methods(name, route) def define_named_route_methods(name, route)
[true, false].each do |only_path| [true, false].each do |only_path|
hash = route.defaults.merge(:use_route => name, :only_path => only_path) hash = route.defaults.merge(:use_route => name, :only_path => only_path)
define_hash_access route, name, hash
define_url_helper route, name, hash define_url_helper route, name, hash
end end
end end
def define_hash_access(route, name, options)
selector = hash_access_name(name, options[:only_path])
@module.module_eval do
redefine_method(selector) do |*args|
self.handle_positional_args(args, options, route)
end
protected selector
end
helpers << selector
end
# Create a url helper allowing ordered parameters to be associated # Create a url helper allowing ordered parameters to be associated
# with corresponding dynamic segments, so you can do: # with corresponding dynamic segments, so you can do:
# #
...@@ -204,7 +183,6 @@ def define_hash_access(route, name, options) ...@@ -204,7 +183,6 @@ def define_hash_access(route, name, options)
# #
def define_url_helper(route, name, options) def define_url_helper(route, name, options)
selector = url_helper_name(name, options[:only_path]) selector = url_helper_name(name, options[:only_path])
hash_access_method = hash_access_name(name, options[:only_path])
if optimize_helper?(route) if optimize_helper?(route)
@module.module_eval <<-END_EVAL, __FILE__, __LINE__ + 1 @module.module_eval <<-END_EVAL, __FILE__, __LINE__ + 1
...@@ -215,7 +193,7 @@ def #{selector}(*args) ...@@ -215,7 +193,7 @@ def #{selector}(*args)
options[:path] = "#{optimized_helper(route)}" options[:path] = "#{optimized_helper(route)}"
ActionDispatch::Http::URL.url_for(options) ActionDispatch::Http::URL.url_for(options)
else else
url_for(#{hash_access_method}(*args)) url_for(handle_positional_args(args, #{options.inspect}, #{route.segment_keys.inspect}))
end end
end end
END_EVAL END_EVAL
...@@ -223,7 +201,7 @@ def #{selector}(*args) ...@@ -223,7 +201,7 @@ def #{selector}(*args)
@module.module_eval <<-END_EVAL, __FILE__, __LINE__ + 1 @module.module_eval <<-END_EVAL, __FILE__, __LINE__ + 1
remove_possible_method :#{selector} remove_possible_method :#{selector}
def #{selector}(*args) def #{selector}(*args)
url_for(#{hash_access_method}(*args)) url_for(handle_positional_args(args, #{options.inspect}, #{route.segment_keys.inspect}))
end end
END_EVAL END_EVAL
end end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册