Skip to content

Commit

Permalink
Push options check up so we can simplify internal methods
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosantoniodasilva committed Jul 31, 2014
1 parent 84093c6 commit 8d61463
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions actionpack/lib/action_dispatch/http/url.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -51,28 +51,25 @@ def full_url_for(options)
def path_for(options) def path_for(options)
result = options[:script_name].to_s.chomp("/") result = options[:script_name].to_s.chomp("/")
result << options[:path].to_s result << options[:path].to_s

result = add_trailing_slash(result) if options[:trailing_slash] result = add_trailing_slash(result) if options[:trailing_slash]

result = add_params(result, options[:params]) if options.key?(:params)
result = add_params options, result result = add_anchor(result, options[:anchor]) if options.key?(:anchor)
add_anchor options, result result
end end


private private


def add_params(options, result) def add_params(result, param)
if options.key? :params params = param.is_a?(Hash) ? param : { params: param }
param = options[:params]
params = param.is_a?(Hash) ? param : { params: param } params.reject! { |_,v| v.to_param.nil? }
result << "?#{params.to_query}" unless params.empty?


params.reject! { |_,v| v.to_param.nil? }
result << "?#{params.to_query}" unless params.empty?
end
result result
end end


def add_anchor(options, result) def add_anchor(result, anchor)
result << "##{Journey::Router::Utils.escape_fragment(options[:anchor].to_param.to_s)}" if options[:anchor] result << "##{Journey::Router::Utils.escape_fragment(anchor.to_param.to_s)}"
result result
end end


Expand Down

0 comments on commit 8d61463

Please sign in to comment.