activesupport 4.0.12 → 7.0.2.4

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 (295) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +249 -501
  3. data/MIT-LICENSE +2 -2
  4. data/README.rdoc +10 -5
  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 +41 -13
  9. data/lib/active_support/benchmarkable.rb +7 -15
  10. data/lib/active_support/builder.rb +3 -1
  11. data/lib/active_support/cache/file_store.rb +96 -74
  12. data/lib/active_support/cache/mem_cache_store.rb +211 -103
  13. data/lib/active_support/cache/memory_store.rb +90 -58
  14. data/lib/active_support/cache/null_store.rb +19 -7
  15. data/lib/active_support/cache/redis_cache_store.rb +468 -0
  16. data/lib/active_support/cache/strategy/local_cache.rb +86 -83
  17. data/lib/active_support/cache/strategy/local_cache_middleware.rb +45 -0
  18. data/lib/active_support/cache.rb +580 -241
  19. data/lib/active_support/callbacks.rb +812 -425
  20. data/lib/active_support/code_generator.rb +65 -0
  21. data/lib/active_support/concern.rb +103 -14
  22. data/lib/active_support/concurrency/load_interlock_aware_monitor.rb +33 -0
  23. data/lib/active_support/concurrency/share_lock.rb +226 -0
  24. data/lib/active_support/configurable.rb +21 -19
  25. data/lib/active_support/configuration_file.rb +51 -0
  26. data/lib/active_support/core_ext/array/access.rb +47 -1
  27. data/lib/active_support/core_ext/array/conversions.rb +35 -44
  28. data/lib/active_support/core_ext/array/deprecated_conversions.rb +25 -0
  29. data/lib/active_support/core_ext/array/extract.rb +21 -0
  30. data/lib/active_support/core_ext/array/extract_options.rb +2 -0
  31. data/lib/active_support/core_ext/array/grouping.rb +26 -16
  32. data/lib/active_support/core_ext/array/inquiry.rb +19 -0
  33. data/lib/active_support/core_ext/array/wrap.rb +7 -4
  34. data/lib/active_support/core_ext/array.rb +10 -7
  35. data/lib/active_support/core_ext/benchmark.rb +5 -3
  36. data/lib/active_support/core_ext/big_decimal/conversions.rb +9 -26
  37. data/lib/active_support/core_ext/big_decimal.rb +3 -1
  38. data/lib/active_support/core_ext/class/attribute.rb +52 -49
  39. data/lib/active_support/core_ext/class/attribute_accessors.rb +5 -169
  40. data/lib/active_support/core_ext/class/subclasses.rb +25 -26
  41. data/lib/active_support/core_ext/class.rb +4 -4
  42. data/lib/active_support/core_ext/date/acts_like.rb +3 -1
  43. data/lib/active_support/core_ext/date/blank.rb +14 -0
  44. data/lib/active_support/core_ext/date/calculations.rb +31 -18
  45. data/lib/active_support/core_ext/date/conversions.rb +43 -32
  46. data/lib/active_support/core_ext/date/deprecated_conversions.rb +26 -0
  47. data/lib/active_support/core_ext/date/zones.rb +5 -34
  48. data/lib/active_support/core_ext/date.rb +7 -4
  49. data/lib/active_support/core_ext/date_and_time/calculations.rb +198 -66
  50. data/lib/active_support/core_ext/date_and_time/compatibility.rb +31 -0
  51. data/lib/active_support/core_ext/date_and_time/zones.rb +40 -0
  52. data/lib/active_support/core_ext/date_time/acts_like.rb +4 -2
  53. data/lib/active_support/core_ext/date_time/blank.rb +14 -0
  54. data/lib/active_support/core_ext/date_time/calculations.rb +79 -38
  55. data/lib/active_support/core_ext/date_time/compatibility.rb +18 -0
  56. data/lib/active_support/core_ext/date_time/conversions.rb +31 -26
  57. data/lib/active_support/core_ext/date_time/deprecated_conversions.rb +22 -0
  58. data/lib/active_support/core_ext/date_time.rb +8 -4
  59. data/lib/active_support/core_ext/digest/uuid.rb +79 -0
  60. data/lib/active_support/core_ext/digest.rb +3 -0
  61. data/lib/active_support/core_ext/enumerable.rb +249 -17
  62. data/lib/active_support/core_ext/file/atomic.rb +41 -32
  63. data/lib/active_support/core_ext/file.rb +3 -1
  64. data/lib/active_support/core_ext/hash/conversions.rb +71 -49
  65. data/lib/active_support/core_ext/hash/deep_merge.rb +9 -13
  66. data/lib/active_support/core_ext/hash/deep_transform_values.rb +46 -0
  67. data/lib/active_support/core_ext/hash/except.rb +14 -5
  68. data/lib/active_support/core_ext/hash/indifferent_access.rb +5 -3
  69. data/lib/active_support/core_ext/hash/keys.rb +39 -56
  70. data/lib/active_support/core_ext/hash/reverse_merge.rb +5 -2
  71. data/lib/active_support/core_ext/hash/slice.rb +8 -23
  72. data/lib/active_support/core_ext/hash.rb +10 -8
  73. data/lib/active_support/core_ext/integer/inflections.rb +3 -1
  74. data/lib/active_support/core_ext/integer/multiple.rb +3 -1
  75. data/lib/active_support/core_ext/integer/time.rb +11 -33
  76. data/lib/active_support/core_ext/integer.rb +5 -3
  77. data/lib/active_support/core_ext/kernel/concern.rb +14 -0
  78. data/lib/active_support/core_ext/kernel/reporting.rb +9 -78
  79. data/lib/active_support/core_ext/kernel/singleton_class.rb +2 -0
  80. data/lib/active_support/core_ext/kernel.rb +5 -4
  81. data/lib/active_support/core_ext/load_error.rb +5 -21
  82. data/lib/active_support/core_ext/module/aliasing.rb +6 -44
  83. data/lib/active_support/core_ext/module/anonymous.rb +12 -1
  84. data/lib/active_support/core_ext/module/attr_internal.rb +8 -8
  85. data/lib/active_support/core_ext/module/attribute_accessors.rb +186 -44
  86. data/lib/active_support/core_ext/module/attribute_accessors_per_thread.rb +157 -0
  87. data/lib/active_support/core_ext/module/concerning.rb +140 -0
  88. data/lib/active_support/core_ext/module/delegation.rb +172 -45
  89. data/lib/active_support/core_ext/module/deprecation.rb +3 -3
  90. data/lib/active_support/core_ext/module/introspection.rb +23 -38
  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 -10
  94. data/lib/active_support/core_ext/name_error.rb +45 -4
  95. data/lib/active_support/core_ext/numeric/bytes.rb +22 -0
  96. data/lib/active_support/core_ext/numeric/conversions.rb +135 -127
  97. data/lib/active_support/core_ext/numeric/deprecated_conversions.rb +60 -0
  98. data/lib/active_support/core_ext/numeric/time.rb +37 -50
  99. data/lib/active_support/core_ext/numeric.rb +6 -3
  100. data/lib/active_support/core_ext/object/acts_like.rb +41 -6
  101. data/lib/active_support/core_ext/object/blank.rb +70 -20
  102. data/lib/active_support/core_ext/object/conversions.rb +6 -4
  103. data/lib/active_support/core_ext/object/deep_dup.rb +19 -10
  104. data/lib/active_support/core_ext/object/duplicable.rb +17 -47
  105. data/lib/active_support/core_ext/object/inclusion.rb +18 -15
  106. data/lib/active_support/core_ext/object/instance_variables.rb +3 -1
  107. data/lib/active_support/core_ext/object/json.rb +244 -0
  108. data/lib/active_support/core_ext/object/to_param.rb +3 -1
  109. data/lib/active_support/core_ext/object/to_query.rb +21 -8
  110. data/lib/active_support/core_ext/object/try.rb +106 -26
  111. data/lib/active_support/core_ext/object/with_options.rb +64 -5
  112. data/lib/active_support/core_ext/object.rb +14 -12
  113. data/lib/active_support/core_ext/pathname/existence.rb +21 -0
  114. data/lib/active_support/core_ext/pathname.rb +3 -0
  115. data/lib/active_support/core_ext/range/compare_range.rb +57 -0
  116. data/lib/active_support/core_ext/range/conversions.rb +37 -15
  117. data/lib/active_support/core_ext/range/deprecated_conversions.rb +26 -0
  118. data/lib/active_support/core_ext/range/each.rb +18 -17
  119. data/lib/active_support/core_ext/range/include_time_with_zone.rb +7 -0
  120. data/lib/active_support/core_ext/range/overlaps.rb +2 -0
  121. data/lib/active_support/core_ext/range.rb +7 -4
  122. data/lib/active_support/core_ext/regexp.rb +10 -1
  123. data/lib/active_support/core_ext/securerandom.rb +45 -0
  124. data/lib/active_support/core_ext/string/access.rb +42 -51
  125. data/lib/active_support/core_ext/string/behavior.rb +3 -1
  126. data/lib/active_support/core_ext/string/conversions.rb +18 -13
  127. data/lib/active_support/core_ext/string/exclude.rb +5 -3
  128. data/lib/active_support/core_ext/string/filters.rb +97 -7
  129. data/lib/active_support/core_ext/string/indent.rb +6 -4
  130. data/lib/active_support/core_ext/string/inflections.rb +106 -25
  131. data/lib/active_support/core_ext/string/inquiry.rb +4 -1
  132. data/lib/active_support/core_ext/string/multibyte.rb +18 -9
  133. data/lib/active_support/core_ext/string/output_safety.rb +227 -54
  134. data/lib/active_support/core_ext/string/starts_ends_with.rb +4 -2
  135. data/lib/active_support/core_ext/string/strip.rb +6 -5
  136. data/lib/active_support/core_ext/string/zones.rb +4 -1
  137. data/lib/active_support/core_ext/string.rb +15 -13
  138. data/lib/active_support/core_ext/symbol/starts_ends_with.rb +6 -0
  139. data/lib/active_support/core_ext/symbol.rb +3 -0
  140. data/lib/active_support/core_ext/time/acts_like.rb +3 -1
  141. data/lib/active_support/core_ext/time/calculations.rb +178 -116
  142. data/lib/active_support/core_ext/time/compatibility.rb +16 -0
  143. data/lib/active_support/core_ext/time/conversions.rb +37 -25
  144. data/lib/active_support/core_ext/time/deprecated_conversions.rb +22 -0
  145. data/lib/active_support/core_ext/time/zones.rb +44 -42
  146. data/lib/active_support/core_ext/time.rb +8 -5
  147. data/lib/active_support/core_ext/uri.rb +4 -25
  148. data/lib/active_support/core_ext.rb +4 -2
  149. data/lib/active_support/current_attributes/test_helper.rb +13 -0
  150. data/lib/active_support/current_attributes.rb +226 -0
  151. data/lib/active_support/dependencies/autoload.rb +3 -1
  152. data/lib/active_support/dependencies/interlock.rb +49 -0
  153. data/lib/active_support/dependencies/require_dependency.rb +28 -0
  154. data/lib/active_support/dependencies.rb +71 -696
  155. data/lib/active_support/deprecation/behaviors.rb +65 -16
  156. data/lib/active_support/deprecation/constant_accessor.rb +52 -0
  157. data/lib/active_support/deprecation/disallowed.rb +56 -0
  158. data/lib/active_support/deprecation/instance_delegator.rb +16 -2
  159. data/lib/active_support/deprecation/method_wrappers.rb +62 -21
  160. data/lib/active_support/deprecation/proxy_wrappers.rb +82 -31
  161. data/lib/active_support/deprecation/reporting.rb +81 -18
  162. data/lib/active_support/deprecation.rb +19 -11
  163. data/lib/active_support/descendants_tracker.rb +192 -34
  164. data/lib/active_support/digest.rb +22 -0
  165. data/lib/active_support/duration/iso8601_parser.rb +123 -0
  166. data/lib/active_support/duration/iso8601_serializer.rb +67 -0
  167. data/lib/active_support/duration.rb +437 -39
  168. data/lib/active_support/encrypted_configuration.rb +56 -0
  169. data/lib/active_support/encrypted_file.rb +117 -0
  170. data/lib/active_support/environment_inquirer.rb +20 -0
  171. data/lib/active_support/error_reporter.rb +117 -0
  172. data/lib/active_support/evented_file_update_checker.rb +170 -0
  173. data/lib/active_support/execution_context/test_helper.rb +13 -0
  174. data/lib/active_support/execution_context.rb +53 -0
  175. data/lib/active_support/execution_wrapper.rb +151 -0
  176. data/lib/active_support/executor/test_helper.rb +7 -0
  177. data/lib/active_support/executor.rb +8 -0
  178. data/lib/active_support/file_update_checker.rb +62 -37
  179. data/lib/active_support/fork_tracker.rb +71 -0
  180. data/lib/active_support/gem_version.rb +17 -0
  181. data/lib/active_support/gzip.rb +7 -5
  182. data/lib/active_support/hash_with_indifferent_access.rb +207 -54
  183. data/lib/active_support/html_safe_translation.rb +43 -0
  184. data/lib/active_support/i18n.rb +10 -6
  185. data/lib/active_support/i18n_railtie.rb +48 -19
  186. data/lib/active_support/inflections.rb +19 -12
  187. data/lib/active_support/inflector/inflections.rb +97 -37
  188. data/lib/active_support/inflector/methods.rb +192 -157
  189. data/lib/active_support/inflector/transliterate.rb +83 -33
  190. data/lib/active_support/inflector.rb +7 -5
  191. data/lib/active_support/isolated_execution_state.rb +64 -0
  192. data/lib/active_support/json/decoding.rb +37 -42
  193. data/lib/active_support/json/encoding.rb +93 -293
  194. data/lib/active_support/json.rb +4 -2
  195. data/lib/active_support/key_generator.rb +30 -47
  196. data/lib/active_support/lazy_load_hooks.rb +54 -21
  197. data/lib/active_support/locale/en.rb +33 -0
  198. data/lib/active_support/locale/en.yml +10 -4
  199. data/lib/active_support/log_subscriber/test_helper.rb +14 -12
  200. data/lib/active_support/log_subscriber.rb +61 -18
  201. data/lib/active_support/logger.rb +40 -4
  202. data/lib/active_support/logger_silence.rb +17 -20
  203. data/lib/active_support/logger_thread_safe_level.rb +69 -0
  204. data/lib/active_support/message_encryptor.rb +178 -55
  205. data/lib/active_support/message_verifier.rb +195 -26
  206. data/lib/active_support/messages/metadata.rb +80 -0
  207. data/lib/active_support/messages/rotation_configuration.rb +23 -0
  208. data/lib/active_support/messages/rotator.rb +57 -0
  209. data/lib/active_support/multibyte/chars.rb +45 -92
  210. data/lib/active_support/multibyte/unicode.rb +44 -377
  211. data/lib/active_support/multibyte.rb +5 -3
  212. data/lib/active_support/notifications/fanout.rb +177 -44
  213. data/lib/active_support/notifications/instrumenter.rb +117 -17
  214. data/lib/active_support/notifications.rb +106 -39
  215. data/lib/active_support/number_helper/number_converter.rb +181 -0
  216. data/lib/active_support/number_helper/number_to_currency_converter.rb +46 -0
  217. data/lib/active_support/number_helper/number_to_delimited_converter.rb +30 -0
  218. data/lib/active_support/number_helper/number_to_human_converter.rb +69 -0
  219. data/lib/active_support/number_helper/number_to_human_size_converter.rb +60 -0
  220. data/lib/active_support/number_helper/number_to_percentage_converter.rb +16 -0
  221. data/lib/active_support/number_helper/number_to_phone_converter.rb +59 -0
  222. data/lib/active_support/number_helper/number_to_rounded_converter.rb +59 -0
  223. data/lib/active_support/number_helper/rounding_helper.rb +46 -0
  224. data/lib/active_support/number_helper.rb +152 -394
  225. data/lib/active_support/option_merger.rb +18 -5
  226. data/lib/active_support/ordered_hash.rb +8 -6
  227. data/lib/active_support/ordered_options.rb +43 -7
  228. data/lib/active_support/parameter_filter.rb +138 -0
  229. data/lib/active_support/per_thread_registry.rb +24 -11
  230. data/lib/active_support/proxy_object.rb +2 -0
  231. data/lib/active_support/rails.rb +10 -11
  232. data/lib/active_support/railtie.rb +118 -12
  233. data/lib/active_support/reloader.rb +130 -0
  234. data/lib/active_support/rescuable.rb +112 -57
  235. data/lib/active_support/ruby_features.rb +7 -0
  236. data/lib/active_support/secure_compare_rotator.rb +51 -0
  237. data/lib/active_support/security_utils.rb +38 -0
  238. data/lib/active_support/string_inquirer.rb +11 -4
  239. data/lib/active_support/subscriber.rb +109 -39
  240. data/lib/active_support/tagged_logging.rb +54 -17
  241. data/lib/active_support/test_case.rb +121 -37
  242. data/lib/active_support/testing/assertions.rb +177 -39
  243. data/lib/active_support/testing/autorun.rb +5 -3
  244. data/lib/active_support/testing/constant_lookup.rb +3 -6
  245. data/lib/active_support/testing/declarative.rb +10 -22
  246. data/lib/active_support/testing/deprecation.rb +65 -11
  247. data/lib/active_support/testing/file_fixtures.rb +38 -0
  248. data/lib/active_support/testing/isolation.rb +56 -87
  249. data/lib/active_support/testing/method_call_assertions.rb +70 -0
  250. data/lib/active_support/testing/parallelization/server.rb +82 -0
  251. data/lib/active_support/testing/parallelization/worker.rb +103 -0
  252. data/lib/active_support/testing/parallelization.rb +55 -0
  253. data/lib/active_support/testing/parallelize_executor.rb +76 -0
  254. data/lib/active_support/testing/setup_and_teardown.rb +30 -10
  255. data/lib/active_support/testing/stream.rb +41 -0
  256. data/lib/active_support/testing/tagged_logging.rb +6 -4
  257. data/lib/active_support/testing/time_helpers.rb +246 -0
  258. data/lib/active_support/time.rb +13 -13
  259. data/lib/active_support/time_with_zone.rb +315 -90
  260. data/lib/active_support/values/time_zone.rb +306 -135
  261. data/lib/active_support/version.rb +6 -7
  262. data/lib/active_support/xml_mini/jdom.rb +117 -115
  263. data/lib/active_support/xml_mini/libxml.rb +22 -21
  264. data/lib/active_support/xml_mini/libxmlsax.rb +17 -19
  265. data/lib/active_support/xml_mini/nokogiri.rb +19 -19
  266. data/lib/active_support/xml_mini/nokogirisax.rb +16 -17
  267. data/lib/active_support/xml_mini/rexml.rb +25 -17
  268. data/lib/active_support/xml_mini.rb +67 -56
  269. data/lib/active_support.rb +58 -3
  270. metadata +125 -66
  271. data/lib/active_support/basic_object.rb +0 -11
  272. data/lib/active_support/buffered_logger.rb +0 -21
  273. data/lib/active_support/concurrency/latch.rb +0 -27
  274. data/lib/active_support/core_ext/array/prepend_and_append.rb +0 -7
  275. data/lib/active_support/core_ext/array/uniq_by.rb +0 -19
  276. data/lib/active_support/core_ext/class/delegating_attributes.rb +0 -40
  277. data/lib/active_support/core_ext/date_time/zones.rb +0 -24
  278. data/lib/active_support/core_ext/hash/diff.rb +0 -14
  279. data/lib/active_support/core_ext/kernel/agnostics.rb +0 -11
  280. data/lib/active_support/core_ext/kernel/debugger.rb +0 -10
  281. data/lib/active_support/core_ext/logger.rb +0 -67
  282. data/lib/active_support/core_ext/marshal.rb +0 -21
  283. data/lib/active_support/core_ext/module/qualified_const.rb +0 -52
  284. data/lib/active_support/core_ext/module/reachable.rb +0 -8
  285. data/lib/active_support/core_ext/object/to_json.rb +0 -27
  286. data/lib/active_support/core_ext/proc.rb +0 -17
  287. data/lib/active_support/core_ext/range/include_range.rb +0 -23
  288. data/lib/active_support/core_ext/string/encoding.rb +0 -8
  289. data/lib/active_support/core_ext/struct.rb +0 -6
  290. data/lib/active_support/core_ext/thread.rb +0 -79
  291. data/lib/active_support/core_ext/time/marshal.rb +0 -30
  292. data/lib/active_support/file_watcher.rb +0 -36
  293. data/lib/active_support/json/variable.rb +0 -18
  294. data/lib/active_support/testing/pending.rb +0 -14
  295. data/lib/active_support/values/unicode_tables.dat +0 -0
@@ -1,170 +1,6 @@
1
- require 'active_support/core_ext/array/extract_options'
1
+ # frozen_string_literal: true
2
2
 
3
- # Extends the class object with class and instance accessors for class attributes,
4
- # just like the native attr* accessors for instance attributes.
5
- class Class
6
- # Defines a class attribute if it's not defined and creates a reader method that
7
- # returns the attribute value.
8
- #
9
- # class Person
10
- # cattr_reader :hair_colors
11
- # end
12
- #
13
- # Person.class_variable_set("@@hair_colors", [:brown, :black])
14
- # Person.hair_colors # => [:brown, :black]
15
- # Person.new.hair_colors # => [:brown, :black]
16
- #
17
- # The attribute name must be a valid method name in Ruby.
18
- #
19
- # class Person
20
- # cattr_reader :"1_Badname "
21
- # end
22
- # # => NameError: invalid attribute name
23
- #
24
- # If you want to opt out the instance reader method, you can pass <tt>instance_reader: false</tt>
25
- # or <tt>instance_accessor: false</tt>.
26
- #
27
- # class Person
28
- # cattr_reader :hair_colors, instance_reader: false
29
- # end
30
- #
31
- # Person.new.hair_colors # => NoMethodError
32
- def cattr_reader(*syms)
33
- options = syms.extract_options!
34
- syms.each do |sym|
35
- raise NameError.new("invalid class attribute name: #{sym}") unless sym =~ /^[_A-Za-z]\w*$/
36
- class_eval(<<-EOS, __FILE__, __LINE__ + 1)
37
- unless defined? @@#{sym}
38
- @@#{sym} = nil
39
- end
40
-
41
- def self.#{sym}
42
- @@#{sym}
43
- end
44
- EOS
45
-
46
- unless options[:instance_reader] == false || options[:instance_accessor] == false
47
- class_eval(<<-EOS, __FILE__, __LINE__ + 1)
48
- def #{sym}
49
- @@#{sym}
50
- end
51
- EOS
52
- end
53
- end
54
- end
55
-
56
- # Defines a class attribute if it's not defined and creates a writer method to allow
57
- # assignment to the attribute.
58
- #
59
- # class Person
60
- # cattr_writer :hair_colors
61
- # end
62
- #
63
- # Person.hair_colors = [:brown, :black]
64
- # Person.class_variable_get("@@hair_colors") # => [:brown, :black]
65
- # Person.new.hair_colors = [:blonde, :red]
66
- # Person.class_variable_get("@@hair_colors") # => [:blonde, :red]
67
- #
68
- # The attribute name must be a valid method name in Ruby.
69
- #
70
- # class Person
71
- # cattr_writer :"1_Badname "
72
- # end
73
- # # => NameError: invalid attribute name
74
- #
75
- # If you want to opt out the instance writer method, pass <tt>instance_writer: false</tt>
76
- # or <tt>instance_accessor: false</tt>.
77
- #
78
- # class Person
79
- # cattr_writer :hair_colors, instance_writer: false
80
- # end
81
- #
82
- # Person.new.hair_colors = [:blonde, :red] # => NoMethodError
83
- #
84
- # Also, you can pass a block to set up the attribute with a default value.
85
- #
86
- # class Person
87
- # cattr_writer :hair_colors do
88
- # [:brown, :black, :blonde, :red]
89
- # end
90
- # end
91
- #
92
- # Person.class_variable_get("@@hair_colors") # => [:brown, :black, :blonde, :red]
93
- def cattr_writer(*syms)
94
- options = syms.extract_options!
95
- syms.each do |sym|
96
- raise NameError.new("invalid class attribute name: #{sym}") unless sym =~ /^[_A-Za-z]\w*$/
97
- class_eval(<<-EOS, __FILE__, __LINE__ + 1)
98
- unless defined? @@#{sym}
99
- @@#{sym} = nil
100
- end
101
-
102
- def self.#{sym}=(obj)
103
- @@#{sym} = obj
104
- end
105
- EOS
106
-
107
- unless options[:instance_writer] == false || options[:instance_accessor] == false
108
- class_eval(<<-EOS, __FILE__, __LINE__ + 1)
109
- def #{sym}=(obj)
110
- @@#{sym} = obj
111
- end
112
- EOS
113
- end
114
- send("#{sym}=", yield) if block_given?
115
- end
116
- end
117
-
118
- # Defines both class and instance accessors for class attributes.
119
- #
120
- # class Person
121
- # cattr_accessor :hair_colors
122
- # end
123
- #
124
- # Person.hair_colors = [:brown, :black, :blonde, :red]
125
- # Person.hair_colors # => [:brown, :black, :blonde, :red]
126
- # Person.new.hair_colors # => [:brown, :black, :blonde, :red]
127
- #
128
- # If a subclass changes the value then that would also change the value for
129
- # parent class. Similarly if parent class changes the value then that would
130
- # change the value of subclasses too.
131
- #
132
- # class Male < Person
133
- # end
134
- #
135
- # Male.hair_colors << :blue
136
- # Person.hair_colors # => [:brown, :black, :blonde, :red, :blue]
137
- #
138
- # To opt out of the instance writer method, pass <tt>instance_writer: false</tt>.
139
- # To opt out of the instance reader method, pass <tt>instance_reader: false</tt>.
140
- #
141
- # class Person
142
- # cattr_accessor :hair_colors, instance_writer: false, instance_reader: false
143
- # end
144
- #
145
- # Person.new.hair_colors = [:brown] # => NoMethodError
146
- # Person.new.hair_colors # => NoMethodError
147
- #
148
- # Or pass <tt>instance_accessor: false</tt>, to opt out both instance methods.
149
- #
150
- # class Person
151
- # cattr_accessor :hair_colors, instance_accessor: false
152
- # end
153
- #
154
- # Person.new.hair_colors = [:brown] # => NoMethodError
155
- # Person.new.hair_colors # => NoMethodError
156
- #
157
- # Also you can pass a block to set up the attribute with a default value.
158
- #
159
- # class Person
160
- # cattr_accessor :hair_colors do
161
- # [:brown, :black, :blonde, :red]
162
- # end
163
- # end
164
- #
165
- # Person.class_variable_get("@@hair_colors") #=> [:brown, :black, :blonde, :red]
166
- def cattr_accessor(*syms, &blk)
167
- cattr_reader(*syms)
168
- cattr_writer(*syms, &blk)
169
- end
170
- end
3
+ # cattr_* became mattr_* aliases in 7dfbd91b0780fbd6a1dd9bfbc176e10894871d2d,
4
+ # but we keep this around for libraries that directly require it knowing they
5
+ # want cattr_*. No need to deprecate.
6
+ require "active_support/core_ext/module/attribute_accessors"
@@ -1,42 +1,41 @@
1
- require 'active_support/core_ext/module/anonymous'
2
- require 'active_support/core_ext/module/reachable'
1
+ # frozen_string_literal: true
3
2
 
4
- class Class
5
- begin
6
- ObjectSpace.each_object(Class.new) {}
3
+ require "active_support/ruby_features"
7
4
 
8
- def descendants # :nodoc:
9
- descendants = []
10
- ObjectSpace.each_object(singleton_class) do |k|
11
- descendants.unshift k unless k == self
12
- end
13
- descendants
5
+ class Class
6
+ if ActiveSupport::RubyFeatures::CLASS_SUBCLASSES
7
+ # Returns an array with all classes that are < than its receiver.
8
+ #
9
+ # class C; end
10
+ # C.descendants # => []
11
+ #
12
+ # class B < C; end
13
+ # C.descendants # => [B]
14
+ #
15
+ # class A < B; end
16
+ # C.descendants # => [B, A]
17
+ #
18
+ # class D < C; end
19
+ # C.descendants # => [B, A, D]
20
+ def descendants
21
+ subclasses.concat(subclasses.flat_map(&:descendants))
14
22
  end
15
- rescue StandardError # JRuby
16
- def descendants # :nodoc:
17
- descendants = []
18
- ObjectSpace.each_object(Class) do |k|
19
- descendants.unshift k if k < self
23
+ else
24
+ def descendants
25
+ ObjectSpace.each_object(singleton_class).reject do |k|
26
+ k.singleton_class? || k == self
20
27
  end
21
- descendants.uniq!
22
- descendants
23
28
  end
24
29
  end
25
30
 
26
31
  # Returns an array with the direct children of +self+.
27
32
  #
28
- # Integer.subclasses # => [Fixnum, Bignum]
29
- #
30
33
  # class Foo; end
31
34
  # class Bar < Foo; end
32
35
  # class Baz < Bar; end
33
36
  #
34
37
  # Foo.subclasses # => [Bar]
35
38
  def subclasses
36
- subclasses, chain = [], descendants
37
- chain.each do |k|
38
- subclasses << k unless chain.any? { |c| c > k }
39
- end
40
- subclasses
41
- end
39
+ descendants.select { |descendant| descendant.superclass == self }
40
+ end unless ActiveSupport::RubyFeatures::CLASS_SUBCLASSES
42
41
  end
@@ -1,4 +1,4 @@
1
- require 'active_support/core_ext/class/attribute'
2
- require 'active_support/core_ext/class/attribute_accessors'
3
- require 'active_support/core_ext/class/delegating_attributes'
4
- 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?.
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "date"
4
+
5
+ class Date # :nodoc:
6
+ # No Date is blank:
7
+ #
8
+ # Date.today.blank? # => false
9
+ #
10
+ # @return [false]
11
+ def blank?
12
+ false
13
+ end
14
+ end
@@ -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
@@ -15,7 +17,7 @@ class Date
15
17
  # If <tt>Date.beginning_of_week</tt> has not been set for the current request, returns the week start specified in <tt>config.beginning_of_week</tt>.
16
18
  # If no config.beginning_of_week was specified, returns :monday.
17
19
  def beginning_of_week
18
- Thread.current[:beginning_of_week] || beginning_of_week_default || :monday
20
+ ::ActiveSupport::IsolatedExecutionState[:beginning_of_week] || beginning_of_week_default || :monday
19
21
  end
20
22
 
21
23
  # Sets <tt>Date.beginning_of_week</tt> to a week start (e.g. :monday) for current request/thread.
@@ -23,10 +25,10 @@ class Date
23
25
  # This method accepts any of the following day symbols:
24
26
  # :monday, :tuesday, :wednesday, :thursday, :friday, :saturday, :sunday
25
27
  def beginning_of_week=(week_start)
26
- Thread.current[:beginning_of_week] = find_beginning_of_week!(week_start)
28
+ ::ActiveSupport::IsolatedExecutionState[:beginning_of_week] = find_beginning_of_week!(week_start)
27
29
  end
28
30
 
29
- # Returns week start day symbol (e.g. :monday), or raises an ArgumentError for invalid day symbol.
31
+ # Returns week start day symbol (e.g. :monday), or raises an +ArgumentError+ for invalid day symbol.
30
32
  def find_beginning_of_week!(week_start)
31
33
  raise ArgumentError, "Invalid beginning of week: #{week_start}" unless ::Date::DAYS_INTO_WEEK.key?(week_start)
32
34
  week_start
@@ -69,13 +71,23 @@ class Date
69
71
  alias :at_midnight :beginning_of_day
70
72
  alias :at_beginning_of_day :beginning_of_day
71
73
 
74
+ # Converts Date to a Time (or DateTime if necessary) with the time portion set to the middle of the day (12:00)
75
+ def middle_of_day
76
+ in_time_zone.middle_of_day
77
+ end
78
+ alias :midday :middle_of_day
79
+ alias :noon :middle_of_day
80
+ alias :at_midday :middle_of_day
81
+ alias :at_noon :middle_of_day
82
+ alias :at_middle_of_day :middle_of_day
83
+
72
84
  # Converts Date to a Time (or DateTime if necessary) with the time portion set to the end of the day (23:59:59)
73
85
  def end_of_day
74
86
  in_time_zone.end_of_day
75
87
  end
76
88
  alias :at_end_of_day :end_of_day
77
89
 
78
- def plus_with_duration(other) #:nodoc:
90
+ def plus_with_duration(other) # :nodoc:
79
91
  if ActiveSupport::Duration === other
80
92
  other.since(self)
81
93
  else
@@ -85,7 +97,7 @@ class Date
85
97
  alias_method :plus_without_duration, :+
86
98
  alias_method :+, :plus_with_duration
87
99
 
88
- def minus_with_duration(other) #:nodoc:
100
+ def minus_with_duration(other) # :nodoc:
89
101
  if ActiveSupport::Duration === other
90
102
  plus_with_duration(-other)
91
103
  else
@@ -98,12 +110,13 @@ class Date
98
110
  # Provides precise Date calculations for years, months, and days. The +options+ parameter takes a hash with
99
111
  # any of these keys: <tt>:years</tt>, <tt>:months</tt>, <tt>:weeks</tt>, <tt>:days</tt>.
100
112
  def advance(options)
101
- options = options.dup
102
113
  d = self
103
- d = d >> options.delete(:years) * 12 if options[:years]
104
- d = d >> options.delete(:months) if options[:months]
105
- d = d + options.delete(:weeks) * 7 if options[:weeks]
106
- 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
+
107
120
  d
108
121
  end
109
122
 
@@ -119,11 +132,11 @@ class Date
119
132
  options.fetch(:day, day)
120
133
  )
121
134
  end
122
-
135
+
123
136
  # Allow Date to be compared with Time by converting to DateTime and relying on the <=> from there.
124
137
  def compare_with_coercion(other)
125
138
  if other.is_a?(Time)
126
- self.to_datetime <=> other
139
+ to_datetime <=> other
127
140
  else
128
141
  compare_without_coercion(other)
129
142
  end
@@ -1,44 +1,42 @@
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 => '%e %b',
9
- :long => '%B %e, %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 => '%e %b %Y'
19
+ rfc822: "%d %b %Y",
20
+ iso8601: lambda { |date| date.iso8601 }
17
21
  }
18
22
 
19
- # Ruby 1.9 has Date#to_time which converts to localtime only.
20
- remove_method :to_time
21
-
22
- # Ruby 1.9 has Date#xmlschema which converts to a string without the time
23
- # component. This removal may generate an issue on FreeBSD, that's why we
24
- # need to use remove_possible_method here
25
- remove_possible_method :xmlschema
26
-
27
23
  # Convert to a formatted string. See DATE_FORMATS for predefined formats.
28
24
  #
29
- # This method is aliased to <tt>to_s</tt>.
25
+ # This method is aliased to <tt>to_formatted_s</tt>.
30
26
  #
31
27
  # date = Date.new(2007, 11, 10) # => Sat, 10 Nov 2007
32
28
  #
29
+ # date.to_fs(:db) # => "2007-11-10"
33
30
  # date.to_formatted_s(:db) # => "2007-11-10"
34
- # date.to_s(:db) # => "2007-11-10"
35
31
  #
36
- # date.to_formatted_s(:short) # => "10 Nov"
37
- # date.to_formatted_s(:long) # => "November 10, 2007"
38
- # date.to_formatted_s(:long_ordinal) # => "November 10th, 2007"
39
- # date.to_formatted_s(:rfc822) # => "10 Nov 2007"
32
+ # date.to_fs(:short) # => "10 Nov"
33
+ # date.to_fs(:number) # => "20071110"
34
+ # date.to_fs(:long) # => "November 10, 2007"
35
+ # date.to_fs(:long_ordinal) # => "November 10th, 2007"
36
+ # date.to_fs(:rfc822) # => "10 Nov 2007"
37
+ # date.to_fs(:iso8601) # => "2007-11-10"
40
38
  #
41
- # == Adding your own date formats to to_formatted_s
39
+ # == Adding your own date formats to to_fs
42
40
  # You can add your own formats to the Date::DATE_FORMATS hash.
43
41
  # Use the format name as the hash key and either a strftime string
44
42
  # or Proc instance that takes a date argument as the value.
@@ -46,7 +44,7 @@ class Date
46
44
  # # config/initializers/date_formats.rb
47
45
  # Date::DATE_FORMATS[:month_and_year] = '%B %Y'
48
46
  # Date::DATE_FORMATS[:short_ordinal] = ->(date) { date.strftime("%B #{date.day.ordinalize}") }
49
- def to_formatted_s(format = :default)
47
+ def to_fs(format = :default)
50
48
  if formatter = DATE_FORMATS[format]
51
49
  if formatter.respond_to?(:call)
52
50
  formatter.call(self).to_s
@@ -57,29 +55,42 @@ class Date
57
55
  to_default_s
58
56
  end
59
57
  end
58
+ alias_method :to_formatted_s, :to_fs
60
59
  alias_method :to_default_s, :to_s
61
- alias_method :to_s, :to_formatted_s
62
60
 
63
61
  # Overrides the default inspect method with a human readable one, e.g., "Mon, 21 Feb 2005"
64
62
  def readable_inspect
65
- strftime('%a, %d %b %Y')
63
+ strftime("%a, %d %b %Y")
66
64
  end
67
65
  alias_method :default_inspect, :inspect
68
66
  alias_method :inspect, :readable_inspect
69
67
 
68
+ silence_redefinition_of_method :to_time
69
+
70
70
  # Converts a Date instance to a Time, where the time is set to the beginning of the day.
71
71
  # The timezone can be either :local or :utc (default :local).
72
72
  #
73
73
  # date = Date.new(2007, 11, 10) # => Sat, 10 Nov 2007
74
74
  #
75
- # date.to_time # => Sat Nov 10 00:00:00 0800 2007
76
- # date.to_time(:local) # => Sat Nov 10 00:00:00 0800 2007
75
+ # date.to_time # => 2007-11-10 00:00:00 0800
76
+ # date.to_time(:local) # => 2007-11-10 00:00:00 0800
77
77
  #
78
- # date.to_time(:utc) # => Sat Nov 10 00:00:00 UTC 2007
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.
79
82
  def to_time(form = :local)
80
- ::Time.send(form, year, month, day)
83
+ raise ArgumentError, "Expected :local or :utc, got #{form.inspect}." unless [:local, :utc].include?(form)
84
+ ::Time.public_send(form, year, month, day)
81
85
  end
82
86
 
87
+ silence_redefinition_of_method :xmlschema
88
+
89
+ # Returns a string which represents the time in used time zone as DateTime
90
+ # defined by XML Schema:
91
+ #
92
+ # date = Date.new(2015, 05, 23) # => Sat, 23 May 2015
93
+ # date.xmlschema # => "2015-05-23T00:00:00+04:00"
83
94
  def xmlschema
84
95
  in_time_zone.xmlschema
85
96
  end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "date"
4
+
5
+ class Date
6
+ NOT_SET = Object.new # :nodoc:
7
+ def to_s(format = NOT_SET) # :nodoc:
8
+ if formatter = DATE_FORMATS[format]
9
+ ActiveSupport::Deprecation.warn(
10
+ "Date#to_s(#{format.inspect}) is deprecated. Please use Date#to_fs(#{format.inspect}) instead."
11
+ )
12
+ if formatter.respond_to?(:call)
13
+ formatter.call(self).to_s
14
+ else
15
+ strftime(formatter)
16
+ end
17
+ elsif format == NOT_SET
18
+ to_default_s
19
+ else
20
+ ActiveSupport::Deprecation.warn(
21
+ "Date#to_s(#{format.inspect}) is deprecated. Please use Date#to_fs(#{format.inspect}) instead."
22
+ )
23
+ to_default_s
24
+ end
25
+ end
26
+ end
@@ -1,37 +1,8 @@
1
- require 'date'
2
- require 'active_support/core_ext/time/zones'
1
+ # frozen_string_literal: true
3
2
 
4
- class Date
5
- # *DEPRECATED*: Use +Date#in_time_zone+ instead.
6
- #
7
- # Converts Date to a TimeWithZone in the current zone if <tt>Time.zone</tt> or
8
- # <tt>Time.zone_default</tt> is set, otherwise converts Date to a Time via
9
- # Date#to_time.
10
- def to_time_in_current_zone
11
- ActiveSupport::Deprecation.warn 'Date#to_time_in_current_zone is deprecated. Use Date#in_time_zone instead', caller
12
-
13
- if ::Time.zone
14
- ::Time.zone.local(year, month, day)
15
- else
16
- to_time
17
- end
18
- end
3
+ require "date"
4
+ require "active_support/core_ext/date_and_time/zones"
19
5
 
20
- # Converts Date to a TimeWithZone in the current zone if Time.zone or Time.zone_default
21
- # is set, otherwise converts Date to a Time via Date#to_time
22
- #
23
- # Time.zone = 'Hawaii' # => 'Hawaii'
24
- # Date.new(2000).in_time_zone # => Sat, 01 Jan 2000 00:00:00 HST -10:00
25
- #
26
- # You can also pass in a TimeZone instance or string that identifies a TimeZone as an argument,
27
- # and the conversion will be based on that zone instead of <tt>Time.zone</tt>.
28
- #
29
- # Date.new(2000).in_time_zone('Alaska') # => Sat, 01 Jan 2000 00:00:00 AKST -09:00
30
- def in_time_zone(zone = ::Time.zone)
31
- if zone
32
- ::Time.find_zone!(zone).local(year, month, day)
33
- else
34
- to_time
35
- end
36
- end
6
+ class Date
7
+ include DateAndTime::Zones
37
8
  end
@@ -1,5 +1,8 @@
1
- require 'active_support/core_ext/date/acts_like'
2
- require 'active_support/core_ext/date/calculations'
3
- require 'active_support/core_ext/date/conversions'
4
- require 'active_support/core_ext/date/zones'
1
+ # frozen_string_literal: true
5
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/deprecated_conversions" unless ENV["RAILS_DISABLE_DEPRECATED_TO_S_CONVERSION"]
8
+ require "active_support/core_ext/date/zones"