activesupport 5.0.7.2 → 5.1.0.beta1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of activesupport might be problematic. Click here for more details.

Files changed (210) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +215 -820
  3. data/MIT-LICENSE +1 -1
  4. data/README.rdoc +1 -1
  5. data/lib/active_support.rb +8 -4
  6. data/lib/active_support/all.rb +3 -3
  7. data/lib/active_support/array_inquirer.rb +7 -5
  8. data/lib/active_support/backtrace_cleaner.rb +4 -4
  9. data/lib/active_support/benchmarkable.rb +3 -3
  10. data/lib/active_support/builder.rb +1 -1
  11. data/lib/active_support/cache.rb +42 -49
  12. data/lib/active_support/cache/file_store.rb +12 -21
  13. data/lib/active_support/cache/mem_cache_store.rb +30 -40
  14. data/lib/active_support/cache/memory_store.rb +11 -13
  15. data/lib/active_support/cache/null_store.rb +4 -4
  16. data/lib/active_support/cache/strategy/local_cache.rb +16 -25
  17. data/lib/active_support/cache/strategy/local_cache_middleware.rb +8 -9
  18. data/lib/active_support/callbacks.rb +647 -584
  19. data/lib/active_support/concurrency/share_lock.rb +20 -21
  20. data/lib/active_support/configurable.rb +5 -5
  21. data/lib/active_support/core_ext.rb +1 -2
  22. data/lib/active_support/core_ext/array.rb +7 -7
  23. data/lib/active_support/core_ext/array/access.rb +1 -1
  24. data/lib/active_support/core_ext/array/conversions.rb +15 -15
  25. data/lib/active_support/core_ext/array/grouping.rb +1 -1
  26. data/lib/active_support/core_ext/array/inquiry.rb +1 -1
  27. data/lib/active_support/core_ext/array/prepend_and_append.rb +1 -1
  28. data/lib/active_support/core_ext/benchmark.rb +1 -1
  29. data/lib/active_support/core_ext/big_decimal.rb +1 -1
  30. data/lib/active_support/core_ext/big_decimal/conversions.rb +4 -6
  31. data/lib/active_support/core_ext/class.rb +2 -2
  32. data/lib/active_support/core_ext/class/attribute.rb +5 -5
  33. data/lib/active_support/core_ext/class/attribute_accessors.rb +1 -1
  34. data/lib/active_support/core_ext/class/subclasses.rb +18 -4
  35. data/lib/active_support/core_ext/date.rb +5 -5
  36. data/lib/active_support/core_ext/date/acts_like.rb +1 -1
  37. data/lib/active_support/core_ext/date/blank.rb +1 -1
  38. data/lib/active_support/core_ext/date/calculations.rb +8 -8
  39. data/lib/active_support/core_ext/date/conversions.rb +12 -12
  40. data/lib/active_support/core_ext/date/zones.rb +2 -2
  41. data/lib/active_support/core_ext/date_and_time/calculations.rb +27 -22
  42. data/lib/active_support/core_ext/date_and_time/compatibility.rb +9 -1
  43. data/lib/active_support/core_ext/date_and_time/zones.rb +7 -8
  44. data/lib/active_support/core_ext/date_time.rb +5 -5
  45. data/lib/active_support/core_ext/date_time/acts_like.rb +2 -2
  46. data/lib/active_support/core_ext/date_time/blank.rb +1 -1
  47. data/lib/active_support/core_ext/date_time/calculations.rb +9 -9
  48. data/lib/active_support/core_ext/date_time/compatibility.rb +2 -13
  49. data/lib/active_support/core_ext/date_time/conversions.rb +12 -12
  50. data/lib/active_support/core_ext/digest/uuid.rb +4 -4
  51. data/lib/active_support/core_ext/enumerable.rb +46 -57
  52. data/lib/active_support/core_ext/file.rb +1 -1
  53. data/lib/active_support/core_ext/file/atomic.rb +4 -4
  54. data/lib/active_support/core_ext/hash.rb +9 -9
  55. data/lib/active_support/core_ext/hash/compact.rb +12 -9
  56. data/lib/active_support/core_ext/hash/conversions.rb +36 -37
  57. data/lib/active_support/core_ext/hash/indifferent_access.rb +1 -2
  58. data/lib/active_support/core_ext/hash/keys.rb +8 -8
  59. data/lib/active_support/core_ext/hash/reverse_merge.rb +1 -1
  60. data/lib/active_support/core_ext/hash/slice.rb +4 -4
  61. data/lib/active_support/core_ext/hash/transform_values.rb +1 -0
  62. data/lib/active_support/core_ext/integer.rb +3 -3
  63. data/lib/active_support/core_ext/integer/inflections.rb +1 -1
  64. data/lib/active_support/core_ext/integer/time.rb +2 -2
  65. data/lib/active_support/core_ext/kernel.rb +4 -4
  66. data/lib/active_support/core_ext/kernel/concern.rb +1 -1
  67. data/lib/active_support/core_ext/kernel/reporting.rb +1 -1
  68. data/lib/active_support/core_ext/load_error.rb +1 -18
  69. data/lib/active_support/core_ext/marshal.rb +2 -2
  70. data/lib/active_support/core_ext/module.rb +11 -12
  71. data/lib/active_support/core_ext/module/aliasing.rb +3 -48
  72. data/lib/active_support/core_ext/module/attr_internal.rb +4 -4
  73. data/lib/active_support/core_ext/module/attribute_accessors.rb +11 -5
  74. data/lib/active_support/core_ext/module/attribute_accessors_per_thread.rb +20 -13
  75. data/lib/active_support/core_ext/module/concerning.rb +1 -1
  76. data/lib/active_support/core_ext/module/delegation.rb +82 -16
  77. data/lib/active_support/core_ext/module/introspection.rb +3 -11
  78. data/lib/active_support/core_ext/module/reachable.rb +2 -2
  79. data/lib/active_support/core_ext/numeric.rb +4 -4
  80. data/lib/active_support/core_ext/numeric/conversions.rb +3 -9
  81. data/lib/active_support/core_ext/numeric/inquiry.rb +21 -21
  82. data/lib/active_support/core_ext/numeric/time.rb +5 -5
  83. data/lib/active_support/core_ext/object.rb +12 -12
  84. data/lib/active_support/core_ext/object/blank.rb +3 -1
  85. data/lib/active_support/core_ext/object/conversions.rb +4 -4
  86. data/lib/active_support/core_ext/object/deep_dup.rb +1 -1
  87. data/lib/active_support/core_ext/object/duplicable.rb +24 -4
  88. data/lib/active_support/core_ext/object/inclusion.rb +1 -1
  89. data/lib/active_support/core_ext/object/json.rb +26 -12
  90. data/lib/active_support/core_ext/object/to_param.rb +1 -1
  91. data/lib/active_support/core_ext/object/to_query.rb +4 -4
  92. data/lib/active_support/core_ext/object/try.rb +1 -1
  93. data/lib/active_support/core_ext/object/with_options.rb +1 -1
  94. data/lib/active_support/core_ext/range.rb +4 -4
  95. data/lib/active_support/core_ext/range/conversions.rb +1 -1
  96. data/lib/active_support/core_ext/regexp.rb +4 -0
  97. data/lib/active_support/core_ext/securerandom.rb +3 -3
  98. data/lib/active_support/core_ext/string.rb +13 -13
  99. data/lib/active_support/core_ext/string/access.rb +6 -6
  100. data/lib/active_support/core_ext/string/conversions.rb +2 -2
  101. data/lib/active_support/core_ext/string/filters.rb +3 -3
  102. data/lib/active_support/core_ext/string/indent.rb +4 -4
  103. data/lib/active_support/core_ext/string/inflections.rb +10 -14
  104. data/lib/active_support/core_ext/string/inquiry.rb +1 -1
  105. data/lib/active_support/core_ext/string/multibyte.rb +1 -1
  106. data/lib/active_support/core_ext/string/output_safety.rb +19 -20
  107. data/lib/active_support/core_ext/string/strip.rb +1 -1
  108. data/lib/active_support/core_ext/string/zones.rb +2 -2
  109. data/lib/active_support/core_ext/time.rb +5 -5
  110. data/lib/active_support/core_ext/time/acts_like.rb +1 -1
  111. data/lib/active_support/core_ext/time/calculations.rb +23 -29
  112. data/lib/active_support/core_ext/time/compatibility.rb +1 -10
  113. data/lib/active_support/core_ext/time/conversions.rb +12 -12
  114. data/lib/active_support/core_ext/time/zones.rb +3 -3
  115. data/lib/active_support/core_ext/uri.rb +2 -2
  116. data/lib/active_support/dependencies.rb +45 -47
  117. data/lib/active_support/dependencies/interlock.rb +1 -1
  118. data/lib/active_support/deprecation.rb +8 -8
  119. data/lib/active_support/deprecation/behaviors.rb +3 -3
  120. data/lib/active_support/deprecation/instance_delegator.rb +2 -2
  121. data/lib/active_support/deprecation/method_wrappers.rb +3 -3
  122. data/lib/active_support/deprecation/proxy_wrappers.rb +6 -4
  123. data/lib/active_support/deprecation/reporting.rb +7 -7
  124. data/lib/active_support/duration.rb +30 -26
  125. data/lib/active_support/duration/iso8601_parser.rb +66 -65
  126. data/lib/active_support/duration/iso8601_serializer.rb +11 -9
  127. data/lib/active_support/evented_file_update_checker.rb +59 -60
  128. data/lib/active_support/execution_wrapper.rb +3 -3
  129. data/lib/active_support/executor.rb +1 -1
  130. data/lib/active_support/file_update_checker.rb +54 -50
  131. data/lib/active_support/gem_version.rb +3 -3
  132. data/lib/active_support/gzip.rb +5 -5
  133. data/lib/active_support/hash_with_indifferent_access.rb +10 -20
  134. data/lib/active_support/i18n.rb +5 -5
  135. data/lib/active_support/i18n_railtie.rb +11 -10
  136. data/lib/active_support/inflections.rb +11 -11
  137. data/lib/active_support/inflector.rb +5 -5
  138. data/lib/active_support/inflector/inflections.rb +11 -9
  139. data/lib/active_support/inflector/methods.rb +51 -50
  140. data/lib/active_support/inflector/transliterate.rb +8 -11
  141. data/lib/active_support/json.rb +2 -2
  142. data/lib/active_support/json/decoding.rb +3 -3
  143. data/lib/active_support/json/encoding.rb +8 -7
  144. data/lib/active_support/key_generator.rb +17 -17
  145. data/lib/active_support/lazy_load_hooks.rb +12 -30
  146. data/lib/active_support/log_subscriber.rb +5 -5
  147. data/lib/active_support/log_subscriber/test_helper.rb +9 -9
  148. data/lib/active_support/logger.rb +3 -3
  149. data/lib/active_support/logger_silence.rb +3 -3
  150. data/lib/active_support/logger_thread_safe_level.rb +1 -1
  151. data/lib/active_support/message_encryptor.rb +72 -35
  152. data/lib/active_support/message_verifier.rb +7 -7
  153. data/lib/active_support/multibyte.rb +2 -2
  154. data/lib/active_support/multibyte/chars.rb +23 -21
  155. data/lib/active_support/multibyte/unicode.rb +68 -89
  156. data/lib/active_support/notifications.rb +5 -5
  157. data/lib/active_support/notifications/fanout.rb +3 -3
  158. data/lib/active_support/notifications/instrumenter.rb +5 -5
  159. data/lib/active_support/number_helper.rb +4 -4
  160. data/lib/active_support/number_helper/number_converter.rb +11 -11
  161. data/lib/active_support/number_helper/number_to_currency_converter.rb +3 -3
  162. data/lib/active_support/number_helper/number_to_delimited_converter.rb +1 -2
  163. data/lib/active_support/number_helper/number_to_human_converter.rb +6 -6
  164. data/lib/active_support/number_helper/number_to_human_size_converter.rb +6 -11
  165. data/lib/active_support/number_helper/number_to_percentage_converter.rb +1 -1
  166. data/lib/active_support/number_helper/number_to_phone_converter.rb +1 -3
  167. data/lib/active_support/number_helper/number_to_rounded_converter.rb +6 -6
  168. data/lib/active_support/option_merger.rb +1 -1
  169. data/lib/active_support/ordered_hash.rb +3 -3
  170. data/lib/active_support/ordered_options.rb +6 -4
  171. data/lib/active_support/per_thread_registry.rb +5 -5
  172. data/lib/active_support/rails.rb +12 -6
  173. data/lib/active_support/railtie.rb +3 -3
  174. data/lib/active_support/reloader.rb +1 -1
  175. data/lib/active_support/rescuable.rb +8 -14
  176. data/lib/active_support/security_utils.rb +1 -1
  177. data/lib/active_support/string_inquirer.rb +8 -2
  178. data/lib/active_support/subscriber.rb +9 -5
  179. data/lib/active_support/tagged_logging.rb +4 -4
  180. data/lib/active_support/test_case.rb +12 -29
  181. data/lib/active_support/testing/assertions.rb +100 -2
  182. data/lib/active_support/testing/autorun.rb +6 -2
  183. data/lib/active_support/testing/constant_lookup.rb +0 -1
  184. data/lib/active_support/testing/declarative.rb +1 -1
  185. data/lib/active_support/testing/deprecation.rb +3 -2
  186. data/lib/active_support/testing/isolation.rb +13 -22
  187. data/lib/active_support/testing/method_call_assertions.rb +1 -1
  188. data/lib/active_support/testing/setup_and_teardown.rb +2 -2
  189. data/lib/active_support/testing/stream.rb +28 -28
  190. data/lib/active_support/testing/tagged_logging.rb +1 -1
  191. data/lib/active_support/testing/time_helpers.rb +45 -12
  192. data/lib/active_support/time.rb +12 -12
  193. data/lib/active_support/time_with_zone.rb +16 -26
  194. data/lib/active_support/values/time_zone.rb +40 -46
  195. data/lib/active_support/values/unicode_tables.dat +0 -0
  196. data/lib/active_support/version.rb +1 -1
  197. data/lib/active_support/xml_mini.rb +34 -36
  198. data/lib/active_support/xml_mini/jdom.rb +112 -112
  199. data/lib/active_support/xml_mini/libxml.rb +15 -12
  200. data/lib/active_support/xml_mini/libxmlsax.rb +17 -15
  201. data/lib/active_support/xml_mini/nokogiri.rb +13 -11
  202. data/lib/active_support/xml_mini/nokogirisax.rb +15 -14
  203. data/lib/active_support/xml_mini/rexml.rb +9 -9
  204. metadata +8 -19
  205. data/lib/active_support/concurrency/latch.rb +0 -26
  206. data/lib/active_support/core_ext/kernel/debugger.rb +0 -3
  207. data/lib/active_support/core_ext/module/method_transplanting.rb +0 -3
  208. data/lib/active_support/core_ext/module/qualified_const.rb +0 -70
  209. data/lib/active_support/core_ext/struct.rb +0 -3
  210. data/lib/active_support/core_ext/time/marshal.rb +0 -3
@@ -1,4 +1,4 @@
1
- Copyright (c) 2005-2016 David Heinemeier Hansson
1
+ Copyright (c) 2005-2017 David Heinemeier Hansson
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
@@ -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
- * https://github.com/rails/rails/tree/5-0-stable/activesupport
17
+ * https://github.com/rails/rails/tree/master/activesupport
18
18
 
19
19
 
20
20
  == License
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2005-2016 David Heinemeier Hansson
2
+ # Copyright (c) 2005-2017 David Heinemeier Hansson
3
3
  #
4
4
  # Permission is hereby granted, free of charge, to any person obtaining
5
5
  # a copy of this software and associated documentation files (the
@@ -21,7 +21,7 @@
21
21
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
22
  #++
23
23
 
24
- require 'securerandom'
24
+ require "securerandom"
25
25
  require "active_support/dependencies/autoload"
26
26
  require "active_support/version"
27
27
  require "active_support/logger"
@@ -80,11 +80,15 @@ module ActiveSupport
80
80
  cattr_accessor :test_order # :nodoc:
81
81
 
82
82
  def self.halt_callback_chains_on_return_false
83
- Callbacks.halt_and_display_warning_on_return_false
83
+ ActiveSupport::Deprecation.warn(<<-MSG.squish)
84
+ ActiveSupport.halt_callback_chains_on_return_false is deprecated and will be removed in Rails 5.2.
85
+ MSG
84
86
  end
85
87
 
86
88
  def self.halt_callback_chains_on_return_false=(value)
87
- Callbacks.halt_and_display_warning_on_return_false = value
89
+ ActiveSupport::Deprecation.warn(<<-MSG.squish)
90
+ ActiveSupport.halt_callback_chains_on_return_false= is deprecated and will be removed in Rails 5.2.
91
+ MSG
88
92
  end
89
93
 
90
94
  def self.to_time_preserves_timezone
@@ -1,3 +1,3 @@
1
- require 'active_support'
2
- require 'active_support/time'
3
- require 'active_support/core_ext'
1
+ require "active_support"
2
+ require "active_support/time"
3
+ require "active_support/core_ext"
@@ -9,8 +9,10 @@ module ActiveSupport
9
9
  # variants.desktop? # => false
10
10
  class ArrayInquirer < Array
11
11
  # Passes each element of +candidates+ collection to ArrayInquirer collection.
12
- # The method returns true if at least one element is the same. If +candidates+
13
- # collection is not given, method returns true.
12
+ # The method returns true if any element from the ArrayInquirer collection
13
+ # is equal to the stringified or symbolized form of any element in the +candidates+ collection.
14
+ #
15
+ # If +candidates+ collection is not given, method returns true.
14
16
  #
15
17
  # variants = ActiveSupport::ArrayInquirer.new([:phone, :tablet])
16
18
  #
@@ -18,7 +20,7 @@ module ActiveSupport
18
20
  # variants.any?(:phone, :tablet) # => true
19
21
  # variants.any?('phone', 'desktop') # => true
20
22
  # variants.any?(:desktop, :watch) # => false
21
- def any?(*candidates, &block)
23
+ def any?(*candidates)
22
24
  if candidates.none?
23
25
  super
24
26
  else
@@ -30,11 +32,11 @@ module ActiveSupport
30
32
 
31
33
  private
32
34
  def respond_to_missing?(name, include_private = false)
33
- name[-1] == '?'
35
+ (name[-1] == "?") || super
34
36
  end
35
37
 
36
38
  def method_missing(name, *args)
37
- if name[-1] == '?'
39
+ if name[-1] == "?"
38
40
  any?(name[0..-2])
39
41
  else
40
42
  super
@@ -12,9 +12,9 @@ module ActiveSupport
12
12
  # is to exclude the output of a noisy library from the backtrace, so that you
13
13
  # can focus on the rest.
14
14
  #
15
- # bc = BacktraceCleaner.new
15
+ # bc = ActiveSupport::BacktraceCleaner.new
16
16
  # bc.add_filter { |line| line.gsub(Rails.root.to_s, '') } # strip the Rails.root prefix
17
- # bc.add_silencer { |line| line =~ /mongrel|rubygems/ } # skip any lines from mongrel or rubygems
17
+ # bc.add_silencer { |line| line =~ /puma|rubygems/ } # skip any lines from puma or rubygems
18
18
  # bc.clean(exception.backtrace) # perform the cleanup
19
19
  #
20
20
  # To reconfigure an existing BacktraceCleaner (like the default one in Rails)
@@ -59,8 +59,8 @@ module ActiveSupport
59
59
  # Adds a silencer from the block provided. If the silencer returns +true+
60
60
  # for a given line, it will be excluded from the clean backtrace.
61
61
  #
62
- # # Will reject all lines that include the word "mongrel", like "/gems/mongrel/server.rb" or "/app/my_mongrel_server/rb"
63
- # backtrace_cleaner.add_silencer { |line| line =~ /mongrel/ }
62
+ # # Will reject all lines that include the word "puma", like "/gems/puma/server.rb" or "/app/my_puma_server/rb"
63
+ # backtrace_cleaner.add_silencer { |line| line =~ /puma/ }
64
64
  def add_silencer(&block)
65
65
  @silencers << block
66
66
  end
@@ -1,5 +1,5 @@
1
- require 'active_support/core_ext/benchmark'
2
- require 'active_support/core_ext/hash/keys'
1
+ require "active_support/core_ext/benchmark"
2
+ require "active_support/core_ext/hash/keys"
3
3
 
4
4
  module ActiveSupport
5
5
  module Benchmarkable
@@ -39,7 +39,7 @@ module ActiveSupport
39
39
 
40
40
  result = nil
41
41
  ms = Benchmark.ms { result = options[:silence] ? logger.silence { yield } : yield }
42
- logger.send(options[:level], '%s (%.1fms)' % [ message, ms ])
42
+ logger.send(options[:level], "%s (%.1fms)" % [ message, ms ])
43
43
  result
44
44
  else
45
45
  yield
@@ -1,5 +1,5 @@
1
1
  begin
2
- require 'builder'
2
+ require "builder"
3
3
  rescue LoadError => e
4
4
  $stderr.puts "You don't have builder installed in your application. Please add it to your Gemfile and run bundle install"
5
5
  raise e
@@ -1,29 +1,26 @@
1
- require 'benchmark'
2
- require 'zlib'
3
- require 'active_support/core_ext/array/extract_options'
4
- require 'active_support/core_ext/array/wrap'
5
- require 'active_support/core_ext/benchmark'
6
- require 'active_support/core_ext/module/attribute_accessors'
7
- require 'active_support/core_ext/numeric/bytes'
8
- require 'active_support/core_ext/numeric/time'
9
- require 'active_support/core_ext/object/to_param'
10
- require 'active_support/core_ext/string/inflections'
11
- require 'active_support/core_ext/string/strip'
1
+ require "zlib"
2
+ require "active_support/core_ext/array/extract_options"
3
+ require "active_support/core_ext/array/wrap"
4
+ require "active_support/core_ext/module/attribute_accessors"
5
+ require "active_support/core_ext/numeric/bytes"
6
+ require "active_support/core_ext/numeric/time"
7
+ require "active_support/core_ext/object/to_param"
8
+ require "active_support/core_ext/string/inflections"
12
9
 
13
10
  module ActiveSupport
14
11
  # See ActiveSupport::Cache::Store for documentation.
15
12
  module Cache
16
- autoload :FileStore, 'active_support/cache/file_store'
17
- autoload :MemoryStore, 'active_support/cache/memory_store'
18
- autoload :MemCacheStore, 'active_support/cache/mem_cache_store'
19
- autoload :NullStore, 'active_support/cache/null_store'
13
+ autoload :FileStore, "active_support/cache/file_store"
14
+ autoload :MemoryStore, "active_support/cache/memory_store"
15
+ autoload :MemCacheStore, "active_support/cache/mem_cache_store"
16
+ autoload :NullStore, "active_support/cache/null_store"
20
17
 
21
18
  # These options mean something to all cache implementations. Individual cache
22
19
  # implementations may support additional options.
23
20
  UNIVERSAL_OPTIONS = [:namespace, :compress, :compress_threshold, :expires_in, :race_condition_ttl]
24
21
 
25
22
  module Strategy
26
- autoload :LocalCache, 'active_support/cache/strategy/local_cache'
23
+ autoload :LocalCache, "active_support/cache/strategy/local_cache"
27
24
  end
28
25
 
29
26
  class << self
@@ -73,8 +70,8 @@ module ActiveSupport
73
70
  # each of elements in the array will be turned into parameters/keys and
74
71
  # concatenated into a single key. For example:
75
72
  #
76
- # expand_cache_key([:foo, :bar]) # => "foo/bar"
77
- # expand_cache_key([:foo, :bar], "namespace") # => "namespace/foo/bar"
73
+ # ActiveSupport::Cache.expand_cache_key([:foo, :bar]) # => "foo/bar"
74
+ # ActiveSupport::Cache.expand_cache_key([:foo, :bar], "namespace") # => "namespace/foo/bar"
78
75
  #
79
76
  # The +key+ argument can also respond to +cache_key+ or +to_param+.
80
77
  def expand_cache_key(key, namespace = nil)
@@ -153,7 +150,7 @@ module ActiveSupport
153
150
  # or +write+. To specify the threshold at which to compress values, set the
154
151
  # <tt>:compress_threshold</tt> option. The default threshold is 16K.
155
152
  class Store
156
- cattr_accessor :logger, :instance_writer => true
153
+ cattr_accessor :logger, instance_writer: true
157
154
 
158
155
  attr_reader :silence, :options
159
156
  alias :silence? :silence
@@ -200,15 +197,15 @@ module ActiveSupport
200
197
  # You may also specify additional options via the +options+ argument.
201
198
  # Setting <tt>force: true</tt> forces a cache "miss," meaning we treat
202
199
  # the cache value as missing even if it's present. Passing a block is
203
- # required when `force` is true so this always results in a cache write.
200
+ # required when +force+ is true so this always results in a cache write.
204
201
  #
205
202
  # cache.write('today', 'Monday')
206
203
  # cache.fetch('today', force: true) { 'Tuesday' } # => 'Tuesday'
207
204
  # cache.fetch('today', force: true) # => ArgumentError
208
205
  #
209
- # The `:force` option is useful when you're calling some other method to
206
+ # The +:force+ option is useful when you're calling some other method to
210
207
  # ask whether you should force a cache write. Otherwise, it's clearer to
211
- # just call `Cache#write`.
208
+ # just call <tt>Cache#write</tt>.
212
209
  #
213
210
  # Setting <tt>:compress</tt> will store a large cache entry set by the call
214
211
  # in a compressed format.
@@ -250,14 +247,14 @@ module ActiveSupport
250
247
  # sleep 60
251
248
  #
252
249
  # Thread.new do
253
- # val_1 = cache.fetch('foo', race_condition_ttl: 10) do
250
+ # val_1 = cache.fetch('foo', race_condition_ttl: 10.seconds) do
254
251
  # sleep 1
255
252
  # 'new value 1'
256
253
  # end
257
254
  # end
258
255
  #
259
256
  # Thread.new do
260
- # val_2 = cache.fetch('foo', race_condition_ttl: 10) do
257
+ # val_2 = cache.fetch('foo', race_condition_ttl: 10.seconds) do
261
258
  # 'new value 2'
262
259
  # end
263
260
  # end
@@ -300,7 +297,7 @@ module ActiveSupport
300
297
  save_block_result_to_cache(name, options) { |_name| yield _name }
301
298
  end
302
299
  elsif options && options[:force]
303
- raise ArgumentError, 'Missing block: Calling `Cache#fetch` with `force: true` requires a block.'
300
+ raise ArgumentError, "Missing block: Calling `Cache#fetch` with `force: true` requires a block."
304
301
  else
305
302
  read(name, options)
306
303
  end
@@ -361,6 +358,9 @@ module ActiveSupport
361
358
  # the cache with the given keys, then that data is returned. Otherwise,
362
359
  # the supplied block is called for each key for which there was no data,
363
360
  # and the result will be written to the cache and returned.
361
+ # Therefore, you need to pass a block that returns the data to be written
362
+ # to the cache. If you do not want to write the cache when the cache is
363
+ # not found, use #read_multi.
364
364
  #
365
365
  # Options are passed to the underlying cache implementation.
366
366
  #
@@ -374,6 +374,8 @@ module ActiveSupport
374
374
  # # "unknown_key" => "Fallback value for key: unknown_key" }
375
375
  #
376
376
  def fetch_multi(*names)
377
+ raise ArgumentError, "Missing block: `Cache#fetch_multi` requires a block." unless block_given?
378
+
377
379
  options = names.extract_options!
378
380
  options = merged_options(options)
379
381
  results = read_multi(*names, options)
@@ -464,20 +466,20 @@ module ActiveSupport
464
466
  # The options hash is passed to the underlying cache implementation.
465
467
  #
466
468
  # All implementations may not support this method.
467
- def clear(options = nil)
469
+ def clear
468
470
  raise NotImplementedError.new("#{self.class.name} does not support clear")
469
471
  end
470
472
 
471
- protected
473
+ private
472
474
  # Adds the namespace defined in the options to a pattern designed to
473
475
  # match keys. Implementations that support delete_matched should call
474
476
  # this method to translate a pattern that matches names into one that
475
477
  # matches namespaced keys.
476
- def key_matcher(pattern, options)
478
+ def key_matcher(pattern, options) # :doc:
477
479
  prefix = options[:namespace].is_a?(Proc) ? options[:namespace].call : options[:namespace]
478
480
  if prefix
479
481
  source = pattern.source
480
- if source.start_with?('^')
482
+ if source.start_with?("^")
481
483
  source = source[1, source.length]
482
484
  else
483
485
  source = ".*#{source[0, source.length]}"
@@ -490,25 +492,24 @@ module ActiveSupport
490
492
 
491
493
  # Reads an entry from the cache implementation. Subclasses must implement
492
494
  # this method.
493
- def read_entry(key, options) # :nodoc:
495
+ def read_entry(key, options)
494
496
  raise NotImplementedError.new
495
497
  end
496
498
 
497
499
  # Writes an entry to the cache implementation. Subclasses must implement
498
500
  # this method.
499
- def write_entry(key, entry, options) # :nodoc:
501
+ def write_entry(key, entry, options)
500
502
  raise NotImplementedError.new
501
503
  end
502
504
 
503
505
  # Deletes an entry from the cache implementation. Subclasses must
504
506
  # implement this method.
505
- def delete_entry(key, options) # :nodoc:
507
+ def delete_entry(key, options)
506
508
  raise NotImplementedError.new
507
509
  end
508
510
 
509
- private
510
511
  # Merges the default options with ones specific to a method call.
511
- def merged_options(call_options) # :nodoc:
512
+ def merged_options(call_options)
512
513
  if call_options
513
514
  options.merge(call_options)
514
515
  else
@@ -519,18 +520,18 @@ module ActiveSupport
519
520
  # Expands key to be a consistent string value. Invokes +cache_key+ if
520
521
  # object responds to +cache_key+. Otherwise, +to_param+ method will be
521
522
  # called. If the key is a Hash, then keys will be sorted alphabetically.
522
- def expanded_key(key) # :nodoc:
523
+ def expanded_key(key)
523
524
  return key.cache_key.to_s if key.respond_to?(:cache_key)
524
525
 
525
526
  case key
526
527
  when Array
527
528
  if key.size > 1
528
- key = key.collect{|element| expanded_key(element)}
529
+ key = key.collect { |element| expanded_key(element) }
529
530
  else
530
531
  key = key.first
531
532
  end
532
533
  when Hash
533
- key = key.sort_by { |k,_| k.to_s }.collect{|k,v| "#{k}=#{v}"}
534
+ key = key.sort_by { |k, _| k.to_s }.collect { |k, v| "#{k}=#{v}" }
534
535
  end
535
536
 
536
537
  key.to_param
@@ -546,20 +547,12 @@ module ActiveSupport
546
547
  key
547
548
  end
548
549
 
549
- def namespaced_key(*args)
550
- ActiveSupport::Deprecation.warn(<<-MESSAGE.strip_heredoc)
551
- `namespaced_key` is deprecated and will be removed from Rails 5.1.
552
- Please use `normalize_key` which will return a fully resolved key.
553
- MESSAGE
554
- normalize_key(*args)
555
- end
556
-
557
550
  def instrument(operation, key, options = nil)
558
551
  log { "Cache #{operation}: #{normalize_key(key, options)}#{options.blank? ? "" : " (#{options.inspect})"}" }
559
552
 
560
- payload = { :key => key }
553
+ payload = { key: key }
561
554
  payload.merge!(options) if options.is_a?(Hash)
562
- ActiveSupport::Notifications.instrument("cache_#{operation}.active_support", payload){ yield(payload) }
555
+ ActiveSupport::Notifications.instrument("cache_#{operation}.active_support", payload) { yield(payload) }
563
556
  end
564
557
 
565
558
  def log
@@ -574,7 +567,7 @@ module ActiveSupport
574
567
  # When an entry has a positive :race_condition_ttl defined, put the stale entry back into the cache
575
568
  # for a brief period while the entry is being recalculated.
576
569
  entry.expires_at = Time.now + race_ttl
577
- write_entry(key, entry, :expires_in => race_ttl * 2)
570
+ write_entry(key, entry, expires_in: race_ttl * 2)
578
571
  else
579
572
  delete_entry(key, options)
580
573
  end
@@ -584,7 +577,7 @@ module ActiveSupport
584
577
  end
585
578
 
586
579
  def get_entry_value(entry, name, options)
587
- instrument(:fetch_hit, name, options) { }
580
+ instrument(:fetch_hit, name, options) {}
588
581
  entry.value
589
582
  end
590
583
 
@@ -1,7 +1,7 @@
1
- require 'active_support/core_ext/marshal'
2
- require 'active_support/core_ext/file/atomic'
3
- require 'active_support/core_ext/string/conversions'
4
- require 'uri/common'
1
+ require "active_support/core_ext/marshal"
2
+ require "active_support/core_ext/file/atomic"
3
+ require "active_support/core_ext/string/conversions"
4
+ require "uri/common"
5
5
 
6
6
  module ActiveSupport
7
7
  module Cache
@@ -16,8 +16,8 @@ module ActiveSupport
16
16
  DIR_FORMATTER = "%03X"
17
17
  FILENAME_MAX_SIZE = 228 # max filename size on file system is 255, minus room for timestamp and random characters appended by Tempfile (used by atomic write)
18
18
  FILEPATH_MAX_SIZE = 900 # max is 1024, plus some room
19
- EXCLUDED_DIRS = ['.', '..'].freeze
20
- GITKEEP_FILES = ['.gitkeep', '.keep'].freeze
19
+ EXCLUDED_DIRS = [".", ".."].freeze
20
+ GITKEEP_FILES = [".gitkeep", ".keep"].freeze
21
21
 
22
22
  def initialize(cache_path, options = nil)
23
23
  super(options)
@@ -27,9 +27,9 @@ module ActiveSupport
27
27
  # Deletes all items from the cache. In this case it deletes all the entries in the specified
28
28
  # file store directory except for .keep or .gitkeep. Be careful which directory is specified in your
29
29
  # config file when using +FileStore+ because everything in that directory will be deleted.
30
- def clear(options = nil)
30
+ def clear
31
31
  root_dirs = exclude_from(cache_path, EXCLUDED_DIRS + GITKEEP_FILES)
32
- FileUtils.rm_r(root_dirs.collect{|f| File.join(cache_path, f)})
32
+ FileUtils.rm_r(root_dirs.collect { |f| File.join(cache_path, f) })
33
33
  rescue Errno::ENOENT
34
34
  end
35
35
 
@@ -66,7 +66,7 @@ module ActiveSupport
66
66
  end
67
67
  end
68
68
 
69
- protected
69
+ private
70
70
 
71
71
  def read_entry(key, options)
72
72
  if File.exist?(key)
@@ -80,7 +80,7 @@ module ActiveSupport
80
80
  def write_entry(key, entry, options)
81
81
  return false if options[:unless_exist] && File.exist?(key)
82
82
  ensure_cache_path(File.dirname(key))
83
- File.atomic_write(key, cache_path) {|f| Marshal.dump(entry, f)}
83
+ File.atomic_write(key, cache_path) { |f| Marshal.dump(entry, f) }
84
84
  true
85
85
  end
86
86
 
@@ -98,11 +98,10 @@ module ActiveSupport
98
98
  end
99
99
  end
100
100
 
101
- private
102
101
  # Lock a file for a block so only one process can modify it at a time.
103
- def lock_file(file_name, &block) # :nodoc:
102
+ def lock_file(file_name, &block)
104
103
  if File.exist?(file_name)
105
- File.open(file_name, 'r+') do |f|
104
+ File.open(file_name, "r+") do |f|
106
105
  begin
107
106
  f.flock File::LOCK_EX
108
107
  yield
@@ -138,14 +137,6 @@ module ActiveSupport
138
137
  File.join(cache_path, DIR_FORMATTER % dir_1, DIR_FORMATTER % dir_2, *fname_paths)
139
138
  end
140
139
 
141
- def key_file_path(key)
142
- ActiveSupport::Deprecation.warn(<<-MESSAGE.strip_heredoc)
143
- `key_file_path` is deprecated and will be removed from Rails 5.1.
144
- Please use `normalize_key` which will return a fully resolved key or nothing.
145
- MESSAGE
146
- key
147
- end
148
-
149
140
  # Translate a file path into a key.
150
141
  def file_path_key(path)
151
142
  fname = path[cache_path.to_s.size..-1].split(File::SEPARATOR, 4).last