activesupport 3.0.20 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (132) hide show
  1. data/CHANGELOG +24 -28
  2. data/README.rdoc +2 -2
  3. data/lib/active_support/backtrace_cleaner.rb +17 -12
  4. data/lib/active_support/buffered_logger.rb +7 -9
  5. data/lib/active_support/cache/file_store.rb +4 -3
  6. data/lib/active_support/cache/mem_cache_store.rb +10 -2
  7. data/lib/active_support/cache/strategy/local_cache.rb +28 -23
  8. data/lib/active_support/cache.rb +11 -14
  9. data/lib/active_support/callbacks.rb +195 -175
  10. data/lib/active_support/concern.rb +105 -35
  11. data/lib/active_support/configurable.rb +50 -8
  12. data/lib/active_support/core_ext/array/access.rb +2 -2
  13. data/lib/active_support/core_ext/array/conversions.rb +2 -2
  14. data/lib/active_support/core_ext/array/random_access.rb +10 -7
  15. data/lib/active_support/core_ext/array/uniq_by.rb +2 -3
  16. data/lib/active_support/core_ext/array/wrap.rb +1 -1
  17. data/lib/active_support/core_ext/big_decimal/conversions.rb +0 -2
  18. data/lib/active_support/core_ext/class/attribute.rb +15 -1
  19. data/lib/active_support/core_ext/class/inheritable_attributes.rb +10 -86
  20. data/lib/active_support/core_ext/class/subclasses.rb +20 -34
  21. data/lib/active_support/core_ext/date/calculations.rb +17 -5
  22. data/lib/active_support/core_ext/date/conversions.rb +9 -2
  23. data/lib/active_support/core_ext/date_time/calculations.rb +26 -9
  24. data/lib/active_support/core_ext/date_time/conversions.rb +9 -9
  25. data/lib/active_support/core_ext/date_time/zones.rb +1 -1
  26. data/lib/active_support/core_ext/enumerable.rb +3 -6
  27. data/lib/active_support/core_ext/float/rounding.rb +1 -1
  28. data/lib/active_support/core_ext/hash/conversions.rb +22 -34
  29. data/lib/active_support/core_ext/hash/deep_dup.rb +11 -0
  30. data/lib/active_support/core_ext/hash/indifferent_access.rb +12 -0
  31. data/lib/active_support/core_ext/hash/keys.rb +6 -4
  32. data/lib/active_support/core_ext/hash/reverse_merge.rb +9 -14
  33. data/lib/active_support/core_ext/hash/slice.rb +3 -1
  34. data/lib/active_support/core_ext/hash.rb +1 -0
  35. data/lib/active_support/core_ext/integer/inflections.rb +7 -4
  36. data/lib/active_support/core_ext/kernel/reporting.rb +31 -0
  37. data/lib/active_support/core_ext/kernel/requires.rb +2 -0
  38. data/lib/active_support/core_ext/logger.rb +11 -38
  39. data/lib/active_support/core_ext/module/attr_accessor_with_default.rb +12 -12
  40. data/lib/active_support/core_ext/module/attr_internal.rb +13 -6
  41. data/lib/active_support/core_ext/module/delegation.rb +1 -5
  42. data/lib/active_support/core_ext/module/remove_method.rb +7 -2
  43. data/lib/active_support/core_ext/numeric/time.rb +2 -0
  44. data/lib/active_support/core_ext/object/blank.rb +45 -12
  45. data/lib/active_support/core_ext/object/duplicable.rb +50 -9
  46. data/lib/active_support/core_ext/object/inclusion.rb +15 -0
  47. data/lib/active_support/core_ext/object/instance_variables.rb +1 -35
  48. data/lib/active_support/core_ext/object/to_param.rb +13 -8
  49. data/lib/active_support/core_ext/object/to_query.rb +2 -2
  50. data/lib/active_support/core_ext/object/try.rb +29 -10
  51. data/lib/active_support/core_ext/object/with_options.rb +25 -8
  52. data/lib/active_support/core_ext/object.rb +1 -1
  53. data/lib/active_support/core_ext/range/cover.rb +3 -0
  54. data/lib/active_support/core_ext/range.rb +1 -0
  55. data/lib/active_support/core_ext/string/behavior.rb +1 -2
  56. data/lib/active_support/core_ext/string/conversions.rb +1 -0
  57. data/lib/active_support/core_ext/string/exclude.rb +1 -1
  58. data/lib/active_support/core_ext/string/filters.rb +3 -3
  59. data/lib/active_support/core_ext/string/inflections.rb +1 -1
  60. data/lib/active_support/core_ext/string/inquiry.rb +13 -0
  61. data/lib/active_support/core_ext/string/multibyte.rb +2 -2
  62. data/lib/active_support/core_ext/string/output_safety.rb +45 -62
  63. data/lib/active_support/core_ext/string.rb +1 -0
  64. data/lib/active_support/core_ext/time/calculations.rb +19 -16
  65. data/lib/active_support/core_ext/time/conversions.rb +2 -24
  66. data/lib/active_support/core_ext/time/zones.rb +32 -21
  67. data/lib/active_support/core_ext/uri.rb +8 -0
  68. data/lib/active_support/dependencies.rb +74 -28
  69. data/lib/active_support/deprecation/behaviors.rb +7 -0
  70. data/lib/active_support/deprecation/proxy_wrappers.rb +1 -1
  71. data/lib/active_support/deprecation/reporting.rb +4 -0
  72. data/lib/active_support/deprecation.rb +2 -2
  73. data/lib/active_support/descendants_tracker.rb +9 -7
  74. data/lib/active_support/duration.rb +5 -0
  75. data/lib/active_support/file_update_checker.rb +1 -1
  76. data/lib/active_support/file_watcher.rb +36 -0
  77. data/lib/active_support/hash_with_indifferent_access.rb +20 -8
  78. data/lib/active_support/i18n.rb +0 -1
  79. data/lib/active_support/i18n_railtie.rb +2 -2
  80. data/lib/active_support/inflections.rb +1 -0
  81. data/lib/active_support/inflector/inflections.rb +1 -1
  82. data/lib/active_support/inflector/methods.rb +5 -3
  83. data/lib/active_support/json/decoding.rb +37 -23
  84. data/lib/active_support/json/encoding.rb +12 -4
  85. data/lib/active_support/lazy_load_hooks.rb +7 -7
  86. data/lib/active_support/log_subscriber/test_helper.rb +5 -3
  87. data/lib/active_support/log_subscriber.rb +6 -6
  88. data/lib/active_support/message_encryptor.rb +1 -1
  89. data/lib/active_support/message_verifier.rb +1 -1
  90. data/lib/active_support/multibyte/chars.rb +5 -5
  91. data/lib/active_support/multibyte/unicode.rb +2 -1
  92. data/lib/active_support/notifications/fanout.rb +3 -3
  93. data/lib/active_support/notifications/instrumenter.rb +1 -1
  94. data/lib/active_support/notifications.rb +9 -10
  95. data/lib/active_support/ordered_hash.rb +23 -2
  96. data/lib/active_support/ordered_options.rb +37 -3
  97. data/lib/active_support/railtie.rb +1 -1
  98. data/lib/active_support/rescuable.rb +1 -0
  99. data/lib/active_support/secure_random.rb +3 -196
  100. data/lib/active_support/test_case.rb +2 -10
  101. data/lib/active_support/testing/assertions.rb +20 -7
  102. data/lib/active_support/testing/mochaing.rb +7 -0
  103. data/lib/active_support/testing/pending.rb +27 -23
  104. data/lib/active_support/testing/performance/jruby.rb +115 -0
  105. data/lib/active_support/testing/performance/rubinius.rb +113 -0
  106. data/lib/active_support/testing/performance/ruby/mri.rb +57 -0
  107. data/lib/active_support/testing/performance/ruby/yarv.rb +57 -0
  108. data/lib/active_support/testing/performance/ruby.rb +152 -0
  109. data/lib/active_support/testing/performance.rb +214 -322
  110. data/lib/active_support/testing/setup_and_teardown.rb +8 -11
  111. data/lib/active_support/time_with_zone.rb +6 -3
  112. data/lib/active_support/values/time_zone.rb +26 -8
  113. data/lib/active_support/version.rb +2 -2
  114. data/lib/active_support/whiny_nil.rb +1 -1
  115. data/lib/active_support/xml_mini/jdom.rb +1 -1
  116. data/lib/active_support/xml_mini/libxml.rb +1 -0
  117. data/lib/active_support/xml_mini/libxmlsax.rb +2 -1
  118. data/lib/active_support/xml_mini/nokogiri.rb +1 -0
  119. data/lib/active_support/xml_mini/nokogirisax.rb +1 -0
  120. data/lib/active_support/xml_mini/rexml.rb +1 -0
  121. data/lib/active_support/xml_mini.rb +8 -3
  122. data/lib/active_support.rb +4 -2
  123. metadata +70 -32
  124. checksums.yaml +0 -7
  125. data/lib/active_support/core_ext/cgi/escape_skipping_slashes.rb +0 -19
  126. data/lib/active_support/core_ext/cgi.rb +0 -1
  127. data/lib/active_support/core_ext/object/returning.rb +0 -43
  128. data/lib/active_support/json/backends/jsongem.rb +0 -47
  129. data/lib/active_support/json/backends/okjson.rb +0 -644
  130. data/lib/active_support/json/backends/yajl.rb +0 -44
  131. data/lib/active_support/json/backends/yaml.rb +0 -19
  132. data/lib/active_support/testing/default.rb +0 -9
data/CHANGELOG CHANGED
@@ -1,48 +1,44 @@
1
- ## Rails 3.0.20 (unreleased)
1
+ *Rails 3.1.0 (unreleased)*
2
2
 
3
- ## Rails 3.0.19 (Jan 8, 2013)
3
+ * ActiveSupport::Dependencies#load and ActiveSupport::Dependencies#require now
4
+ return the value from `super` [Aaron Patterson]
4
5
 
5
- * Hash.from_xml raises when it encounters type="symbol" or type="yaml".
6
- Use Hash.from_trusted_xml to parse this XML.
6
+ * Fixed ActiveSupport::Gzip to work properly in Ruby 1.8 [Guillermo Iguaran]
7
7
 
8
- CVE-2013-0156
8
+ * Kernel.require_library_or_gem was deprecated and will be removed in Rails 3.2.0 [Josh Kalderimis]
9
9
 
10
- *Jeremy Kemper*
10
+ * ActiveSupport::Duration#duplicable? was fixed for Ruby 1.8 [thedarkone]
11
11
 
12
- ## Rails 3.0.18 (Jan 2, 2013)
12
+ * ActiveSupport::BufferedLogger set log encoding to BINARY, but still use text
13
+ mode to output portable newlines. [fxn]
13
14
 
14
- * No changes.
15
-
16
- ## Rails 3.0.17 (Aug 9, 2012)
17
-
18
- * ERB::Util.html_escape now escapes single quotes. [Santiago Pastorino]
19
-
20
- ## Rails 3.0.16 (Jul 26, 2012)
21
-
22
- * No changes.
15
+ * ActiveSupport::Dependencies now raises NameError if it finds an existing constant in load_missing_constant. This better reflects the nature of the error which is usually caused by calling constantize on a nested constant. [Andrew White]
23
16
 
24
- ## Rails 3.0.14 (Jun 12, 2012)
17
+ * Deprecated ActiveSupport::SecureRandom in favour of SecureRandom from the standard library [Jon Leighton]
25
18
 
26
- * No changes.
19
+ * New reporting method Kernel#quietly. [fxn]
27
20
 
28
- * Rails 3.0.13 (May 31, 2012)
21
+ * Add String#inquiry as a convenience method for turning a string into a StringInquirer object [DHH]
29
22
 
30
- * Stop SafeBuffer#clone_empty from issuing warnings
23
+ * Add Object#in? to test if an object is included in another object [Prem Sichanugrist, Brian Morearty, John Reitano]
31
24
 
32
- * Rails 3.0.10 (August 16, 2011)
25
+ * LocalCache strategy is now a real middleware class, not an anonymous class
26
+ posing for pictures.
33
27
 
34
- * Delayed backtrace scrubbing in `load_missing_constant` until we actually
35
- raise the exception
28
+ * ActiveSupport::Dependencies::ClassCache class has been introduced for
29
+ holding references to reloadable classes.
36
30
 
31
+ * ActiveSupport::Dependencies::Reference has been refactored to take direct
32
+ advantage of the new ClassCache.
37
33
 
38
- *Rails 3.0.9 (June 16, 2011)*
34
+ * Backports Range#cover? as an alias for Range#include? in Ruby 1.8 [Diego Carrion, fxn]
39
35
 
40
- *No changes.
36
+ * Added weeks_ago and prev_week to Date/DateTime/Time. [Rob Zolkos, fxn]
41
37
 
38
+ * Added before_remove_const callback to ActiveSupport::Dependencies.remove_unloadable_constants! [Andrew White]
42
39
 
43
- *Rails 3.0.8 (June 7, 2011)*
40
+ * JSON decoding now uses the multi_json gem which also vendors a json engine called OkJson. The yaml backend has been removed in favor of OkJson as a default engine for 1.8.x, while the built in 1.9.x json implementation will be used by default. [Josh Kalderimis]
44
41
 
45
- * No changes.
46
42
 
47
43
  *Rails 3.0.7 (April 18, 2011)*
48
44
 
@@ -76,7 +72,7 @@
76
72
 
77
73
  *Rails 3.0.1 (October 15, 2010)*
78
74
 
79
- * No changes.
75
+ * No Changes, just a version bump.
80
76
 
81
77
 
82
78
  *Rails 3.0.0 (August 29, 2010)*
data/README.rdoc CHANGED
@@ -14,7 +14,7 @@ The latest version of Active Support can be installed with Rubygems:
14
14
 
15
15
  Source code can be downloaded as part of the Rails project on GitHub
16
16
 
17
- * http://github.com/rails/rails/tree/master/activesupport/
17
+ * https://github.com/rails/rails/tree/master/activesupport
18
18
 
19
19
 
20
20
  == License
@@ -30,4 +30,4 @@ API documentation is at
30
30
 
31
31
  Bug reports and feature requests can be filed with the rest for the Ruby on Rails project here:
32
32
 
33
- * https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets
33
+ * https://github.com/rails/rails/issues
@@ -1,27 +1,32 @@
1
1
  module ActiveSupport
2
- # Many backtraces include too much information that's not relevant for the context. This makes it hard to find the signal
3
- # in the backtrace and adds debugging time. With a BacktraceCleaner, you can setup filters and silencers for your particular
4
- # context, so only the relevant lines are included.
2
+ # Backtraces often include many lines that are not relevant for the context under review. This makes it hard to find the
3
+ # signal amongst the backtrace noise, and adds debugging time. With a BacktraceCleaner, filters and silencers are used to
4
+ # remove the noisy lines, so that only the most relevant lines remain.
5
5
  #
6
- # If you need to reconfigure an existing BacktraceCleaner, like the one in Rails, to show as much as possible, you can always
7
- # call BacktraceCleaner#remove_silencers! Also, if you need to reconfigure an existing BacktraceCleaner so that it does not
8
- # filter or modify the paths of any lines of the backtrace, you can call BacktraceCleaner#remove_filters! These two methods
9
- # will give you a completely untouched backtrace.
6
+ # Filters are used to modify lines of data, while silencers are used to remove lines entirely. The typical filter use case
7
+ # is to remove lengthy path information from the start of each line, and view file paths relevant to the app directory
8
+ # instead of the file system root. The typical silencer use case is to exclude the output of a noisy library from the
9
+ # backtrace, so that you can focus on the rest.
10
10
  #
11
- # Example:
11
+ # ==== Example:
12
12
  #
13
13
  # bc = BacktraceCleaner.new
14
14
  # bc.add_filter { |line| line.gsub(Rails.root, '') }
15
15
  # bc.add_silencer { |line| line =~ /mongrel|rubygems/ }
16
16
  # bc.clean(exception.backtrace) # will strip the Rails.root prefix and skip any lines from mongrel or rubygems
17
17
  #
18
+ # To reconfigure an existing BacktraceCleaner (like the default one in Rails) and show as much data as possible, you can
19
+ # always call <tt>BacktraceCleaner#remove_silencers!</tt>, which will restore the backtrace to a pristine state. If you
20
+ # need to reconfigure an existing BacktraceCleaner so that it does not filter or modify the paths of any lines of the
21
+ # backtrace, you can call BacktraceCleaner#remove_filters! These two methods will give you a completely untouched backtrace.
22
+ #
18
23
  # Inspired by the Quiet Backtrace gem by Thoughtbot.
19
24
  class BacktraceCleaner
20
25
  def initialize
21
26
  @filters, @silencers = [], []
22
27
  end
23
28
 
24
- # Returns the backtrace after all filters and silencers has been run against it. Filters run first, then silencers.
29
+ # Returns the backtrace after all filters and silencers have been run against it. Filters run first, then silencers.
25
30
  def clean(backtrace, kind = :silent)
26
31
  filtered = filter(backtrace)
27
32
 
@@ -45,8 +50,8 @@ module ActiveSupport
45
50
  @filters << block
46
51
  end
47
52
 
48
- # Adds a silencer from the block provided. If the silencer returns true for a given line, it'll be excluded from the
49
- # clean backtrace.
53
+ # Adds a silencer from the block provided. If the silencer returns true for a given line, it will be excluded from
54
+ # the clean backtrace.
50
55
  #
51
56
  # Example:
52
57
  #
@@ -57,7 +62,7 @@ module ActiveSupport
57
62
  end
58
63
 
59
64
  # Will remove all silencers, but leave in the filters. This is useful if your context of debugging suddenly expands as
60
- # you suspect a bug in the libraries you use.
65
+ # you suspect a bug in one of the libraries you use.
61
66
  def remove_silencers!
62
67
  @silencers = []
63
68
  end
@@ -55,6 +55,13 @@ module ActiveSupport
55
55
  end
56
56
  end
57
57
 
58
+ def open_log(log, mode)
59
+ open(log, mode).tap do |open_log|
60
+ open_log.set_encoding(Encoding::BINARY) if open_log.respond_to?(:set_encoding)
61
+ open_log.sync = true
62
+ end
63
+ end
64
+
58
65
  def add(severity, message = nil, progname = nil, &block)
59
66
  return if @level > severity
60
67
  message = (message || (block && block.call) || progname).to_s
@@ -126,14 +133,5 @@ module ActiveSupport
126
133
  def clear_buffer
127
134
  @buffer.delete(Thread.current)
128
135
  end
129
-
130
- private
131
-
132
- def open_log(log, mode)
133
- open(log, mode).tap do |log|
134
- log.set_encoding(Encoding::BINARY) if log.respond_to?(:set_encoding)
135
- log.sync = true
136
- end
137
- end
138
136
  end
139
137
  end
@@ -1,5 +1,6 @@
1
1
  require 'active_support/core_ext/file/atomic'
2
2
  require 'active_support/core_ext/string/conversions'
3
+ require 'active_support/core_ext/object/inclusion'
3
4
  require 'rack/utils'
4
5
 
5
6
  module ActiveSupport
@@ -15,12 +16,12 @@ module ActiveSupport
15
16
 
16
17
  def initialize(cache_path, options = nil)
17
18
  super(options)
18
- @cache_path = cache_path
19
+ @cache_path = cache_path.to_s
19
20
  extend Strategy::LocalCache
20
21
  end
21
22
 
22
23
  def clear(options = nil)
23
- root_dirs = Dir.entries(cache_path).reject{|f| ['.', '..'].include?(f)}
24
+ root_dirs = Dir.entries(cache_path).reject{|f| f.in?(['.', '..'])}
24
25
  FileUtils.rm_r(root_dirs.collect{|f| File.join(cache_path, f)})
25
26
  end
26
27
 
@@ -161,7 +162,7 @@ module ActiveSupport
161
162
  # Delete empty directories in the cache.
162
163
  def delete_empty_directories(dir)
163
164
  return if dir == cache_path
164
- if Dir.entries(dir).reject{|f| ['.', '..'].include?(f)}.empty?
165
+ if Dir.entries(dir).reject{|f| f.in?(['.', '..'])}.empty?
165
166
  File.delete(dir) rescue nil
166
167
  delete_empty_directories(File.dirname(dir))
167
168
  end
@@ -4,7 +4,9 @@ rescue LoadError => e
4
4
  $stderr.puts "You don't have memcache-client installed in your application. Please add it to your Gemfile and run bundle install"
5
5
  raise e
6
6
  end
7
+
7
8
  require 'digest/md5'
9
+ require 'active_support/core_ext/string/encoding'
8
10
 
9
11
  module ActiveSupport
10
12
  module Cache
@@ -73,7 +75,7 @@ module ActiveSupport
73
75
  def read_multi(*names)
74
76
  options = names.extract_options!
75
77
  options = merged_options(options)
76
- keys_to_names = names.inject({}){|map, name| map[escape_key(namespaced_key(name, options))] = name; map}
78
+ keys_to_names = Hash[names.map{|name| [escape_key(namespaced_key(name, options)), name]}]
77
79
  raw_values = @data.get_multi(keys_to_names.keys, :raw => true)
78
80
  values = {}
79
81
  raw_values.each do |key, value|
@@ -157,8 +159,14 @@ module ActiveSupport
157
159
  end
158
160
 
159
161
  private
162
+
163
+ # Memcache keys are binaries. So we need to force their encoding to binary
164
+ # before applying the regular expression to ensure we are escaping all
165
+ # characters properly.
160
166
  def escape_key(key)
161
- key = key.to_s.gsub(ESCAPE_KEY_CHARS){|match| "%#{match.getbyte(0).to_s(16).upcase}"}
167
+ key = key.to_s.dup
168
+ key = key.force_encoding("BINARY") if key.encoding_aware?
169
+ key = key.gsub(ESCAPE_KEY_CHARS){ |match| "%#{match.getbyte(0).to_s(16).upcase}" }
162
170
  key = "#{key[0, 213]}:md5:#{Digest::MD5.hexdigest(key)}" if key.size > 250
163
171
  key
164
172
  end
@@ -50,34 +50,39 @@ module ActiveSupport
50
50
  end
51
51
  end
52
52
 
53
- # Middleware class can be inserted as a Rack handler to be local cache for the
54
- # duration of request.
55
- def middleware
56
- @middleware ||= begin
57
- klass = Class.new
58
- klass.class_eval(<<-EOS, __FILE__, __LINE__ + 1)
59
- class << self
60
- def name
61
- "ActiveSupport::Cache::Strategy::LocalCache"
62
- end
63
- alias :to_s :name
64
- end
53
+ #--
54
+ # This class wraps up local storage for middlewares. Only the middleware method should
55
+ # construct them.
56
+ class Middleware # :nodoc:
57
+ attr_reader :name, :thread_local_key
65
58
 
66
- def initialize(app)
67
- @app = app
68
- end
59
+ def initialize(name, thread_local_key)
60
+ @name = name
61
+ @thread_local_key = thread_local_key
62
+ @app = nil
63
+ end
69
64
 
70
- def call(env)
71
- Thread.current[:#{thread_local_key}] = LocalStore.new
72
- @app.call(env)
73
- ensure
74
- Thread.current[:#{thread_local_key}] = nil
75
- end
76
- EOS
77
- klass
65
+ def new(app)
66
+ @app = app
67
+ self
68
+ end
69
+
70
+ def call(env)
71
+ Thread.current[thread_local_key] = LocalStore.new
72
+ @app.call(env)
73
+ ensure
74
+ Thread.current[thread_local_key] = nil
78
75
  end
79
76
  end
80
77
 
78
+ # Middleware class can be inserted as a Rack handler to be local cache for the
79
+ # duration of request.
80
+ def middleware
81
+ @middleware ||= Middleware.new(
82
+ "ActiveSupport::Cache::Strategy::LocalCache",
83
+ thread_local_key)
84
+ end
85
+
81
86
  def clear(options = nil) # :nodoc:
82
87
  local_cache.clear(options) if local_cache
83
88
  super
@@ -484,19 +484,20 @@ module ActiveSupport
484
484
  # object responds to +cache_key+. Otherwise, to_param method will be
485
485
  # called. If the key is a Hash, then keys will be sorted alphabetically.
486
486
  def expanded_key(key) # :nodoc:
487
- if key.respond_to?(:cache_key)
488
- key = key.cache_key.to_s
489
- elsif key.is_a?(Array)
487
+ return key.cache_key.to_s if key.respond_to?(:cache_key)
488
+
489
+ case key
490
+ when Array
490
491
  if key.size > 1
491
- key.collect{|element| expanded_key(element)}.to_param
492
+ key = key.collect{|element| expanded_key(element)}
492
493
  else
493
- key.first.to_param
494
+ key = key.first
494
495
  end
495
- elsif key.is_a?(Hash)
496
- key = key.to_a.sort{|a,b| a.first.to_s <=> b.first.to_s}.collect{|k,v| "#{k}=#{v}"}.to_param
497
- else
498
- key = key.to_param
496
+ when Hash
497
+ key = key.sort_by { |k,_| k.to_s }.collect{|k,v| "#{k}=#{v}"}
499
498
  end
499
+
500
+ key.to_param
500
501
  end
501
502
 
502
503
  # Prefix a key with the namespace. Namespace and key will be delimited with a colon.
@@ -589,11 +590,7 @@ module ActiveSupport
589
590
  # Check if the entry is expired. The +expires_in+ parameter can override the
590
591
  # value set when the entry was created.
591
592
  def expired?
592
- if @expires_in && @created_at + @expires_in <= Time.now.to_f
593
- true
594
- else
595
- false
596
- end
593
+ @expires_in && @created_at + @expires_in <= Time.now.to_f
597
594
  end
598
595
 
599
596
  # Set a new time when the entry will expire.