activesupport 4.2.11.1 → 6.0.3.1

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 (263) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +399 -411
  3. data/MIT-LICENSE +2 -2
  4. data/README.rdoc +7 -7
  5. data/lib/active_support/actionable_error.rb +48 -0
  6. data/lib/active_support/all.rb +5 -3
  7. data/lib/active_support/array_inquirer.rb +48 -0
  8. data/lib/active_support/backtrace_cleaner.rb +34 -6
  9. data/lib/active_support/benchmarkable.rb +6 -4
  10. data/lib/active_support/builder.rb +3 -1
  11. data/lib/active_support/cache/file_store.rb +58 -53
  12. data/lib/active_support/cache/mem_cache_store.rb +95 -91
  13. data/lib/active_support/cache/memory_store.rb +39 -36
  14. data/lib/active_support/cache/null_store.rb +11 -7
  15. data/lib/active_support/cache/redis_cache_store.rb +493 -0
  16. data/lib/active_support/cache/strategy/local_cache.rb +75 -42
  17. data/lib/active_support/cache/strategy/local_cache_middleware.rb +10 -9
  18. data/lib/active_support/cache.rb +331 -217
  19. data/lib/active_support/callbacks.rb +650 -592
  20. data/lib/active_support/concern.rb +35 -6
  21. data/lib/active_support/concurrency/load_interlock_aware_monitor.rb +35 -0
  22. data/lib/active_support/concurrency/share_lock.rb +226 -0
  23. data/lib/active_support/configurable.rb +13 -14
  24. data/lib/active_support/core_ext/array/access.rb +41 -1
  25. data/lib/active_support/core_ext/array/conversions.rb +24 -20
  26. data/lib/active_support/core_ext/array/extract.rb +21 -0
  27. data/lib/active_support/core_ext/array/extract_options.rb +2 -0
  28. data/lib/active_support/core_ext/array/grouping.rb +11 -18
  29. data/lib/active_support/core_ext/array/inquiry.rb +19 -0
  30. data/lib/active_support/core_ext/array/prepend_and_append.rb +4 -6
  31. data/lib/active_support/core_ext/array/wrap.rb +7 -4
  32. data/lib/active_support/core_ext/array.rb +9 -6
  33. data/lib/active_support/core_ext/benchmark.rb +3 -1
  34. data/lib/active_support/core_ext/big_decimal/conversions.rb +10 -12
  35. data/lib/active_support/core_ext/big_decimal.rb +3 -1
  36. data/lib/active_support/core_ext/class/attribute.rb +45 -31
  37. data/lib/active_support/core_ext/class/attribute_accessors.rb +3 -1
  38. data/lib/active_support/core_ext/class/subclasses.rb +20 -6
  39. data/lib/active_support/core_ext/class.rb +4 -3
  40. data/lib/active_support/core_ext/date/acts_like.rb +3 -1
  41. data/lib/active_support/core_ext/date/blank.rb +14 -0
  42. data/lib/active_support/core_ext/date/calculations.rb +17 -14
  43. data/lib/active_support/core_ext/date/conversions.rb +25 -23
  44. data/lib/active_support/core_ext/date/zones.rb +4 -2
  45. data/lib/active_support/core_ext/date.rb +6 -4
  46. data/lib/active_support/core_ext/date_and_time/calculations.rb +154 -65
  47. data/lib/active_support/core_ext/date_and_time/compatibility.rb +4 -3
  48. data/lib/active_support/core_ext/date_and_time/zones.rb +12 -13
  49. data/lib/active_support/core_ext/date_time/acts_like.rb +4 -2
  50. data/lib/active_support/core_ext/date_time/blank.rb +14 -0
  51. data/lib/active_support/core_ext/date_time/calculations.rb +37 -19
  52. data/lib/active_support/core_ext/date_time/compatibility.rb +8 -6
  53. data/lib/active_support/core_ext/date_time/conversions.rb +16 -13
  54. data/lib/active_support/core_ext/date_time.rb +7 -5
  55. data/lib/active_support/core_ext/digest/uuid.rb +7 -5
  56. data/lib/active_support/core_ext/digest.rb +3 -0
  57. data/lib/active_support/core_ext/enumerable.rb +114 -22
  58. data/lib/active_support/core_ext/file/atomic.rb +38 -31
  59. data/lib/active_support/core_ext/file.rb +3 -1
  60. data/lib/active_support/core_ext/hash/compact.rb +4 -23
  61. data/lib/active_support/core_ext/hash/conversions.rb +62 -41
  62. data/lib/active_support/core_ext/hash/deep_merge.rb +9 -13
  63. data/lib/active_support/core_ext/hash/deep_transform_values.rb +46 -0
  64. data/lib/active_support/core_ext/hash/except.rb +12 -9
  65. data/lib/active_support/core_ext/hash/indifferent_access.rb +4 -3
  66. data/lib/active_support/core_ext/hash/keys.rb +19 -42
  67. data/lib/active_support/core_ext/hash/reverse_merge.rb +5 -2
  68. data/lib/active_support/core_ext/hash/slice.rb +5 -27
  69. data/lib/active_support/core_ext/hash/transform_values.rb +4 -22
  70. data/lib/active_support/core_ext/hash.rb +10 -9
  71. data/lib/active_support/core_ext/integer/inflections.rb +3 -1
  72. data/lib/active_support/core_ext/integer/multiple.rb +3 -1
  73. data/lib/active_support/core_ext/integer/time.rb +11 -18
  74. data/lib/active_support/core_ext/integer.rb +5 -3
  75. data/lib/active_support/core_ext/kernel/concern.rb +5 -1
  76. data/lib/active_support/core_ext/kernel/reporting.rb +4 -84
  77. data/lib/active_support/core_ext/kernel/singleton_class.rb +2 -0
  78. data/lib/active_support/core_ext/kernel.rb +5 -5
  79. data/lib/active_support/core_ext/load_error.rb +3 -22
  80. data/lib/active_support/core_ext/marshal.rb +8 -8
  81. data/lib/active_support/core_ext/module/aliasing.rb +6 -44
  82. data/lib/active_support/core_ext/module/anonymous.rb +12 -1
  83. data/lib/active_support/core_ext/module/attr_internal.rb +8 -9
  84. data/lib/active_support/core_ext/module/attribute_accessors.rb +46 -46
  85. data/lib/active_support/core_ext/module/attribute_accessors_per_thread.rb +144 -0
  86. data/lib/active_support/core_ext/module/concerning.rb +11 -12
  87. data/lib/active_support/core_ext/module/delegation.rb +133 -30
  88. data/lib/active_support/core_ext/module/deprecation.rb +4 -2
  89. data/lib/active_support/core_ext/module/introspection.rb +44 -19
  90. data/lib/active_support/core_ext/module/reachable.rb +5 -7
  91. data/lib/active_support/core_ext/module/redefine_method.rb +40 -0
  92. data/lib/active_support/core_ext/module/remove_method.rb +8 -3
  93. data/lib/active_support/core_ext/module.rb +13 -11
  94. data/lib/active_support/core_ext/name_error.rb +22 -2
  95. data/lib/active_support/core_ext/numeric/bytes.rb +22 -0
  96. data/lib/active_support/core_ext/numeric/conversions.rb +129 -136
  97. data/lib/active_support/core_ext/numeric/inquiry.rb +5 -0
  98. data/lib/active_support/core_ext/numeric/time.rb +35 -23
  99. data/lib/active_support/core_ext/numeric.rb +5 -3
  100. data/lib/active_support/core_ext/object/acts_like.rb +12 -1
  101. data/lib/active_support/core_ext/object/blank.rb +27 -3
  102. data/lib/active_support/core_ext/object/conversions.rb +6 -4
  103. data/lib/active_support/core_ext/object/deep_dup.rb +13 -4
  104. data/lib/active_support/core_ext/object/duplicable.rb +13 -93
  105. data/lib/active_support/core_ext/object/inclusion.rb +5 -3
  106. data/lib/active_support/core_ext/object/instance_variables.rb +3 -1
  107. data/lib/active_support/core_ext/object/json.rb +51 -20
  108. data/lib/active_support/core_ext/object/to_param.rb +3 -1
  109. data/lib/active_support/core_ext/object/to_query.rb +10 -5
  110. data/lib/active_support/core_ext/object/try.rb +81 -23
  111. data/lib/active_support/core_ext/object/with_options.rb +16 -3
  112. data/lib/active_support/core_ext/object.rb +14 -13
  113. data/lib/active_support/core_ext/range/compare_range.rb +76 -0
  114. data/lib/active_support/core_ext/range/conversions.rb +37 -15
  115. data/lib/active_support/core_ext/range/each.rb +18 -17
  116. data/lib/active_support/core_ext/range/include_range.rb +7 -21
  117. data/lib/active_support/core_ext/range/include_time_with_zone.rb +23 -0
  118. data/lib/active_support/core_ext/range/overlaps.rb +2 -0
  119. data/lib/active_support/core_ext/range.rb +7 -4
  120. data/lib/active_support/core_ext/regexp.rb +2 -0
  121. data/lib/active_support/core_ext/securerandom.rb +45 -0
  122. data/lib/active_support/core_ext/string/access.rb +16 -6
  123. data/lib/active_support/core_ext/string/behavior.rb +3 -1
  124. data/lib/active_support/core_ext/string/conversions.rb +7 -4
  125. data/lib/active_support/core_ext/string/exclude.rb +2 -0
  126. data/lib/active_support/core_ext/string/filters.rb +48 -6
  127. data/lib/active_support/core_ext/string/indent.rb +6 -4
  128. data/lib/active_support/core_ext/string/inflections.rb +66 -24
  129. data/lib/active_support/core_ext/string/inquiry.rb +3 -1
  130. data/lib/active_support/core_ext/string/multibyte.rb +16 -7
  131. data/lib/active_support/core_ext/string/output_safety.rb +93 -40
  132. data/lib/active_support/core_ext/string/starts_ends_with.rb +2 -0
  133. data/lib/active_support/core_ext/string/strip.rb +6 -5
  134. data/lib/active_support/core_ext/string/zones.rb +4 -2
  135. data/lib/active_support/core_ext/string.rb +15 -13
  136. data/lib/active_support/core_ext/time/acts_like.rb +3 -1
  137. data/lib/active_support/core_ext/time/calculations.rb +115 -52
  138. data/lib/active_support/core_ext/time/compatibility.rb +4 -2
  139. data/lib/active_support/core_ext/time/conversions.rb +20 -13
  140. data/lib/active_support/core_ext/time/zones.rb +41 -7
  141. data/lib/active_support/core_ext/time.rb +7 -6
  142. data/lib/active_support/core_ext/uri.rb +6 -7
  143. data/lib/active_support/core_ext.rb +3 -1
  144. data/lib/active_support/current_attributes.rb +203 -0
  145. data/lib/active_support/dependencies/autoload.rb +2 -0
  146. data/lib/active_support/dependencies/interlock.rb +57 -0
  147. data/lib/active_support/dependencies/zeitwerk_integration.rb +117 -0
  148. data/lib/active_support/dependencies.rb +208 -166
  149. data/lib/active_support/deprecation/behaviors.rb +44 -11
  150. data/lib/active_support/deprecation/constant_accessor.rb +52 -0
  151. data/lib/active_support/deprecation/instance_delegator.rb +17 -2
  152. data/lib/active_support/deprecation/method_wrappers.rb +61 -21
  153. data/lib/active_support/deprecation/proxy_wrappers.rb +81 -30
  154. data/lib/active_support/deprecation/reporting.rb +32 -12
  155. data/lib/active_support/deprecation.rb +12 -9
  156. data/lib/active_support/descendants_tracker.rb +57 -9
  157. data/lib/active_support/digest.rb +20 -0
  158. data/lib/active_support/duration/iso8601_parser.rb +123 -0
  159. data/lib/active_support/duration/iso8601_serializer.rb +53 -0
  160. data/lib/active_support/duration.rb +315 -40
  161. data/lib/active_support/encrypted_configuration.rb +45 -0
  162. data/lib/active_support/encrypted_file.rb +100 -0
  163. data/lib/active_support/evented_file_update_checker.rb +234 -0
  164. data/lib/active_support/execution_wrapper.rb +129 -0
  165. data/lib/active_support/executor.rb +8 -0
  166. data/lib/active_support/file_update_checker.rb +62 -37
  167. data/lib/active_support/gem_version.rb +6 -4
  168. data/lib/active_support/gzip.rb +7 -5
  169. data/lib/active_support/hash_with_indifferent_access.rb +129 -30
  170. data/lib/active_support/i18n.rb +9 -6
  171. data/lib/active_support/i18n_railtie.rb +50 -14
  172. data/lib/active_support/inflections.rb +13 -11
  173. data/lib/active_support/inflector/inflections.rb +58 -13
  174. data/lib/active_support/inflector/methods.rb +159 -145
  175. data/lib/active_support/inflector/transliterate.rb +84 -34
  176. data/lib/active_support/inflector.rb +7 -5
  177. data/lib/active_support/json/decoding.rb +32 -30
  178. data/lib/active_support/json/encoding.rb +17 -60
  179. data/lib/active_support/json.rb +4 -2
  180. data/lib/active_support/key_generator.rb +11 -43
  181. data/lib/active_support/lazy_load_hooks.rb +53 -20
  182. data/lib/active_support/locale/en.rb +33 -0
  183. data/lib/active_support/locale/en.yml +2 -0
  184. data/lib/active_support/log_subscriber/test_helper.rb +14 -12
  185. data/lib/active_support/log_subscriber.rb +44 -19
  186. data/lib/active_support/logger.rb +9 -23
  187. data/lib/active_support/logger_silence.rb +32 -14
  188. data/lib/active_support/logger_thread_safe_level.rb +32 -8
  189. data/lib/active_support/message_encryptor.rb +166 -53
  190. data/lib/active_support/message_verifier.rb +149 -16
  191. data/lib/active_support/messages/metadata.rb +72 -0
  192. data/lib/active_support/messages/rotation_configuration.rb +22 -0
  193. data/lib/active_support/messages/rotator.rb +56 -0
  194. data/lib/active_support/multibyte/chars.rb +56 -63
  195. data/lib/active_support/multibyte/unicode.rb +56 -290
  196. data/lib/active_support/multibyte.rb +4 -2
  197. data/lib/active_support/notifications/fanout.rb +109 -22
  198. data/lib/active_support/notifications/instrumenter.rb +107 -16
  199. data/lib/active_support/notifications.rb +51 -10
  200. data/lib/active_support/number_helper/number_converter.rb +16 -15
  201. data/lib/active_support/number_helper/number_to_currency_converter.rb +14 -15
  202. data/lib/active_support/number_helper/number_to_delimited_converter.rb +11 -4
  203. data/lib/active_support/number_helper/number_to_human_converter.rb +13 -10
  204. data/lib/active_support/number_helper/number_to_human_size_converter.rb +11 -9
  205. data/lib/active_support/number_helper/number_to_percentage_converter.rb +5 -1
  206. data/lib/active_support/number_helper/number_to_phone_converter.rb +15 -5
  207. data/lib/active_support/number_helper/number_to_rounded_converter.rb +25 -57
  208. data/lib/active_support/number_helper/rounding_helper.rb +66 -0
  209. data/lib/active_support/number_helper.rb +105 -68
  210. data/lib/active_support/option_merger.rb +24 -4
  211. data/lib/active_support/ordered_hash.rb +7 -5
  212. data/lib/active_support/ordered_options.rb +27 -5
  213. data/lib/active_support/parameter_filter.rb +128 -0
  214. data/lib/active_support/per_thread_registry.rb +9 -4
  215. data/lib/active_support/proxy_object.rb +2 -0
  216. data/lib/active_support/rails.rb +10 -8
  217. data/lib/active_support/railtie.rb +43 -9
  218. data/lib/active_support/reloader.rb +130 -0
  219. data/lib/active_support/rescuable.rb +108 -53
  220. data/lib/active_support/security_utils.rb +15 -11
  221. data/lib/active_support/string_inquirer.rb +11 -4
  222. data/lib/active_support/subscriber.rb +74 -30
  223. data/lib/active_support/tagged_logging.rb +25 -13
  224. data/lib/active_support/test_case.rb +107 -44
  225. data/lib/active_support/testing/assertions.rb +151 -20
  226. data/lib/active_support/testing/autorun.rb +4 -2
  227. data/lib/active_support/testing/constant_lookup.rb +2 -1
  228. data/lib/active_support/testing/declarative.rb +3 -1
  229. data/lib/active_support/testing/deprecation.rb +13 -10
  230. data/lib/active_support/testing/file_fixtures.rb +38 -0
  231. data/lib/active_support/testing/isolation.rb +35 -26
  232. data/lib/active_support/testing/method_call_assertions.rb +70 -0
  233. data/lib/active_support/testing/parallelization.rb +134 -0
  234. data/lib/active_support/testing/setup_and_teardown.rb +13 -8
  235. data/lib/active_support/testing/stream.rb +43 -0
  236. data/lib/active_support/testing/tagged_logging.rb +3 -1
  237. data/lib/active_support/testing/time_helpers.rb +84 -20
  238. data/lib/active_support/time.rb +14 -12
  239. data/lib/active_support/time_with_zone.rb +179 -39
  240. data/lib/active_support/values/time_zone.rb +203 -63
  241. data/lib/active_support/version.rb +3 -1
  242. data/lib/active_support/xml_mini/jdom.rb +116 -115
  243. data/lib/active_support/xml_mini/libxml.rb +16 -13
  244. data/lib/active_support/xml_mini/libxmlsax.rb +15 -14
  245. data/lib/active_support/xml_mini/nokogiri.rb +14 -12
  246. data/lib/active_support/xml_mini/nokogirisax.rb +14 -13
  247. data/lib/active_support/xml_mini/rexml.rb +11 -9
  248. data/lib/active_support/xml_mini.rb +38 -46
  249. data/lib/active_support.rb +13 -11
  250. metadata +84 -26
  251. data/lib/active_support/concurrency/latch.rb +0 -27
  252. data/lib/active_support/core_ext/big_decimal/yaml_conversions.rb +0 -16
  253. data/lib/active_support/core_ext/class/delegating_attributes.rb +0 -45
  254. data/lib/active_support/core_ext/date_time/zones.rb +0 -6
  255. data/lib/active_support/core_ext/kernel/agnostics.rb +0 -11
  256. data/lib/active_support/core_ext/kernel/debugger.rb +0 -10
  257. data/lib/active_support/core_ext/module/method_transplanting.rb +0 -13
  258. data/lib/active_support/core_ext/module/qualified_const.rb +0 -52
  259. data/lib/active_support/core_ext/object/itself.rb +0 -15
  260. data/lib/active_support/core_ext/struct.rb +0 -6
  261. data/lib/active_support/core_ext/thread.rb +0 -86
  262. data/lib/active_support/core_ext/time/marshal.rb +0 -30
  263. data/lib/active_support/values/unicode_tables.dat +0 -0
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Hash
4
+ # Returns a new hash with all values converted by the block operation.
5
+ # This includes the values from the root hash and from all
6
+ # nested hashes and arrays.
7
+ #
8
+ # hash = { person: { name: 'Rob', age: '28' } }
9
+ #
10
+ # hash.deep_transform_values{ |value| value.to_s.upcase }
11
+ # # => {person: {name: "ROB", age: "28"}}
12
+ def deep_transform_values(&block)
13
+ _deep_transform_values_in_object(self, &block)
14
+ end
15
+
16
+ # Destructively converts all values by using the block operation.
17
+ # This includes the values from the root hash and from all
18
+ # nested hashes and arrays.
19
+ def deep_transform_values!(&block)
20
+ _deep_transform_values_in_object!(self, &block)
21
+ end
22
+
23
+ private
24
+ # support methods for deep transforming nested hashes and arrays
25
+ def _deep_transform_values_in_object(object, &block)
26
+ case object
27
+ when Hash
28
+ object.transform_values { |value| _deep_transform_values_in_object(value, &block) }
29
+ when Array
30
+ object.map { |e| _deep_transform_values_in_object(e, &block) }
31
+ else
32
+ yield(object)
33
+ end
34
+ end
35
+
36
+ def _deep_transform_values_in_object!(object, &block)
37
+ case object
38
+ when Hash
39
+ object.transform_values! { |value| _deep_transform_values_in_object!(value, &block) }
40
+ when Array
41
+ object.map! { |e| _deep_transform_values_in_object!(e, &block) }
42
+ else
43
+ yield(object)
44
+ end
45
+ end
46
+ end
@@ -1,19 +1,22 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Hash
2
- # Returns a hash that includes everything but the given keys.
3
- # hash = { a: true, b: false, c: nil}
4
- # hash.except(:c) # => { a: true, b: false}
5
- # hash # => { a: true, b: false, c: nil}
4
+ # Returns a hash that includes everything except given keys.
5
+ # hash = { a: true, b: false, c: nil }
6
+ # hash.except(:c) # => { a: true, b: false }
7
+ # hash.except(:a, :b) # => { c: nil }
8
+ # hash # => { a: true, b: false, c: nil }
6
9
  #
7
10
  # This is useful for limiting a set of parameters to everything but a few known toggles:
8
11
  # @person.update(params[:person].except(:admin))
9
12
  def except(*keys)
10
- dup.except!(*keys)
13
+ slice(*self.keys - keys)
11
14
  end
12
15
 
13
- # Replaces the hash without the given keys.
14
- # hash = { a: true, b: false, c: nil}
15
- # hash.except!(:c) # => { a: true, b: false}
16
- # hash # => { a: true, b: false }
16
+ # Removes the given keys from hash and returns it.
17
+ # hash = { a: true, b: false, c: nil }
18
+ # hash.except!(:c) # => { a: true, b: false }
19
+ # hash # => { a: true, b: false }
17
20
  def except!(*keys)
18
21
  keys.each { |key| delete(key) }
19
22
  self
@@ -1,12 +1,13 @@
1
- require 'active_support/hash_with_indifferent_access'
1
+ # frozen_string_literal: true
2
2
 
3
- class Hash
3
+ require "active_support/hash_with_indifferent_access"
4
4
 
5
+ class Hash
5
6
  # Returns an <tt>ActiveSupport::HashWithIndifferentAccess</tt> out of its receiver:
6
7
  #
7
8
  # { a: 1 }.with_indifferent_access['a'] # => 1
8
9
  def with_indifferent_access
9
- ActiveSupport::HashWithIndifferentAccess.new_from_hash_copying_default(self)
10
+ ActiveSupport::HashWithIndifferentAccess.new(self)
10
11
  end
11
12
 
12
13
  # Called when object is nested under an object that receives
@@ -1,29 +1,6 @@
1
- class Hash
2
- # Returns a new hash with all keys converted using the block operation.
3
- #
4
- # hash = { name: 'Rob', age: '28' }
5
- #
6
- # hash.transform_keys{ |key| key.to_s.upcase }
7
- # # => {"NAME"=>"Rob", "AGE"=>"28"}
8
- def transform_keys
9
- return enum_for(:transform_keys) unless block_given?
10
- result = self.class.new
11
- each_key do |key|
12
- result[yield(key)] = self[key]
13
- end
14
- result
15
- end
16
-
17
- # Destructively convert all keys using the block operations.
18
- # Same as transform_keys but modifies +self+.
19
- def transform_keys!
20
- return enum_for(:transform_keys!) unless block_given?
21
- keys.each do |key|
22
- self[yield(key)] = delete(key)
23
- end
24
- self
25
- end
1
+ # frozen_string_literal: true
26
2
 
3
+ class Hash
27
4
  # Returns a new hash with all keys converted to strings.
28
5
  #
29
6
  # hash = { name: 'Rob', age: '28' }
@@ -31,13 +8,13 @@ class Hash
31
8
  # hash.stringify_keys
32
9
  # # => {"name"=>"Rob", "age"=>"28"}
33
10
  def stringify_keys
34
- transform_keys{ |key| key.to_s }
11
+ transform_keys(&:to_s)
35
12
  end
36
13
 
37
- # Destructively convert all keys to strings. Same as
14
+ # Destructively converts all keys to strings. Same as
38
15
  # +stringify_keys+, but modifies +self+.
39
16
  def stringify_keys!
40
- transform_keys!{ |key| key.to_s }
17
+ transform_keys!(&:to_s)
41
18
  end
42
19
 
43
20
  # Returns a new hash with all keys converted to symbols, as long as
@@ -48,19 +25,19 @@ class Hash
48
25
  # hash.symbolize_keys
49
26
  # # => {:name=>"Rob", :age=>"28"}
50
27
  def symbolize_keys
51
- transform_keys{ |key| key.to_sym rescue key }
28
+ transform_keys { |key| key.to_sym rescue key }
52
29
  end
53
30
  alias_method :to_options, :symbolize_keys
54
31
 
55
- # Destructively convert all keys to symbols, as long as they respond
32
+ # Destructively converts all keys to symbols, as long as they respond
56
33
  # to +to_sym+. Same as +symbolize_keys+, but modifies +self+.
57
34
  def symbolize_keys!
58
- transform_keys!{ |key| key.to_sym rescue key }
35
+ transform_keys! { |key| key.to_sym rescue key }
59
36
  end
60
37
  alias_method :to_options!, :symbolize_keys!
61
38
 
62
- # Validate all keys in a hash match <tt>*valid_keys</tt>, raising
63
- # ArgumentError on a mismatch.
39
+ # Validates all keys in a hash match <tt>*valid_keys</tt>, raising
40
+ # +ArgumentError+ on a mismatch.
64
41
  #
65
42
  # Note that keys are treated differently than HashWithIndifferentAccess,
66
43
  # meaning that string and symbol keys will not match.
@@ -89,7 +66,7 @@ class Hash
89
66
  _deep_transform_keys_in_object(self, &block)
90
67
  end
91
68
 
92
- # Destructively convert all keys by using the block operation.
69
+ # Destructively converts all keys by using the block operation.
93
70
  # This includes the keys from the root hash and from all
94
71
  # nested hashes and arrays.
95
72
  def deep_transform_keys!(&block)
@@ -105,14 +82,14 @@ class Hash
105
82
  # hash.deep_stringify_keys
106
83
  # # => {"person"=>{"name"=>"Rob", "age"=>"28"}}
107
84
  def deep_stringify_keys
108
- deep_transform_keys{ |key| key.to_s }
85
+ deep_transform_keys(&:to_s)
109
86
  end
110
87
 
111
- # Destructively convert all keys to strings.
88
+ # Destructively converts all keys to strings.
112
89
  # This includes the keys from the root hash and from all
113
90
  # nested hashes and arrays.
114
91
  def deep_stringify_keys!
115
- deep_transform_keys!{ |key| key.to_s }
92
+ deep_transform_keys!(&:to_s)
116
93
  end
117
94
 
118
95
  # Returns a new hash with all keys converted to symbols, as long as
@@ -124,14 +101,14 @@ class Hash
124
101
  # hash.deep_symbolize_keys
125
102
  # # => {:person=>{:name=>"Rob", :age=>"28"}}
126
103
  def deep_symbolize_keys
127
- deep_transform_keys{ |key| key.to_sym rescue key }
104
+ deep_transform_keys { |key| key.to_sym rescue key }
128
105
  end
129
106
 
130
- # Destructively convert all keys to symbols, as long as they respond
107
+ # Destructively converts all keys to symbols, as long as they respond
131
108
  # to +to_sym+. This includes the keys from the root hash and from all
132
109
  # nested hashes and arrays.
133
110
  def deep_symbolize_keys!
134
- deep_transform_keys!{ |key| key.to_sym rescue key }
111
+ deep_transform_keys! { |key| key.to_sym rescue key }
135
112
  end
136
113
 
137
114
  private
@@ -143,7 +120,7 @@ class Hash
143
120
  result[yield(key)] = _deep_transform_keys_in_object(value, &block)
144
121
  end
145
122
  when Array
146
- object.map {|e| _deep_transform_keys_in_object(e, &block) }
123
+ object.map { |e| _deep_transform_keys_in_object(e, &block) }
147
124
  else
148
125
  object
149
126
  end
@@ -158,7 +135,7 @@ class Hash
158
135
  end
159
136
  object
160
137
  when Array
161
- object.map! {|e| _deep_transform_keys_in_object!(e, &block)}
138
+ object.map! { |e| _deep_transform_keys_in_object!(e, &block) }
162
139
  else
163
140
  object
164
141
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Hash
2
4
  # Merges the caller into +other_hash+. For example,
3
5
  #
@@ -12,11 +14,12 @@ class Hash
12
14
  def reverse_merge(other_hash)
13
15
  other_hash.merge(self)
14
16
  end
17
+ alias_method :with_defaults, :reverse_merge
15
18
 
16
19
  # Destructive +reverse_merge+.
17
20
  def reverse_merge!(other_hash)
18
- # right wins if there is no left
19
- merge!( other_hash ){|key,left,right| left }
21
+ replace(reverse_merge(other_hash))
20
22
  end
21
23
  alias_method :reverse_update, :reverse_merge!
24
+ alias_method :with_defaults!, :reverse_merge!
22
25
  end
@@ -1,35 +1,13 @@
1
- class Hash
2
- # Slice a hash to include only the given keys. Returns a hash containing
3
- # the given keys.
4
- #
5
- # { a: 1, b: 2, c: 3, d: 4 }.slice(:a, :b)
6
- # # => {:a=>1, :b=>2}
7
- #
8
- # This is useful for limiting an options hash to valid keys before
9
- # passing to a method:
10
- #
11
- # def search(criteria = {})
12
- # criteria.assert_valid_keys(:mass, :velocity, :time)
13
- # end
14
- #
15
- # search(options.slice(:mass, :velocity, :time))
16
- #
17
- # If you have an array of keys you want to limit to, you should splat them:
18
- #
19
- # valid_keys = [:mass, :velocity, :time]
20
- # search(options.slice(*valid_keys))
21
- def slice(*keys)
22
- keys.map! { |key| convert_key(key) } if respond_to?(:convert_key, true)
23
- keys.each_with_object(self.class.new) { |k, hash| hash[k] = self[k] if has_key?(k) }
24
- end
1
+ # frozen_string_literal: true
25
2
 
3
+ class Hash
26
4
  # Replaces the hash with only the given keys.
27
5
  # Returns a hash containing the removed key/value pairs.
28
6
  #
29
- # { a: 1, b: 2, c: 3, d: 4 }.slice!(:a, :b)
30
- # # => {:c=>3, :d=>4}
7
+ # hash = { a: 1, b: 2, c: 3, d: 4 }
8
+ # hash.slice!(:a, :b) # => {:c=>3, :d=>4}
9
+ # hash # => {:a=>1, :b=>2}
31
10
  def slice!(*keys)
32
- keys.map! { |key| convert_key(key) } if respond_to?(:convert_key, true)
33
11
  omit = slice(*self.keys - keys)
34
12
  hash = slice(*keys)
35
13
  hash.default = default
@@ -1,23 +1,5 @@
1
- class Hash
2
- # Returns a new hash with the results of running +block+ once for every value.
3
- # The keys are unchanged.
4
- #
5
- # { a: 1, b: 2, c: 3 }.transform_values { |x| x * 2 }
6
- # # => { a: 2, b: 4, c: 6 }
7
- def transform_values
8
- return enum_for(:transform_values) unless block_given?
9
- result = self.class.new
10
- each do |key, value|
11
- result[key] = yield(value)
12
- end
13
- result
14
- end unless method_defined? :transform_values
1
+ # frozen_string_literal: true
15
2
 
16
- # Destructive +transform_values+
17
- def transform_values!
18
- return enum_for(:transform_values!) unless block_given?
19
- each do |key, value|
20
- self[key] = yield(value)
21
- end
22
- end unless method_defined? :transform_values!
23
- end
3
+ require "active_support/deprecation"
4
+
5
+ ActiveSupport::Deprecation.warn "Ruby 2.5+ (required by Rails 6) provides Hash#transform_values natively, so requiring active_support/core_ext/hash/transform_values is no longer necessary. Requiring it will raise LoadError in Rails 6.1."
@@ -1,9 +1,10 @@
1
- require 'active_support/core_ext/hash/compact'
2
- require 'active_support/core_ext/hash/conversions'
3
- require 'active_support/core_ext/hash/deep_merge'
4
- require 'active_support/core_ext/hash/except'
5
- require 'active_support/core_ext/hash/indifferent_access'
6
- require 'active_support/core_ext/hash/keys'
7
- require 'active_support/core_ext/hash/reverse_merge'
8
- require 'active_support/core_ext/hash/slice'
9
- require 'active_support/core_ext/hash/transform_values'
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/core_ext/hash/conversions"
4
+ require "active_support/core_ext/hash/deep_merge"
5
+ require "active_support/core_ext/hash/deep_transform_values"
6
+ require "active_support/core_ext/hash/except"
7
+ require "active_support/core_ext/hash/indifferent_access"
8
+ require "active_support/core_ext/hash/keys"
9
+ require "active_support/core_ext/hash/reverse_merge"
10
+ require "active_support/core_ext/hash/slice"
@@ -1,4 +1,6 @@
1
- require 'active_support/inflector'
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/inflector"
2
4
 
3
5
  class Integer
4
6
  # Ordinalize turns a number into an ordinal string used to denote the
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Integer
2
4
  # Check whether the integer is evenly divisible by the argument.
3
5
  #
@@ -5,6 +7,6 @@ class Integer
5
7
  # 6.multiple_of?(5) # => false
6
8
  # 10.multiple_of?(2) # => true
7
9
  def multiple_of?(number)
8
- number != 0 ? self % number == 0 : zero?
10
+ number == 0 ? self == 0 : self % number == 0
9
11
  end
10
12
  end
@@ -1,29 +1,22 @@
1
- require 'active_support/duration'
2
- require 'active_support/core_ext/numeric/time'
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/duration"
4
+ require "active_support/core_ext/numeric/time"
3
5
 
4
6
  class Integer
5
- # Enables the use of time calculations and declarations, like <tt>45.minutes +
6
- # 2.hours + 4.years</tt>.
7
- #
8
- # These methods use Time#advance for precise date calculations when using
9
- # <tt>from_now</tt>, +ago+, etc. as well as adding or subtracting their
10
- # results from a Time object.
11
- #
12
- # # equivalent to Time.now.advance(months: 1)
13
- # 1.month.from_now
7
+ # Returns a Duration instance matching the number of months provided.
14
8
  #
15
- # # equivalent to Time.now.advance(years: 2)
16
- # 2.years.from_now
17
- #
18
- # # equivalent to Time.now.advance(months: 4, years: 5)
19
- # (4.months + 5.years).from_now
9
+ # 2.months # => 2 months
20
10
  def months
21
- ActiveSupport::Duration.new(self * 30.days, [[:months, self]])
11
+ ActiveSupport::Duration.months(self)
22
12
  end
23
13
  alias :month :months
24
14
 
15
+ # Returns a Duration instance matching the number of years provided.
16
+ #
17
+ # 2.years # => 2 years
25
18
  def years
26
- ActiveSupport::Duration.new(self * 365.25.days, [[:years, self]])
19
+ ActiveSupport::Duration.years(self)
27
20
  end
28
21
  alias :year :years
29
22
  end
@@ -1,3 +1,5 @@
1
- require 'active_support/core_ext/integer/multiple'
2
- require 'active_support/core_ext/integer/inflections'
3
- require 'active_support/core_ext/integer/time'
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/core_ext/integer/multiple"
4
+ require "active_support/core_ext/integer/inflections"
5
+ require "active_support/core_ext/integer/time"
@@ -1,6 +1,10 @@
1
- require 'active_support/core_ext/module/concerning'
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/core_ext/module/concerning"
2
4
 
3
5
  module Kernel
6
+ module_function
7
+
4
8
  # A shortcut to define a toplevel concern, not within a module.
5
9
  #
6
10
  # See Module::Concerning for more.
@@ -1,9 +1,9 @@
1
- require 'rbconfig'
2
- require 'tempfile'
3
- require 'active_support/deprecation'
1
+ # frozen_string_literal: true
4
2
 
5
3
  module Kernel
6
- # Sets $VERBOSE to nil for the duration of the block and back to its original
4
+ module_function
5
+
6
+ # Sets $VERBOSE to +nil+ for the duration of the block and back to its original
7
7
  # value afterwards.
8
8
  #
9
9
  # silence_warnings do
@@ -30,34 +30,6 @@ module Kernel
30
30
  $VERBOSE = old_verbose
31
31
  end
32
32
 
33
- # For compatibility
34
- def silence_stderr #:nodoc:
35
- ActiveSupport::Deprecation.warn(
36
- "`#silence_stderr` is deprecated and will be removed in the next release."
37
- ) #not thread-safe
38
- silence_stream(STDERR) { yield }
39
- end
40
-
41
- # Deprecated : this method is not thread safe
42
- # Silences any stream for the duration of the block.
43
- #
44
- # silence_stream(STDOUT) do
45
- # puts 'This will never be seen'
46
- # end
47
- #
48
- # puts 'But this will'
49
- #
50
- # This method is not thread-safe.
51
- def silence_stream(stream)
52
- old_stream = stream.dup
53
- stream.reopen(RbConfig::CONFIG['host_os'] =~ /mswin|mingw/ ? 'NUL:' : '/dev/null')
54
- stream.sync = true
55
- yield
56
- ensure
57
- stream.reopen(old_stream)
58
- old_stream.close
59
- end
60
-
61
33
  # Blocks and ignores any exception passed as argument if raised within the block.
62
34
  #
63
35
  # suppress(ZeroDivisionError) do
@@ -70,56 +42,4 @@ module Kernel
70
42
  yield
71
43
  rescue *exception_classes
72
44
  end
73
-
74
- # Captures the given stream and returns it:
75
- #
76
- # stream = capture(:stdout) { puts 'notice' }
77
- # stream # => "notice\n"
78
- #
79
- # stream = capture(:stderr) { warn 'error' }
80
- # stream # => "error\n"
81
- #
82
- # even for subprocesses:
83
- #
84
- # stream = capture(:stdout) { system('echo notice') }
85
- # stream # => "notice\n"
86
- #
87
- # stream = capture(:stderr) { system('echo error 1>&2') }
88
- # stream # => "error\n"
89
- def capture(stream)
90
- ActiveSupport::Deprecation.warn(
91
- "`#capture(stream)` is deprecated and will be removed in the next release."
92
- ) #not thread-safe
93
- stream = stream.to_s
94
- captured_stream = Tempfile.new(stream)
95
- stream_io = eval("$#{stream}")
96
- origin_stream = stream_io.dup
97
- stream_io.reopen(captured_stream)
98
-
99
- yield
100
-
101
- stream_io.rewind
102
- return captured_stream.read
103
- ensure
104
- captured_stream.close
105
- captured_stream.unlink
106
- stream_io.reopen(origin_stream)
107
- end
108
- alias :silence :capture
109
-
110
- # Silences both STDOUT and STDERR, even for subprocesses.
111
- #
112
- # quietly { system 'bundle install' }
113
- #
114
- # This method is not thread-safe.
115
- def quietly
116
- ActiveSupport::Deprecation.warn(
117
- "`#quietly` is deprecated and will be removed in the next release."
118
- ) #not thread-safe
119
- silence_stream(STDOUT) do
120
- silence_stream(STDERR) do
121
- yield
122
- end
123
- end
124
- end
125
45
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Kernel
2
4
  # class_eval on an object acts like singleton_class.class_eval.
3
5
  def class_eval(*args, &block)
@@ -1,5 +1,5 @@
1
- require 'active_support/core_ext/kernel/agnostics'
2
- require 'active_support/core_ext/kernel/concern'
3
- require 'active_support/core_ext/kernel/debugger' if RUBY_VERSION < '2.0.0'
4
- require 'active_support/core_ext/kernel/reporting'
5
- require 'active_support/core_ext/kernel/singleton_class'
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/core_ext/kernel/concern"
4
+ require "active_support/core_ext/kernel/reporting"
5
+ require "active_support/core_ext/kernel/singleton_class"
@@ -1,28 +1,9 @@
1
- class LoadError
2
- REGEXPS = [
3
- /^no such file to load -- (.+)$/i,
4
- /^Missing \w+ (?:file\s*)?([^\s]+.rb)$/i,
5
- /^Missing API definition file in (.+)$/i,
6
- /^cannot load such file -- (.+)$/i,
7
- ]
8
-
9
- unless method_defined?(:path)
10
- # Returns the path which was unable to be loaded.
11
- def path
12
- @path ||= begin
13
- REGEXPS.find do |regex|
14
- message =~ regex
15
- end
16
- $1
17
- end
18
- end
19
- end
1
+ # frozen_string_literal: true
20
2
 
3
+ class LoadError
21
4
  # Returns true if the given path name (except perhaps for the ".rb"
22
5
  # extension) is the missing file which caused the exception to be raised.
23
6
  def is_missing?(location)
24
- location.sub(/\.rb$/, '') == path.sub(/\.rb$/, '')
7
+ location.sub(/\.rb$/, "") == path.to_s.sub(/\.rb$/, "")
25
8
  end
26
9
  end
27
-
28
- MissingSourceFile = LoadError
@@ -1,11 +1,11 @@
1
- require 'active_support/core_ext/module/aliasing'
1
+ # frozen_string_literal: true
2
2
 
3
- module Marshal
4
- class << self
5
- def load_with_autoloading(source, proc = nil)
6
- load_without_autoloading(source, proc)
3
+ module ActiveSupport
4
+ module MarshalWithAutoloading # :nodoc:
5
+ def load(source, proc = nil)
6
+ super(source, proc)
7
7
  rescue ArgumentError, NameError => exc
8
- if exc.message.match(%r|undefined class/module (.+?)(::)?\z|)
8
+ if exc.message.match(%r|undefined class/module (.+?)(?:::)?\z|)
9
9
  # try loading the class/module
10
10
  loaded = $1.constantize
11
11
 
@@ -18,7 +18,7 @@ module Marshal
18
18
  raise exc
19
19
  end
20
20
  end
21
-
22
- alias_method_chain :load, :autoloading
23
21
  end
24
22
  end
23
+
24
+ Marshal.singleton_class.prepend(ActiveSupport::MarshalWithAutoloading)