activesupport 4.2.11.1 → 6.1.7.3

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 (272) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +464 -391
  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 +50 -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 +61 -55
  12. data/lib/active_support/cache/mem_cache_store.rb +115 -100
  13. data/lib/active_support/cache/memory_store.rb +81 -58
  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 +90 -42
  17. data/lib/active_support/cache/strategy/local_cache_middleware.rb +10 -9
  18. data/lib/active_support/cache.rb +386 -225
  19. data/lib/active_support/callbacks.rb +661 -594
  20. data/lib/active_support/concern.rb +80 -7
  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 +16 -17
  24. data/lib/active_support/configuration_file.rb +51 -0
  25. data/lib/active_support/core_ext/array/access.rb +41 -1
  26. data/lib/active_support/core_ext/array/conversions.rb +24 -20
  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 +11 -18
  30. data/lib/active_support/core_ext/array/inquiry.rb +19 -0
  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 +5 -3
  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 +52 -48
  37. data/lib/active_support/core_ext/class/attribute_accessors.rb +3 -1
  38. data/lib/active_support/core_ext/class/subclasses.rb +18 -25
  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 +27 -24
  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 +167 -65
  47. data/lib/active_support/core_ext/date_and_time/compatibility.rb +19 -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 +8 -5
  56. data/lib/active_support/core_ext/digest.rb +3 -0
  57. data/lib/active_support/core_ext/enumerable.rb +186 -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/conversions.rb +62 -41
  61. data/lib/active_support/core_ext/hash/deep_merge.rb +9 -13
  62. data/lib/active_support/core_ext/hash/deep_transform_values.rb +46 -0
  63. data/lib/active_support/core_ext/hash/except.rb +13 -10
  64. data/lib/active_support/core_ext/hash/indifferent_access.rb +4 -3
  65. data/lib/active_support/core_ext/hash/keys.rb +20 -43
  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 +5 -1
  74. data/lib/active_support/core_ext/kernel/reporting.rb +4 -84
  75. data/lib/active_support/core_ext/kernel/singleton_class.rb +2 -0
  76. data/lib/active_support/core_ext/kernel.rb +5 -5
  77. data/lib/active_support/core_ext/load_error.rb +3 -22
  78. data/lib/active_support/core_ext/marshal.rb +10 -8
  79. data/lib/active_support/core_ext/module/aliasing.rb +6 -44
  80. data/lib/active_support/core_ext/module/anonymous.rb +12 -1
  81. data/lib/active_support/core_ext/module/attr_internal.rb +8 -9
  82. data/lib/active_support/core_ext/module/attribute_accessors.rb +63 -69
  83. data/lib/active_support/core_ext/module/attribute_accessors_per_thread.rb +148 -0
  84. data/lib/active_support/core_ext/module/concerning.rb +19 -14
  85. data/lib/active_support/core_ext/module/delegation.rb +164 -51
  86. data/lib/active_support/core_ext/module/deprecation.rb +4 -2
  87. data/lib/active_support/core_ext/module/introspection.rb +23 -22
  88. data/lib/active_support/core_ext/module/redefine_method.rb +40 -0
  89. data/lib/active_support/core_ext/module/remove_method.rb +8 -3
  90. data/lib/active_support/core_ext/module.rb +13 -11
  91. data/lib/active_support/core_ext/name_error.rb +51 -4
  92. data/lib/active_support/core_ext/numeric/bytes.rb +22 -0
  93. data/lib/active_support/core_ext/numeric/conversions.rb +133 -136
  94. data/lib/active_support/core_ext/numeric/time.rb +35 -23
  95. data/lib/active_support/core_ext/numeric.rb +5 -3
  96. data/lib/active_support/core_ext/object/acts_like.rb +12 -1
  97. data/lib/active_support/core_ext/object/blank.rb +27 -3
  98. data/lib/active_support/core_ext/object/conversions.rb +6 -4
  99. data/lib/active_support/core_ext/object/deep_dup.rb +13 -4
  100. data/lib/active_support/core_ext/object/duplicable.rb +13 -93
  101. data/lib/active_support/core_ext/object/inclusion.rb +5 -3
  102. data/lib/active_support/core_ext/object/instance_variables.rb +3 -1
  103. data/lib/active_support/core_ext/object/json.rb +63 -21
  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 +81 -23
  107. data/lib/active_support/core_ext/object/with_options.rb +16 -3
  108. data/lib/active_support/core_ext/object.rb +14 -13
  109. data/lib/active_support/core_ext/range/compare_range.rb +82 -0
  110. data/lib/active_support/core_ext/range/conversions.rb +37 -15
  111. data/lib/active_support/core_ext/range/each.rb +18 -17
  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 +45 -0
  117. data/lib/active_support/core_ext/string/access.rb +9 -18
  118. data/lib/active_support/core_ext/string/behavior.rb +3 -1
  119. data/lib/active_support/core_ext/string/conversions.rb +8 -4
  120. data/lib/active_support/core_ext/string/exclude.rb +2 -0
  121. data/lib/active_support/core_ext/string/filters.rb +48 -6
  122. data/lib/active_support/core_ext/string/indent.rb +6 -4
  123. data/lib/active_support/core_ext/string/inflections.rb +102 -26
  124. data/lib/active_support/core_ext/string/inquiry.rb +4 -1
  125. data/lib/active_support/core_ext/string/multibyte.rb +18 -9
  126. data/lib/active_support/core_ext/string/output_safety.rb +125 -40
  127. data/lib/active_support/core_ext/string/starts_ends_with.rb +4 -2
  128. data/lib/active_support/core_ext/string/strip.rb +6 -5
  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 +137 -53
  135. data/lib/active_support/core_ext/time/compatibility.rb +4 -2
  136. data/lib/active_support/core_ext/time/conversions.rb +22 -13
  137. data/lib/active_support/core_ext/time/zones.rb +41 -7
  138. data/lib/active_support/core_ext/time.rb +7 -6
  139. data/lib/active_support/core_ext/uri.rb +11 -8
  140. data/lib/active_support/core_ext.rb +3 -1
  141. data/lib/active_support/current_attributes/test_helper.rb +13 -0
  142. data/lib/active_support/current_attributes.rb +210 -0
  143. data/lib/active_support/dependencies/autoload.rb +2 -0
  144. data/lib/active_support/dependencies/interlock.rb +57 -0
  145. data/lib/active_support/dependencies/zeitwerk_integration.rb +120 -0
  146. data/lib/active_support/dependencies.rb +241 -175
  147. data/lib/active_support/deprecation/behaviors.rb +58 -12
  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 +62 -21
  152. data/lib/active_support/deprecation/proxy_wrappers.rb +81 -30
  153. data/lib/active_support/deprecation/reporting.rb +81 -18
  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 +22 -0
  157. data/lib/active_support/duration/iso8601_parser.rb +123 -0
  158. data/lib/active_support/duration/iso8601_serializer.rb +59 -0
  159. data/lib/active_support/duration.rb +364 -39
  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 +170 -0
  164. data/lib/active_support/execution_wrapper.rb +132 -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/fork_tracker.rb +64 -0
  168. data/lib/active_support/gem_version.rb +7 -5
  169. data/lib/active_support/gzip.rb +7 -5
  170. data/lib/active_support/hash_with_indifferent_access.rb +171 -48
  171. data/lib/active_support/i18n.rb +9 -6
  172. data/lib/active_support/i18n_railtie.rb +47 -16
  173. data/lib/active_support/inflections.rb +13 -11
  174. data/lib/active_support/inflector/inflections.rb +58 -14
  175. data/lib/active_support/inflector/methods.rb +186 -169
  176. data/lib/active_support/inflector/transliterate.rb +83 -33
  177. data/lib/active_support/inflector.rb +7 -5
  178. data/lib/active_support/json/decoding.rb +32 -30
  179. data/lib/active_support/json/encoding.rb +22 -61
  180. data/lib/active_support/json.rb +4 -2
  181. data/lib/active_support/key_generator.rb +11 -43
  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 +9 -3
  185. data/lib/active_support/log_subscriber/test_helper.rb +14 -12
  186. data/lib/active_support/log_subscriber.rb +52 -19
  187. data/lib/active_support/logger.rb +10 -24
  188. data/lib/active_support/logger_silence.rb +14 -20
  189. data/lib/active_support/logger_thread_safe_level.rb +56 -10
  190. data/lib/active_support/message_encryptor.rb +167 -57
  191. data/lib/active_support/message_verifier.rb +151 -18
  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 +35 -80
  196. data/lib/active_support/multibyte/unicode.rb +22 -330
  197. data/lib/active_support/multibyte.rb +4 -2
  198. data/lib/active_support/notifications/fanout.rb +125 -23
  199. data/lib/active_support/notifications/instrumenter.rb +98 -16
  200. data/lib/active_support/notifications.rb +82 -14
  201. data/lib/active_support/number_helper/number_converter.rb +17 -16
  202. data/lib/active_support/number_helper/number_to_currency_converter.rb +9 -14
  203. data/lib/active_support/number_helper/number_to_delimited_converter.rb +11 -4
  204. data/lib/active_support/number_helper/number_to_human_converter.rb +14 -11
  205. data/lib/active_support/number_helper/number_to_human_size_converter.rb +12 -10
  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 +15 -5
  208. data/lib/active_support/number_helper/number_to_rounded_converter.rb +29 -57
  209. data/lib/active_support/number_helper/rounding_helper.rb +50 -0
  210. data/lib/active_support/number_helper.rb +123 -71
  211. data/lib/active_support/option_merger.rb +25 -4
  212. data/lib/active_support/ordered_hash.rb +7 -5
  213. data/lib/active_support/ordered_options.rb +35 -7
  214. data/lib/active_support/parameter_filter.rb +133 -0
  215. data/lib/active_support/per_thread_registry.rb +10 -4
  216. data/lib/active_support/proxy_object.rb +2 -0
  217. data/lib/active_support/rails.rb +10 -11
  218. data/lib/active_support/railtie.rb +66 -10
  219. data/lib/active_support/reloader.rb +130 -0
  220. data/lib/active_support/rescuable.rb +112 -57
  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 +13 -4
  224. data/lib/active_support/subscriber.rb +80 -31
  225. data/lib/active_support/tagged_logging.rb +54 -17
  226. data/lib/active_support/test_case.rb +107 -44
  227. data/lib/active_support/testing/assertions.rb +158 -20
  228. data/lib/active_support/testing/autorun.rb +4 -2
  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 +13 -10
  232. data/lib/active_support/testing/file_fixtures.rb +38 -0
  233. data/lib/active_support/testing/isolation.rb +35 -26
  234. data/lib/active_support/testing/method_call_assertions.rb +70 -0
  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 +43 -0
  240. data/lib/active_support/testing/tagged_logging.rb +3 -1
  241. data/lib/active_support/testing/time_helpers.rb +121 -20
  242. data/lib/active_support/time.rb +14 -12
  243. data/lib/active_support/time_with_zone.rb +215 -51
  244. data/lib/active_support/values/time_zone.rb +223 -71
  245. data/lib/active_support/version.rb +3 -1
  246. data/lib/active_support/xml_mini/jdom.rb +116 -115
  247. data/lib/active_support/xml_mini/libxml.rb +16 -13
  248. data/lib/active_support/xml_mini/libxmlsax.rb +15 -14
  249. data/lib/active_support/xml_mini/nokogiri.rb +14 -12
  250. data/lib/active_support/xml_mini/nokogirisax.rb +14 -13
  251. data/lib/active_support/xml_mini/rexml.rb +18 -9
  252. data/lib/active_support/xml_mini.rb +38 -46
  253. data/lib/active_support.rb +25 -11
  254. metadata +100 -43
  255. data/lib/active_support/concurrency/latch.rb +0 -27
  256. data/lib/active_support/core_ext/array/prepend_and_append.rb +0 -7
  257. data/lib/active_support/core_ext/big_decimal/yaml_conversions.rb +0 -16
  258. data/lib/active_support/core_ext/class/delegating_attributes.rb +0 -45
  259. data/lib/active_support/core_ext/date_time/zones.rb +0 -6
  260. data/lib/active_support/core_ext/hash/compact.rb +0 -24
  261. data/lib/active_support/core_ext/hash/transform_values.rb +0 -23
  262. data/lib/active_support/core_ext/kernel/agnostics.rb +0 -11
  263. data/lib/active_support/core_ext/kernel/debugger.rb +0 -10
  264. data/lib/active_support/core_ext/module/method_transplanting.rb +0 -13
  265. data/lib/active_support/core_ext/module/qualified_const.rb +0 -52
  266. data/lib/active_support/core_ext/module/reachable.rb +0 -8
  267. data/lib/active_support/core_ext/object/itself.rb +0 -15
  268. data/lib/active_support/core_ext/range/include_range.rb +0 -23
  269. data/lib/active_support/core_ext/struct.rb +0 -6
  270. data/lib/active_support/core_ext/thread.rb +0 -86
  271. data/lib/active_support/core_ext/time/marshal.rb +0 -30
  272. data/lib/active_support/values/unicode_tables.dat +0 -0
@@ -1,45 +0,0 @@
1
- require 'active_support/core_ext/kernel/singleton_class'
2
- require 'active_support/core_ext/module/remove_method'
3
- require 'active_support/core_ext/module/deprecation'
4
-
5
-
6
- class Class
7
- def superclass_delegating_accessor(name, options = {})
8
- # Create private _name and _name= methods that can still be used if the public
9
- # methods are overridden.
10
- _superclass_delegating_accessor("_#{name}", options)
11
-
12
- # Generate the public methods name, name=, and name?.
13
- # These methods dispatch to the private _name, and _name= methods, making them
14
- # overridable.
15
- singleton_class.send(:define_method, name) { send("_#{name}") }
16
- singleton_class.send(:define_method, "#{name}?") { !!send("_#{name}") }
17
- singleton_class.send(:define_method, "#{name}=") { |value| send("_#{name}=", value) }
18
-
19
- # If an instance_reader is needed, generate public instance methods name and name?.
20
- if options[:instance_reader] != false
21
- define_method(name) { send("_#{name}") }
22
- define_method("#{name}?") { !!send("#{name}") }
23
- end
24
- end
25
-
26
- deprecate superclass_delegating_accessor: :class_attribute
27
-
28
- private
29
- # Take the object being set and store it in a method. This gives us automatic
30
- # inheritance behavior, without having to store the object in an instance
31
- # variable and look up the superclass chain manually.
32
- def _stash_object_in_method(object, method, instance_reader = true)
33
- singleton_class.remove_possible_method(method)
34
- singleton_class.send(:define_method, method) { object }
35
- remove_possible_method(method)
36
- define_method(method) { object } if instance_reader
37
- end
38
-
39
- def _superclass_delegating_accessor(name, options = {})
40
- singleton_class.send(:define_method, "#{name}=") do |value|
41
- _stash_object_in_method(value, name, options[:instance_reader] != false)
42
- end
43
- send("#{name}=", nil)
44
- end
45
- end
@@ -1,6 +0,0 @@
1
- require 'date'
2
- require 'active_support/core_ext/date_and_time/zones'
3
-
4
- class DateTime
5
- include DateAndTime::Zones
6
- end
@@ -1,24 +0,0 @@
1
- class Hash
2
- unless Hash.instance_methods(false).include?(:compact)
3
- # Returns a hash with non +nil+ values.
4
- #
5
- # hash = { a: true, b: false, c: nil}
6
- # hash.compact # => { a: true, b: false}
7
- # hash # => { a: true, b: false, c: nil}
8
- # { c: nil }.compact # => {}
9
- def compact
10
- self.select { |_, value| !value.nil? }
11
- end
12
- end
13
-
14
- unless Hash.instance_methods(false).include?(:compact!)
15
- # Replaces current hash with non +nil+ values.
16
- #
17
- # hash = { a: true, b: false, c: nil}
18
- # hash.compact! # => { a: true, b: false}
19
- # hash # => { a: true, b: false}
20
- def compact!
21
- self.reject! { |_, value| value.nil? }
22
- end
23
- end
24
- end
@@ -1,23 +0,0 @@
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
15
-
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
@@ -1,11 +0,0 @@
1
- class Object
2
- # Makes backticks behave (somewhat more) similarly on all platforms.
3
- # On win32 `nonexistent_command` raises Errno::ENOENT; on Unix, the
4
- # spawned shell prints a message to stderr and sets $?. We emulate
5
- # Unix on the former but not the latter.
6
- def `(command) #:nodoc:
7
- super
8
- rescue Errno::ENOENT => e
9
- STDERR.puts "#$0: #{e}"
10
- end
11
- end
@@ -1,10 +0,0 @@
1
- module Kernel
2
- unless respond_to?(:debugger)
3
- # Starts a debugging session if the +debugger+ gem has been loaded (call rails server --debugger to do load it).
4
- def debugger
5
- message = "\n***** Debugger requested, but was not available (ensure the debugger gem is listed in Gemfile/installed as gem): Start server with --debugger to enable *****\n"
6
- defined?(Rails.logger) ? Rails.logger.info(message) : $stderr.puts(message)
7
- end
8
- alias breakpoint debugger unless respond_to?(:breakpoint)
9
- end
10
- end
@@ -1,13 +0,0 @@
1
- class Module
2
- ###
3
- # TODO: remove this after 1.9 support is dropped
4
- def methods_transplantable? # :nodoc:
5
- x = Module.new {
6
- def foo; end # :nodoc:
7
- }
8
- Module.new { define_method :bar, x.instance_method(:foo) }
9
- true
10
- rescue TypeError
11
- false
12
- end
13
- end
@@ -1,52 +0,0 @@
1
- require 'active_support/core_ext/string/inflections'
2
-
3
- #--
4
- # Allows code reuse in the methods below without polluting Module.
5
- #++
6
- module QualifiedConstUtils
7
- def self.raise_if_absolute(path)
8
- raise NameError.new("wrong constant name #$&") if path =~ /\A::[^:]+/
9
- end
10
-
11
- def self.names(path)
12
- path.split('::')
13
- end
14
- end
15
-
16
- ##
17
- # Extends the API for constants to be able to deal with qualified names. Arguments
18
- # are assumed to be relative to the receiver.
19
- #
20
- #--
21
- # Qualified names are required to be relative because we are extending existing
22
- # methods that expect constant names, ie, relative paths of length 1. For example,
23
- # Object.const_get('::String') raises NameError and so does qualified_const_get.
24
- #++
25
- class Module
26
- def qualified_const_defined?(path, search_parents=true)
27
- QualifiedConstUtils.raise_if_absolute(path)
28
-
29
- QualifiedConstUtils.names(path).inject(self) do |mod, name|
30
- return unless mod.const_defined?(name, search_parents)
31
- mod.const_get(name)
32
- end
33
- return true
34
- end
35
-
36
- def qualified_const_get(path)
37
- QualifiedConstUtils.raise_if_absolute(path)
38
-
39
- QualifiedConstUtils.names(path).inject(self) do |mod, name|
40
- mod.const_get(name)
41
- end
42
- end
43
-
44
- def qualified_const_set(path, value)
45
- QualifiedConstUtils.raise_if_absolute(path)
46
-
47
- const_name = path.demodulize
48
- mod_name = path.deconstantize
49
- mod = mod_name.empty? ? self : qualified_const_get(mod_name)
50
- mod.const_set(const_name, value)
51
- end
52
- end
@@ -1,8 +0,0 @@
1
- require 'active_support/core_ext/module/anonymous'
2
- require 'active_support/core_ext/string/inflections'
3
-
4
- class Module
5
- def reachable? #:nodoc:
6
- !anonymous? && name.safe_constantize.equal?(self)
7
- end
8
- end
@@ -1,15 +0,0 @@
1
- class Object
2
- # TODO: Remove this file when we drop support for Ruby < 2.2
3
- unless respond_to?(:itself)
4
- # Returns the object itself.
5
- #
6
- # Useful for chaining methods, such as Active Record scopes:
7
- #
8
- # Event.public_send(state.presence_in([ :trashed, :drafted ]) || :itself).order(:created_at)
9
- #
10
- # @return Object
11
- def itself
12
- self
13
- end
14
- end
15
- end
@@ -1,23 +0,0 @@
1
- require 'active_support/core_ext/module/aliasing'
2
-
3
- class Range
4
- # Extends the default Range#include? to support range comparisons.
5
- # (1..5).include?(1..5) # => true
6
- # (1..5).include?(2..3) # => true
7
- # (1..5).include?(2..6) # => false
8
- #
9
- # The native Range#include? behavior is untouched.
10
- # ('a'..'f').include?('c') # => true
11
- # (5..9).include?(11) # => false
12
- def include_with_range?(value)
13
- if value.is_a?(::Range)
14
- # 1...10 includes 1..9 but it does not include 1..10.
15
- operator = exclude_end? && !value.exclude_end? ? :< : :<=
16
- include_without_range?(value.first) && value.last.send(operator, last)
17
- else
18
- include_without_range?(value)
19
- end
20
- end
21
-
22
- alias_method_chain :include?, :range
23
- end
@@ -1,6 +0,0 @@
1
- # Backport of Struct#to_h from Ruby 2.0
2
- class Struct # :nodoc:
3
- def to_h
4
- Hash[members.zip(values)]
5
- end
6
- end unless Struct.instance_methods.include?(:to_h)
@@ -1,86 +0,0 @@
1
- class Thread
2
- LOCK = Mutex.new # :nodoc:
3
-
4
- # Returns the value of a thread local variable that has been set. Note that
5
- # these are different than fiber local values.
6
- #
7
- # Thread local values are carried along with threads, and do not respect
8
- # fibers. For example:
9
- #
10
- # Thread.new {
11
- # Thread.current.thread_variable_set("foo", "bar") # set a thread local
12
- # Thread.current["foo"] = "bar" # set a fiber local
13
- #
14
- # Fiber.new {
15
- # Fiber.yield [
16
- # Thread.current.thread_variable_get("foo"), # get the thread local
17
- # Thread.current["foo"], # get the fiber local
18
- # ]
19
- # }.resume
20
- # }.join.value # => ['bar', nil]
21
- #
22
- # The value <tt>"bar"</tt> is returned for the thread local, where +nil+ is returned
23
- # for the fiber local. The fiber is executed in the same thread, so the
24
- # thread local values are available.
25
- def thread_variable_get(key)
26
- _locals[key.to_sym]
27
- end
28
-
29
- # Sets a thread local with +key+ to +value+. Note that these are local to
30
- # threads, and not to fibers. Please see Thread#thread_variable_get for
31
- # more information.
32
- def thread_variable_set(key, value)
33
- _locals[key.to_sym] = value
34
- end
35
-
36
- # Returns an array of the names of the thread-local variables (as Symbols).
37
- #
38
- # thr = Thread.new do
39
- # Thread.current.thread_variable_set(:cat, 'meow')
40
- # Thread.current.thread_variable_set("dog", 'woof')
41
- # end
42
- # thr.join # => #<Thread:0x401b3f10 dead>
43
- # thr.thread_variables # => [:dog, :cat]
44
- #
45
- # Note that these are not fiber local variables. Please see Thread#thread_variable_get
46
- # for more details.
47
- def thread_variables
48
- _locals.keys
49
- end
50
-
51
- # Returns <tt>true</tt> if the given string (or symbol) exists as a
52
- # thread-local variable.
53
- #
54
- # me = Thread.current
55
- # me.thread_variable_set(:oliver, "a")
56
- # me.thread_variable?(:oliver) # => true
57
- # me.thread_variable?(:stanley) # => false
58
- #
59
- # Note that these are not fiber local variables. Please see Thread#thread_variable_get
60
- # for more details.
61
- def thread_variable?(key)
62
- _locals.has_key?(key.to_sym)
63
- end
64
-
65
- # Freezes the thread so that thread local variables cannot be set via
66
- # Thread#thread_variable_set, nor can fiber local variables be set.
67
- #
68
- # me = Thread.current
69
- # me.freeze
70
- # me.thread_variable_set(:oliver, "a") #=> RuntimeError: can't modify frozen thread locals
71
- # me[:oliver] = "a" #=> RuntimeError: can't modify frozen thread locals
72
- def freeze
73
- _locals.freeze
74
- super
75
- end
76
-
77
- private
78
-
79
- def _locals
80
- if defined?(@_locals)
81
- @_locals
82
- else
83
- LOCK.synchronize { @_locals ||= {} }
84
- end
85
- end
86
- end unless Thread.instance_methods.include?(:thread_variable_set)
@@ -1,30 +0,0 @@
1
- # Ruby 1.9.2 adds utc_offset and zone to Time, but marshaling only
2
- # preserves utc_offset. Preserve zone also, even though it may not
3
- # work in some edge cases.
4
- if Time.local(2010).zone != Marshal.load(Marshal.dump(Time.local(2010))).zone
5
- class Time
6
- class << self
7
- alias_method :_load_without_zone, :_load
8
- def _load(marshaled_time)
9
- time = _load_without_zone(marshaled_time)
10
- time.instance_eval do
11
- if zone = defined?(@_zone) && remove_instance_variable('@_zone')
12
- ary = to_a
13
- ary[0] += subsec if ary[0] == sec
14
- ary[-1] = zone
15
- utc? ? Time.utc(*ary) : Time.local(*ary)
16
- else
17
- self
18
- end
19
- end
20
- end
21
- end
22
-
23
- alias_method :_dump_without_zone, :_dump
24
- def _dump(*args)
25
- obj = dup
26
- obj.instance_variable_set('@_zone', zone)
27
- obj.send :_dump_without_zone, *args
28
- end
29
- end
30
- end