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