1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Push options check up so we can simplify internal methods

This commit is contained in:
Carlos Antonio da Silva 2014-07-31 13:05:56 -03:00
parent 84093c6627
commit 8d61463f34

View file

@ -51,28 +51,25 @@ module ActionDispatch
def path_for(options)
result = options[:script_name].to_s.chomp("/")
result << options[:path].to_s
result = add_trailing_slash(result) if options[:trailing_slash]
result = add_params options, result
add_anchor options, result
result = add_params(result, options[:params]) if options.key?(:params)
result = add_anchor(result, options[:anchor]) if options.key?(:anchor)
result
end
private
def add_params(options, result)
if options.key? :params
param = options[:params]
def add_params(result, param)
params = param.is_a?(Hash) ? param : { params: param }
params.reject! { |_,v| v.to_param.nil? }
result << "?#{params.to_query}" unless params.empty?
end
result
end
def add_anchor(options, result)
result << "##{Journey::Router::Utils.escape_fragment(options[:anchor].to_param.to_s)}" if options[:anchor]
def add_anchor(result, anchor)
result << "##{Journey::Router::Utils.escape_fragment(anchor.to_param.to_s)}"
result
end