mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Do not reassign variable when mutation is happening
These methods mutate the path variable/argument so there is no need to reassign it every time.
This commit is contained in:
parent
091a59301f
commit
0b859dfefe
1 changed files with 5 additions and 8 deletions
|
@ -51,9 +51,11 @@ module ActionDispatch
|
||||||
def path_for(options)
|
def path_for(options)
|
||||||
path = options[:script_name].to_s.chomp("/")
|
path = options[:script_name].to_s.chomp("/")
|
||||||
path << options[:path] if options.key?(:path)
|
path << options[:path] if options.key?(:path)
|
||||||
path = add_trailing_slash(path) if options[:trailing_slash]
|
|
||||||
path = add_params(path, options[:params]) if options.key?(:params)
|
add_trailing_slash(path) if options[:trailing_slash]
|
||||||
path = add_anchor(path, options[:anchor]) if options.key?(:anchor)
|
add_params(path, options[:params]) if options.key?(:params)
|
||||||
|
add_anchor(path, options[:anchor]) if options.key?(:anchor)
|
||||||
|
|
||||||
path
|
path
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -63,13 +65,10 @@ module ActionDispatch
|
||||||
params = { params: params } unless params.is_a?(Hash)
|
params = { params: params } unless params.is_a?(Hash)
|
||||||
params.reject! { |_,v| v.to_param.nil? }
|
params.reject! { |_,v| v.to_param.nil? }
|
||||||
path << "?#{params.to_query}" unless params.empty?
|
path << "?#{params.to_query}" unless params.empty?
|
||||||
|
|
||||||
path
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def add_anchor(path, anchor)
|
def add_anchor(path, anchor)
|
||||||
path << "##{Journey::Router::Utils.escape_fragment(anchor.to_param.to_s)}"
|
path << "##{Journey::Router::Utils.escape_fragment(anchor.to_param.to_s)}"
|
||||||
path
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def extract_domain_from(host, tld_length)
|
def extract_domain_from(host, tld_length)
|
||||||
|
@ -89,8 +88,6 @@ module ActionDispatch
|
||||||
elsif !path.include?(".")
|
elsif !path.include?(".")
|
||||||
path.sub!(/[^\/]\z|\A\z/, '\&/')
|
path.sub!(/[^\/]\z|\A\z/, '\&/')
|
||||||
end
|
end
|
||||||
|
|
||||||
path
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def build_host_url(host, port, protocol, options, path)
|
def build_host_url(host, port, protocol, options, path)
|
||||||
|
|
Loading…
Reference in a new issue