activesupport 5.0.0 → 6.1.0

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 (268) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +343 -590
  3. data/MIT-LICENSE +1 -1
  4. data/README.rdoc +5 -4
  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 +11 -5
  8. data/lib/active_support/backtrace_cleaner.rb +33 -5
  9. data/lib/active_support/benchmarkable.rb +5 -3
  10. data/lib/active_support/builder.rb +3 -1
  11. data/lib/active_support/cache/file_store.rb +45 -53
  12. data/lib/active_support/cache/mem_cache_store.rb +81 -79
  13. data/lib/active_support/cache/memory_store.rb +69 -41
  14. data/lib/active_support/cache/null_store.rb +11 -4
  15. data/lib/active_support/cache/redis_cache_store.rb +493 -0
  16. data/lib/active_support/cache/strategy/local_cache.rb +74 -37
  17. data/lib/active_support/cache/strategy/local_cache_middleware.rb +10 -9
  18. data/lib/active_support/cache.rb +332 -161
  19. data/lib/active_support/callbacks.rb +657 -586
  20. data/lib/active_support/concern.rb +79 -6
  21. data/lib/active_support/concurrency/load_interlock_aware_monitor.rb +35 -0
  22. data/lib/active_support/concurrency/share_lock.rb +59 -19
  23. data/lib/active_support/configurable.rb +15 -17
  24. data/lib/active_support/configuration_file.rb +46 -0
  25. data/lib/active_support/core_ext/array/access.rb +21 -7
  26. data/lib/active_support/core_ext/array/conversions.rb +20 -18
  27. data/lib/active_support/core_ext/array/extract.rb +21 -0
  28. data/lib/active_support/core_ext/array/extract_options.rb +2 -0
  29. data/lib/active_support/core_ext/array/grouping.rb +3 -1
  30. data/lib/active_support/core_ext/array/inquiry.rb +3 -1
  31. data/lib/active_support/core_ext/array/wrap.rb +2 -0
  32. data/lib/active_support/core_ext/array.rb +9 -7
  33. data/lib/active_support/core_ext/benchmark.rb +5 -3
  34. data/lib/active_support/core_ext/big_decimal/conversions.rb +6 -6
  35. data/lib/active_support/core_ext/big_decimal.rb +3 -1
  36. data/lib/active_support/core_ext/class/attribute.rb +52 -49
  37. data/lib/active_support/core_ext/class/attribute_accessors.rb +3 -1
  38. data/lib/active_support/core_ext/class/subclasses.rb +18 -26
  39. data/lib/active_support/core_ext/class.rb +4 -2
  40. data/lib/active_support/core_ext/date/acts_like.rb +3 -1
  41. data/lib/active_support/core_ext/date/blank.rb +3 -1
  42. data/lib/active_support/core_ext/date/calculations.rb +16 -13
  43. data/lib/active_support/core_ext/date/conversions.rb +23 -21
  44. data/lib/active_support/core_ext/date/zones.rb +4 -2
  45. data/lib/active_support/core_ext/date.rb +7 -5
  46. data/lib/active_support/core_ext/date_and_time/calculations.rb +82 -53
  47. data/lib/active_support/core_ext/date_and_time/compatibility.rb +18 -5
  48. data/lib/active_support/core_ext/date_and_time/zones.rb +9 -9
  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 +3 -1
  51. data/lib/active_support/core_ext/date_time/calculations.rb +23 -11
  52. data/lib/active_support/core_ext/date_time/compatibility.rb +15 -2
  53. data/lib/active_support/core_ext/date_time/conversions.rb +14 -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 +165 -29
  58. data/lib/active_support/core_ext/file/atomic.rb +7 -5
  59. data/lib/active_support/core_ext/file.rb +3 -1
  60. data/lib/active_support/core_ext/hash/conversions.rb +40 -39
  61. data/lib/active_support/core_ext/hash/deep_merge.rb +8 -12
  62. data/lib/active_support/core_ext/hash/deep_transform_values.rb +46 -0
  63. data/lib/active_support/core_ext/hash/except.rb +4 -2
  64. data/lib/active_support/core_ext/hash/indifferent_access.rb +3 -2
  65. data/lib/active_support/core_ext/hash/keys.rb +9 -36
  66. data/lib/active_support/core_ext/hash/reverse_merge.rb +5 -2
  67. data/lib/active_support/core_ext/hash/slice.rb +8 -29
  68. data/lib/active_support/core_ext/hash.rb +10 -9
  69. data/lib/active_support/core_ext/integer/inflections.rb +3 -1
  70. data/lib/active_support/core_ext/integer/multiple.rb +3 -1
  71. data/lib/active_support/core_ext/integer/time.rb +11 -18
  72. data/lib/active_support/core_ext/integer.rb +5 -3
  73. data/lib/active_support/core_ext/kernel/concern.rb +3 -1
  74. data/lib/active_support/core_ext/kernel/reporting.rb +3 -1
  75. data/lib/active_support/core_ext/kernel/singleton_class.rb +2 -0
  76. data/lib/active_support/core_ext/kernel.rb +5 -4
  77. data/lib/active_support/core_ext/load_error.rb +2 -23
  78. data/lib/active_support/core_ext/marshal.rb +6 -2
  79. data/lib/active_support/core_ext/module/aliasing.rb +5 -48
  80. data/lib/active_support/core_ext/module/anonymous.rb +2 -0
  81. data/lib/active_support/core_ext/module/attr_internal.rb +7 -5
  82. data/lib/active_support/core_ext/module/attribute_accessors.rb +53 -59
  83. data/lib/active_support/core_ext/module/attribute_accessors_per_thread.rb +31 -24
  84. data/lib/active_support/core_ext/module/concerning.rb +16 -11
  85. data/lib/active_support/core_ext/module/delegation.rb +159 -44
  86. data/lib/active_support/core_ext/module/deprecation.rb +2 -0
  87. data/lib/active_support/core_ext/module/introspection.rb +23 -26
  88. data/lib/active_support/core_ext/module/redefine_method.rb +40 -0
  89. data/lib/active_support/core_ext/module/remove_method.rb +5 -23
  90. data/lib/active_support/core_ext/module.rb +13 -12
  91. data/lib/active_support/core_ext/name_error.rb +36 -2
  92. data/lib/active_support/core_ext/numeric/bytes.rb +2 -0
  93. data/lib/active_support/core_ext/numeric/conversions.rb +129 -134
  94. data/lib/active_support/core_ext/numeric/time.rb +18 -26
  95. data/lib/active_support/core_ext/numeric.rb +5 -4
  96. data/lib/active_support/core_ext/object/acts_like.rb +12 -1
  97. data/lib/active_support/core_ext/object/blank.rb +14 -2
  98. data/lib/active_support/core_ext/object/conversions.rb +6 -4
  99. data/lib/active_support/core_ext/object/deep_dup.rb +4 -2
  100. data/lib/active_support/core_ext/object/duplicable.rb +13 -62
  101. data/lib/active_support/core_ext/object/inclusion.rb +3 -1
  102. data/lib/active_support/core_ext/object/instance_variables.rb +2 -0
  103. data/lib/active_support/core_ext/object/json.rb +42 -15
  104. data/lib/active_support/core_ext/object/to_param.rb +3 -1
  105. data/lib/active_support/core_ext/object/to_query.rb +10 -5
  106. data/lib/active_support/core_ext/object/try.rb +20 -8
  107. data/lib/active_support/core_ext/object/with_options.rb +15 -2
  108. data/lib/active_support/core_ext/object.rb +14 -12
  109. data/lib/active_support/core_ext/range/compare_range.rb +82 -0
  110. data/lib/active_support/core_ext/range/conversions.rb +35 -25
  111. data/lib/active_support/core_ext/range/each.rb +5 -2
  112. data/lib/active_support/core_ext/range/include_time_with_zone.rb +28 -0
  113. data/lib/active_support/core_ext/range/overlaps.rb +2 -0
  114. data/lib/active_support/core_ext/range.rb +7 -4
  115. data/lib/active_support/core_ext/regexp.rb +10 -1
  116. data/lib/active_support/core_ext/securerandom.rb +28 -6
  117. data/lib/active_support/core_ext/string/access.rb +9 -18
  118. data/lib/active_support/core_ext/string/behavior.rb +2 -0
  119. data/lib/active_support/core_ext/string/conversions.rb +5 -2
  120. data/lib/active_support/core_ext/string/exclude.rb +2 -0
  121. data/lib/active_support/core_ext/string/filters.rb +47 -4
  122. data/lib/active_support/core_ext/string/indent.rb +6 -4
  123. data/lib/active_support/core_ext/string/inflections.rb +78 -29
  124. data/lib/active_support/core_ext/string/inquiry.rb +4 -1
  125. data/lib/active_support/core_ext/string/multibyte.rb +10 -5
  126. data/lib/active_support/core_ext/string/output_safety.rb +86 -31
  127. data/lib/active_support/core_ext/string/starts_ends_with.rb +4 -2
  128. data/lib/active_support/core_ext/string/strip.rb +5 -1
  129. data/lib/active_support/core_ext/string/zones.rb +4 -2
  130. data/lib/active_support/core_ext/string.rb +15 -13
  131. data/lib/active_support/core_ext/symbol/starts_ends_with.rb +14 -0
  132. data/lib/active_support/core_ext/symbol.rb +3 -0
  133. data/lib/active_support/core_ext/time/acts_like.rb +3 -1
  134. data/lib/active_support/core_ext/time/calculations.rb +117 -45
  135. data/lib/active_support/core_ext/time/compatibility.rb +13 -2
  136. data/lib/active_support/core_ext/time/conversions.rb +18 -12
  137. data/lib/active_support/core_ext/time/zones.rb +9 -7
  138. data/lib/active_support/core_ext/time.rb +7 -5
  139. data/lib/active_support/core_ext/uri.rb +12 -7
  140. data/lib/active_support/core_ext.rb +3 -2
  141. data/lib/active_support/current_attributes/test_helper.rb +13 -0
  142. data/lib/active_support/current_attributes.rb +208 -0
  143. data/lib/active_support/dependencies/autoload.rb +2 -0
  144. data/lib/active_support/dependencies/interlock.rb +7 -1
  145. data/lib/active_support/dependencies/zeitwerk_integration.rb +117 -0
  146. data/lib/active_support/dependencies.rb +172 -98
  147. data/lib/active_support/deprecation/behaviors.rb +45 -13
  148. data/lib/active_support/deprecation/constant_accessor.rb +52 -0
  149. data/lib/active_support/deprecation/disallowed.rb +56 -0
  150. data/lib/active_support/deprecation/instance_delegator.rb +16 -2
  151. data/lib/active_support/deprecation/method_wrappers.rb +32 -17
  152. data/lib/active_support/deprecation/proxy_wrappers.rb +35 -7
  153. data/lib/active_support/deprecation/reporting.rb +61 -16
  154. data/lib/active_support/deprecation.rb +17 -9
  155. data/lib/active_support/descendants_tracker.rb +61 -9
  156. data/lib/active_support/digest.rb +20 -0
  157. data/lib/active_support/duration/iso8601_parser.rb +67 -66
  158. data/lib/active_support/duration/iso8601_serializer.rb +25 -17
  159. data/lib/active_support/duration.rb +349 -46
  160. data/lib/active_support/encrypted_configuration.rb +45 -0
  161. data/lib/active_support/encrypted_file.rb +117 -0
  162. data/lib/active_support/environment_inquirer.rb +20 -0
  163. data/lib/active_support/evented_file_update_checker.rb +88 -112
  164. data/lib/active_support/execution_wrapper.rb +25 -13
  165. data/lib/active_support/executor.rb +3 -1
  166. data/lib/active_support/file_update_checker.rb +56 -51
  167. data/lib/active_support/fork_tracker.rb +62 -0
  168. data/lib/active_support/gem_version.rb +4 -2
  169. data/lib/active_support/gzip.rb +7 -5
  170. data/lib/active_support/hash_with_indifferent_access.rb +153 -49
  171. data/lib/active_support/i18n.rb +9 -6
  172. data/lib/active_support/i18n_railtie.rb +30 -20
  173. data/lib/active_support/inflections.rb +13 -11
  174. data/lib/active_support/inflector/inflections.rb +28 -15
  175. data/lib/active_support/inflector/methods.rb +120 -109
  176. data/lib/active_support/inflector/transliterate.rb +60 -25
  177. data/lib/active_support/inflector.rb +7 -5
  178. data/lib/active_support/json/decoding.rb +30 -29
  179. data/lib/active_support/json/encoding.rb +22 -11
  180. data/lib/active_support/json.rb +4 -2
  181. data/lib/active_support/key_generator.rb +6 -36
  182. data/lib/active_support/lazy_load_hooks.rb +53 -20
  183. data/lib/active_support/locale/en.rb +33 -0
  184. data/lib/active_support/locale/en.yml +7 -3
  185. data/lib/active_support/log_subscriber/test_helper.rb +11 -9
  186. data/lib/active_support/log_subscriber.rb +51 -18
  187. data/lib/active_support/logger.rb +9 -22
  188. data/lib/active_support/logger_silence.rb +14 -21
  189. data/lib/active_support/logger_thread_safe_level.rb +55 -8
  190. data/lib/active_support/message_encryptor.rb +170 -53
  191. data/lib/active_support/message_verifier.rb +91 -20
  192. data/lib/active_support/messages/metadata.rb +80 -0
  193. data/lib/active_support/messages/rotation_configuration.rb +23 -0
  194. data/lib/active_support/messages/rotator.rb +57 -0
  195. data/lib/active_support/multibyte/chars.rb +24 -78
  196. data/lib/active_support/multibyte/unicode.rb +21 -352
  197. data/lib/active_support/multibyte.rb +4 -2
  198. data/lib/active_support/notifications/fanout.rb +121 -19
  199. data/lib/active_support/notifications/instrumenter.rb +78 -14
  200. data/lib/active_support/notifications.rb +80 -12
  201. data/lib/active_support/number_helper/number_converter.rb +17 -16
  202. data/lib/active_support/number_helper/number_to_currency_converter.rb +6 -9
  203. data/lib/active_support/number_helper/number_to_delimited_converter.rb +5 -3
  204. data/lib/active_support/number_helper/number_to_human_converter.rb +13 -12
  205. data/lib/active_support/number_helper/number_to_human_size_converter.rb +11 -13
  206. data/lib/active_support/number_helper/number_to_percentage_converter.rb +5 -1
  207. data/lib/active_support/number_helper/number_to_phone_converter.rb +5 -4
  208. data/lib/active_support/number_helper/number_to_rounded_converter.rb +18 -55
  209. data/lib/active_support/number_helper/rounding_helper.rb +50 -0
  210. data/lib/active_support/number_helper.rb +45 -16
  211. data/lib/active_support/option_merger.rb +25 -4
  212. data/lib/active_support/ordered_hash.rb +6 -4
  213. data/lib/active_support/ordered_options.rb +23 -9
  214. data/lib/active_support/parameter_filter.rb +133 -0
  215. data/lib/active_support/per_thread_registry.rb +7 -5
  216. data/lib/active_support/proxy_object.rb +2 -0
  217. data/lib/active_support/rails.rb +8 -9
  218. data/lib/active_support/railtie.rb +62 -11
  219. data/lib/active_support/reloader.rb +12 -11
  220. data/lib/active_support/rescuable.rb +20 -11
  221. data/lib/active_support/secure_compare_rotator.rb +51 -0
  222. data/lib/active_support/security_utils.rb +26 -15
  223. data/lib/active_support/string_inquirer.rb +12 -3
  224. data/lib/active_support/subscriber.rb +77 -23
  225. data/lib/active_support/tagged_logging.rb +52 -17
  226. data/lib/active_support/test_case.rb +106 -29
  227. data/lib/active_support/testing/assertions.rb +144 -8
  228. data/lib/active_support/testing/autorun.rb +5 -10
  229. data/lib/active_support/testing/constant_lookup.rb +2 -1
  230. data/lib/active_support/testing/declarative.rb +3 -1
  231. data/lib/active_support/testing/deprecation.rb +4 -2
  232. data/lib/active_support/testing/file_fixtures.rb +4 -0
  233. data/lib/active_support/testing/isolation.rb +19 -24
  234. data/lib/active_support/testing/method_call_assertions.rb +31 -2
  235. data/lib/active_support/testing/parallelization/server.rb +78 -0
  236. data/lib/active_support/testing/parallelization/worker.rb +100 -0
  237. data/lib/active_support/testing/parallelization.rb +51 -0
  238. data/lib/active_support/testing/setup_and_teardown.rb +13 -8
  239. data/lib/active_support/testing/stream.rb +30 -29
  240. data/lib/active_support/testing/tagged_logging.rb +3 -1
  241. data/lib/active_support/testing/time_helpers.rb +125 -24
  242. data/lib/active_support/time.rb +14 -12
  243. data/lib/active_support/time_with_zone.rb +142 -55
  244. data/lib/active_support/values/time_zone.rb +160 -53
  245. data/lib/active_support/version.rb +3 -1
  246. data/lib/active_support/xml_mini/jdom.rb +115 -114
  247. data/lib/active_support/xml_mini/libxml.rb +15 -14
  248. data/lib/active_support/xml_mini/libxmlsax.rb +16 -18
  249. data/lib/active_support/xml_mini/nokogiri.rb +13 -13
  250. data/lib/active_support/xml_mini/nokogirisax.rb +15 -16
  251. data/lib/active_support/xml_mini/rexml.rb +18 -9
  252. data/lib/active_support/xml_mini.rb +44 -42
  253. data/lib/active_support.rb +19 -10
  254. metadata +79 -37
  255. data/lib/active_support/concurrency/latch.rb +0 -19
  256. data/lib/active_support/core_ext/array/prepend_and_append.rb +0 -7
  257. data/lib/active_support/core_ext/hash/compact.rb +0 -20
  258. data/lib/active_support/core_ext/hash/transform_values.rb +0 -29
  259. data/lib/active_support/core_ext/kernel/agnostics.rb +0 -11
  260. data/lib/active_support/core_ext/kernel/debugger.rb +0 -3
  261. data/lib/active_support/core_ext/module/method_transplanting.rb +0 -3
  262. data/lib/active_support/core_ext/module/qualified_const.rb +0 -70
  263. data/lib/active_support/core_ext/module/reachable.rb +0 -8
  264. data/lib/active_support/core_ext/numeric/inquiry.rb +0 -26
  265. data/lib/active_support/core_ext/range/include_range.rb +0 -23
  266. data/lib/active_support/core_ext/struct.rb +0 -3
  267. data/lib/active_support/core_ext/time/marshal.rb +0 -3
  268. data/lib/active_support/values/unicode_tables.dat +0 -0
@@ -1,12 +1,12 @@
1
- require 'bigdecimal'
2
- require 'bigdecimal/util'
1
+ # frozen_string_literal: true
2
+
3
+ require "bigdecimal"
4
+ require "bigdecimal/util"
3
5
 
4
6
  module ActiveSupport
5
7
  module BigDecimalWithDefaultFormat #:nodoc:
6
- DEFAULT_STRING_FORMAT = 'F'
7
-
8
- def to_s(format = nil)
9
- super(format || DEFAULT_STRING_FORMAT)
8
+ def to_s(format = "F")
9
+ super(format)
10
10
  end
11
11
  end
12
12
  end
@@ -1 +1,3 @@
1
- require 'active_support/core_ext/big_decimal/conversions'
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/core_ext/big_decimal/conversions"
@@ -1,11 +1,21 @@
1
- require 'active_support/core_ext/kernel/singleton_class'
2
- require 'active_support/core_ext/module/remove_method'
3
- require 'active_support/core_ext/array/extract_options'
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/core_ext/module/redefine_method"
4
4
 
5
5
  class Class
6
6
  # Declare a class-level attribute whose value is inheritable by subclasses.
7
7
  # Subclasses can change their own value and it will not impact parent class.
8
8
  #
9
+ # ==== Options
10
+ #
11
+ # * <tt>:instance_reader</tt> - Sets the instance reader method (defaults to true).
12
+ # * <tt>:instance_writer</tt> - Sets the instance writer method (defaults to true).
13
+ # * <tt>:instance_accessor</tt> - Sets both instance methods (defaults to true).
14
+ # * <tt>:instance_predicate</tt> - Sets a predicate method (defaults to true).
15
+ # * <tt>:default</tt> - Sets a default value for the attribute (defaults to nil).
16
+ #
17
+ # ==== Examples
18
+ #
9
19
  # class Base
10
20
  # class_attribute :setting
11
21
  # end
@@ -20,14 +30,14 @@ class Class
20
30
  # Base.setting # => true
21
31
  #
22
32
  # In the above case as long as Subclass does not assign a value to setting
23
- # by performing <tt>Subclass.setting = _something_ </tt>, <tt>Subclass.setting</tt>
33
+ # by performing <tt>Subclass.setting = _something_</tt>, <tt>Subclass.setting</tt>
24
34
  # would read value assigned to parent class. Once Subclass assigns a value then
25
35
  # the value assigned by Subclass would be returned.
26
36
  #
27
37
  # This matches normal Ruby method inheritance: think of writing an attribute
28
38
  # on a subclass as overriding the reader method. However, you need to be aware
29
39
  # when using +class_attribute+ with mutable structures as +Array+ or +Hash+.
30
- # In such cases, you don't want to do changes in places but use setters:
40
+ # In such cases, you don't want to do changes in place. Instead use setters:
31
41
  #
32
42
  # Base.setting = []
33
43
  # Base.setting # => []
@@ -68,61 +78,54 @@ class Class
68
78
  # object.setting = false # => NoMethodError
69
79
  #
70
80
  # To opt out of both instance methods, pass <tt>instance_accessor: false</tt>.
71
- def class_attribute(*attrs)
72
- options = attrs.extract_options!
73
- instance_reader = options.fetch(:instance_accessor, true) && options.fetch(:instance_reader, true)
74
- instance_writer = options.fetch(:instance_accessor, true) && options.fetch(:instance_writer, true)
75
- instance_predicate = options.fetch(:instance_predicate, true)
81
+ #
82
+ # To set a default value for the attribute, pass <tt>default:</tt>, like so:
83
+ #
84
+ # class_attribute :settings, default: {}
85
+ def class_attribute(*attrs, instance_accessor: true,
86
+ instance_reader: instance_accessor, instance_writer: instance_accessor, instance_predicate: true, default: nil)
76
87
 
88
+ class_methods, methods = [], []
77
89
  attrs.each do |name|
78
- remove_possible_singleton_method(name)
79
- define_singleton_method(name) { nil }
80
-
81
- remove_possible_singleton_method("#{name}?")
82
- define_singleton_method("#{name}?") { !!public_send(name) } if instance_predicate
83
-
84
- ivar = "@#{name}"
90
+ unless name.is_a?(Symbol) || name.is_a?(String)
91
+ raise TypeError, "#{name.inspect} is not a symbol nor a string"
92
+ end
85
93
 
86
- remove_possible_singleton_method("#{name}=")
87
- define_singleton_method("#{name}=") do |val|
88
- singleton_class.class_eval do
89
- remove_possible_method(name)
90
- define_method(name) { val }
94
+ class_methods << <<~RUBY # In case the method exists and is not public
95
+ silence_redefinition_of_method def #{name}
91
96
  end
97
+ RUBY
92
98
 
93
- if singleton_class?
94
- class_eval do
95
- remove_possible_method(name)
96
- define_method(name) do
97
- if instance_variable_defined? ivar
98
- instance_variable_get ivar
99
- else
100
- singleton_class.send name
101
- end
102
- end
103
- end
99
+ methods << <<~RUBY if instance_reader
100
+ silence_redefinition_of_method def #{name}
101
+ defined?(@#{name}) ? @#{name} : self.class.#{name}
104
102
  end
105
- val
106
- end
103
+ RUBY
107
104
 
108
- if instance_reader
109
- remove_possible_method name
110
- define_method(name) do
111
- if instance_variable_defined?(ivar)
112
- instance_variable_get ivar
113
- else
114
- self.class.public_send name
115
- end
105
+ class_methods << <<~RUBY
106
+ silence_redefinition_of_method def #{name}=(value)
107
+ redefine_method(:#{name}) { value } if singleton_class?
108
+ redefine_singleton_method(:#{name}) { value }
109
+ value
116
110
  end
111
+ RUBY
117
112
 
118
- remove_possible_method "#{name}?"
119
- define_method("#{name}?") { !!public_send(name) } if instance_predicate
120
- end
113
+ methods << <<~RUBY if instance_writer
114
+ silence_redefinition_of_method(:#{name}=)
115
+ attr_writer :#{name}
116
+ RUBY
121
117
 
122
- if instance_writer
123
- remove_possible_method "#{name}="
124
- attr_writer name
118
+ if instance_predicate
119
+ class_methods << "silence_redefinition_of_method def #{name}?; !!self.#{name}; end"
120
+ if instance_reader
121
+ methods << "silence_redefinition_of_method def #{name}?; !!self.#{name}; end"
122
+ end
125
123
  end
126
124
  end
125
+
126
+ location = caller_locations(1, 1).first
127
+ class_eval(["class << self", *class_methods, "end", *methods].join(";").tr("\n", ";"), location.path, location.lineno)
128
+
129
+ attrs.each { |name| public_send("#{name}=", default) }
127
130
  end
128
131
  end
@@ -1,4 +1,6 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # cattr_* became mattr_* aliases in 7dfbd91b0780fbd6a1dd9bfbc176e10894871d2d,
2
4
  # but we keep this around for libraries that directly require it knowing they
3
5
  # want cattr_*. No need to deprecate.
4
- require 'active_support/core_ext/module/attribute_accessors'
6
+ require "active_support/core_ext/module/attribute_accessors"
@@ -1,26 +1,22 @@
1
- require 'active_support/core_ext/module/anonymous'
2
- require 'active_support/core_ext/module/reachable'
1
+ # frozen_string_literal: true
3
2
 
4
3
  class Class
5
- begin
6
- # Test if this Ruby supports each_object against singleton_class
7
- ObjectSpace.each_object(Numeric.singleton_class) {}
8
-
9
- def descendants # :nodoc:
10
- descendants = []
11
- ObjectSpace.each_object(singleton_class) do |k|
12
- descendants.unshift k unless k == self
13
- end
14
- descendants
15
- end
16
- rescue StandardError # JRuby 9.0.4.0 and earlier
17
- def descendants # :nodoc:
18
- descendants = []
19
- ObjectSpace.each_object(Class) do |k|
20
- descendants.unshift k if k < self
21
- end
22
- descendants.uniq!
23
- descendants
4
+ # Returns an array with all classes that are < than its receiver.
5
+ #
6
+ # class C; end
7
+ # C.descendants # => []
8
+ #
9
+ # class B < C; end
10
+ # C.descendants # => [B]
11
+ #
12
+ # class A < B; end
13
+ # C.descendants # => [B, A]
14
+ #
15
+ # class D < C; end
16
+ # C.descendants # => [B, A, D]
17
+ def descendants
18
+ ObjectSpace.each_object(singleton_class).reject do |k|
19
+ k.singleton_class? || k == self
24
20
  end
25
21
  end
26
22
 
@@ -32,10 +28,6 @@ class Class
32
28
  #
33
29
  # Foo.subclasses # => [Bar]
34
30
  def subclasses
35
- subclasses, chain = [], descendants
36
- chain.each do |k|
37
- subclasses << k unless chain.any? { |c| c > k }
38
- end
39
- subclasses
31
+ descendants.select { |descendant| descendant.superclass == self }
40
32
  end
41
33
  end
@@ -1,2 +1,4 @@
1
- require 'active_support/core_ext/class/attribute'
2
- require 'active_support/core_ext/class/subclasses'
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/core_ext/class/attribute"
4
+ require "active_support/core_ext/class/subclasses"
@@ -1,4 +1,6 @@
1
- require 'active_support/core_ext/object/acts_like'
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/core_ext/object/acts_like"
2
4
 
3
5
  class Date
4
6
  # Duck-types as a Date-like class. See Object#acts_like?.
@@ -1,4 +1,6 @@
1
- require 'date'
1
+ # frozen_string_literal: true
2
+
3
+ require "date"
2
4
 
3
5
  class Date #:nodoc:
4
6
  # No Date is blank:
@@ -1,9 +1,11 @@
1
- require 'date'
2
- require 'active_support/duration'
3
- require 'active_support/core_ext/object/acts_like'
4
- require 'active_support/core_ext/date/zones'
5
- require 'active_support/core_ext/time/zones'
6
- require 'active_support/core_ext/date_and_time/calculations'
1
+ # frozen_string_literal: true
2
+
3
+ require "date"
4
+ require "active_support/duration"
5
+ require "active_support/core_ext/object/acts_like"
6
+ require "active_support/core_ext/date/zones"
7
+ require "active_support/core_ext/time/zones"
8
+ require "active_support/core_ext/date_and_time/calculations"
7
9
 
8
10
  class Date
9
11
  include DateAndTime::Calculations
@@ -108,12 +110,13 @@ class Date
108
110
  # Provides precise Date calculations for years, months, and days. The +options+ parameter takes a hash with
109
111
  # any of these keys: <tt>:years</tt>, <tt>:months</tt>, <tt>:weeks</tt>, <tt>:days</tt>.
110
112
  def advance(options)
111
- options = options.dup
112
113
  d = self
113
- d = d >> options.delete(:years) * 12 if options[:years]
114
- d = d >> options.delete(:months) if options[:months]
115
- d = d + options.delete(:weeks) * 7 if options[:weeks]
116
- d = d + options.delete(:days) if options[:days]
114
+
115
+ d = d >> options[:years] * 12 if options[:years]
116
+ d = d >> options[:months] if options[:months]
117
+ d = d + options[:weeks] * 7 if options[:weeks]
118
+ d = d + options[:days] if options[:days]
119
+
117
120
  d
118
121
  end
119
122
 
@@ -129,11 +132,11 @@ class Date
129
132
  options.fetch(:day, day)
130
133
  )
131
134
  end
132
-
135
+
133
136
  # Allow Date to be compared with Time by converting to DateTime and relying on the <=> from there.
134
137
  def compare_with_coercion(other)
135
138
  if other.is_a?(Time)
136
- self.to_datetime <=> other
139
+ to_datetime <=> other
137
140
  else
138
141
  compare_without_coercion(other)
139
142
  end
@@ -1,30 +1,25 @@
1
- require 'date'
2
- require 'active_support/inflector/methods'
3
- require 'active_support/core_ext/date/zones'
4
- require 'active_support/core_ext/module/remove_method'
1
+ # frozen_string_literal: true
2
+
3
+ require "date"
4
+ require "active_support/inflector/methods"
5
+ require "active_support/core_ext/date/zones"
6
+ require "active_support/core_ext/module/redefine_method"
5
7
 
6
8
  class Date
7
9
  DATE_FORMATS = {
8
- :short => '%d %b',
9
- :long => '%B %d, %Y',
10
- :db => '%Y-%m-%d',
11
- :number => '%Y%m%d',
12
- :long_ordinal => lambda { |date|
10
+ short: "%d %b",
11
+ long: "%B %d, %Y",
12
+ db: "%Y-%m-%d",
13
+ inspect: "%Y-%m-%d",
14
+ number: "%Y%m%d",
15
+ long_ordinal: lambda { |date|
13
16
  day_format = ActiveSupport::Inflector.ordinalize(date.day)
14
17
  date.strftime("%B #{day_format}, %Y") # => "April 25th, 2007"
15
18
  },
16
- :rfc822 => '%d %b %Y',
17
- :iso8601 => lambda { |date| date.iso8601 }
19
+ rfc822: "%d %b %Y",
20
+ iso8601: lambda { |date| date.iso8601 }
18
21
  }
19
22
 
20
- # Ruby 1.9 has Date#to_time which converts to localtime only.
21
- remove_method :to_time
22
-
23
- # Ruby 1.9 has Date#xmlschema which converts to a string without the time
24
- # component. This removal may generate an issue on FreeBSD, that's why we
25
- # need to use remove_possible_method here
26
- remove_possible_method :xmlschema
27
-
28
23
  # Convert to a formatted string. See DATE_FORMATS for predefined formats.
29
24
  #
30
25
  # This method is aliased to <tt>to_s</tt>.
@@ -65,11 +60,13 @@ class Date
65
60
 
66
61
  # Overrides the default inspect method with a human readable one, e.g., "Mon, 21 Feb 2005"
67
62
  def readable_inspect
68
- strftime('%a, %d %b %Y')
63
+ strftime("%a, %d %b %Y")
69
64
  end
70
65
  alias_method :default_inspect, :inspect
71
66
  alias_method :inspect, :readable_inspect
72
67
 
68
+ silence_redefinition_of_method :to_time
69
+
73
70
  # Converts a Date instance to a Time, where the time is set to the beginning of the day.
74
71
  # The timezone can be either :local or :utc (default :local).
75
72
  #
@@ -79,11 +76,16 @@ class Date
79
76
  # date.to_time(:local) # => 2007-11-10 00:00:00 0800
80
77
  #
81
78
  # date.to_time(:utc) # => 2007-11-10 00:00:00 UTC
79
+ #
80
+ # NOTE: The :local timezone is Ruby's *process* timezone, i.e. ENV['TZ'].
81
+ # If the *application's* timezone is needed, then use +in_time_zone+ instead.
82
82
  def to_time(form = :local)
83
83
  raise ArgumentError, "Expected :local or :utc, got #{form.inspect}." unless [:local, :utc].include?(form)
84
- ::Time.send(form, year, month, day)
84
+ ::Time.public_send(form, year, month, day)
85
85
  end
86
86
 
87
+ silence_redefinition_of_method :xmlschema
88
+
87
89
  # Returns a string which represents the time in used time zone as DateTime
88
90
  # defined by XML Schema:
89
91
  #
@@ -1,5 +1,7 @@
1
- require 'date'
2
- require 'active_support/core_ext/date_and_time/zones'
1
+ # frozen_string_literal: true
2
+
3
+ require "date"
4
+ require "active_support/core_ext/date_and_time/zones"
3
5
 
4
6
  class Date
5
7
  include DateAndTime::Zones
@@ -1,5 +1,7 @@
1
- require 'active_support/core_ext/date/acts_like'
2
- require 'active_support/core_ext/date/blank'
3
- require 'active_support/core_ext/date/calculations'
4
- require 'active_support/core_ext/date/conversions'
5
- require 'active_support/core_ext/date/zones'
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/core_ext/date/acts_like"
4
+ require "active_support/core_ext/date/blank"
5
+ require "active_support/core_ext/date/calculations"
6
+ require "active_support/core_ext/date/conversions"
7
+ require "active_support/core_ext/date/zones"