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

Allow named routes to be debugged.

上级 bbe80ae6
...@@ -138,41 +138,38 @@ def define_named_route_methods(name, route) ...@@ -138,41 +138,38 @@ def define_named_route_methods(name, route)
end end
end end
def named_helper_module_eval(code, *args)
@module.module_eval(code, *args)
end
def define_hash_access(route, name, kind, options) def define_hash_access(route, name, kind, options)
selector = hash_access_name(name, kind) selector = hash_access_name(name, kind)
named_helper_module_eval <<-end_eval # We use module_eval to avoid leaks
# We use module_eval to avoid leaks
@module.module_eval <<-END_EVAL, __FILE__, __LINE__ + 1
def #{selector}(options = nil) # def hash_for_users_url(options = nil) def #{selector}(options = nil) # def hash_for_users_url(options = nil)
options ? #{options.inspect}.merge(options) : #{options.inspect} # options ? {:only_path=>false}.merge(options) : {:only_path=>false} options ? #{options.inspect}.merge(options) : #{options.inspect} # options ? {:only_path=>false}.merge(options) : {:only_path=>false}
end # end end # end
protected :#{selector} # protected :hash_for_users_url protected :#{selector} # protected :hash_for_users_url
end_eval END_EVAL
helpers << selector helpers << selector
end end
# Create a url helper allowing ordered parameters to be associated
# with corresponding dynamic segments, so you can do:
#
# foo_url(bar, baz, bang)
#
# Instead of:
#
# foo_url(:bar => bar, :baz => baz, :bang => bang)
#
# Also allow options hash, so you can do:
#
# foo_url(bar, baz, bang, :sort_by => 'baz')
#
def define_url_helper(route, name, kind, options) def define_url_helper(route, name, kind, options)
selector = url_helper_name(name, kind) selector = url_helper_name(name, kind)
# The segment keys used for positional parameters
hash_access_method = hash_access_name(name, kind) hash_access_method = hash_access_name(name, kind)
# allow ordered parameters to be associated with corresponding # We use module_eval to avoid leaks
# dynamic segments, so you can do @module.module_eval <<-END_EVAL, __FILE__, __LINE__ + 1
#
# foo_url(bar, baz, bang)
#
# instead of
#
# foo_url(:bar => bar, :baz => baz, :bang => bang)
#
# Also allow options hash, so you can do
#
# foo_url(bar, baz, bang, :sort_by => 'baz')
#
named_helper_module_eval <<-end_eval # We use module_eval to avoid leaks
def #{selector}(*args) # def users_url(*args) def #{selector}(*args) # def users_url(*args)
# #
opts = if args.empty? || Hash === args.first # opts = if args.empty? || Hash === args.first opts = if args.empty? || Hash === args.first # opts = if args.empty? || Hash === args.first
...@@ -190,7 +187,7 @@ def #{selector}(*args) # ...@@ -190,7 +187,7 @@ def #{selector}(*args) #
# #
end # end end # end
protected :#{selector} # protected :users_url protected :#{selector} # protected :users_url
end_eval END_EVAL
helpers << selector helpers << selector
end end
end end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册