提交 0b859dfe 编写于 作者: C Carlos Antonio da Silva

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.
上级 091a5930
......@@ -51,9 +51,11 @@ def full_url_for(options)
def path_for(options)
path = options[:script_name].to_s.chomp("/")
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)
path = add_anchor(path, options[:anchor]) if options.key?(:anchor)
add_trailing_slash(path) if options[:trailing_slash]
add_params(path, options[:params]) if options.key?(:params)
add_anchor(path, options[:anchor]) if options.key?(:anchor)
path
end
......@@ -63,13 +65,10 @@ def add_params(path, params)
params = { params: params } unless params.is_a?(Hash)
params.reject! { |_,v| v.to_param.nil? }
path << "?#{params.to_query}" unless params.empty?
path
end
def add_anchor(path, anchor)
path << "##{Journey::Router::Utils.escape_fragment(anchor.to_param.to_s)}"
path
end
def extract_domain_from(host, tld_length)
......@@ -89,8 +88,6 @@ def add_trailing_slash(path)
elsif !path.include?(".")
path.sub!(/[^\/]\z|\A\z/, '\&/')
end
path
end
def build_host_url(host, port, protocol, options, path)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册