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

refactor calls to to_param in expand_key method

This commit is contained in:
Aaron Patterson 2011-03-07 09:33:19 -08:00
parent 532f915037
commit a032212e7c

View file

@ -484,19 +484,20 @@ module ActiveSupport
# object responds to +cache_key+. Otherwise, to_param method will be
# called. If the key is a Hash, then keys will be sorted alphabetically.
def expanded_key(key) # :nodoc:
if key.respond_to?(:cache_key)
key = key.cache_key.to_s
elsif key.is_a?(Array)
return key.cache_key.to_s if key.respond_to?(:cache_key)
case key
when Array
if key.size > 1
key.collect{|element| expanded_key(element)}.to_param
key = key.collect{|element| expanded_key(element)}
else
key.first.to_param
key = key.first
end
elsif key.is_a?(Hash)
key = key.to_a.sort_by { |x| x.first.to_s }.collect{|k,v| "#{k}=#{v}"}.to_param
else
key = key.to_param
when Hash
key = key.sort_by { |k,_| k.to_s }.collect{|k,v| "#{k}=#{v}"}
end
key.to_param
end
# Prefix a key with the namespace. Namespace and key will be delimited with a colon.