diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2011-03-07 09:33:19 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2011-03-07 09:33:19 -0800 |
commit | a032212e7c1da834ae75d85a4f2f1f943bfdc474 (patch) | |
tree | a5acd144db547ecdcf66ef936e97ff35b12ea039 /activesupport/lib | |
parent | 532f915037ab65873c433e30399d11f93df9f1f8 (diff) | |
download | rails-a032212e7c1da834ae75d85a4f2f1f943bfdc474.tar.gz rails-a032212e7c1da834ae75d85a4f2f1f943bfdc474.tar.bz2 rails-a032212e7c1da834ae75d85a4f2f1f943bfdc474.zip |
refactor calls to to_param in expand_key method
Diffstat (limited to 'activesupport/lib')
-rw-r--r-- | activesupport/lib/active_support/cache.rb | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/activesupport/lib/active_support/cache.rb b/activesupport/lib/active_support/cache.rb index ddb7a315e2..e2b7b0707b 100644 --- a/activesupport/lib/active_support/cache.rb +++ b/activesupport/lib/active_support/cache.rb @@ -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. |