activesupport 5.1.7 → 5.2.0.beta1

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

Potentially problematic release.


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

Files changed (238) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +303 -617
  3. data/README.rdoc +1 -1
  4. data/lib/active_support.rb +3 -12
  5. data/lib/active_support/all.rb +2 -0
  6. data/lib/active_support/array_inquirer.rb +2 -0
  7. data/lib/active_support/backtrace_cleaner.rb +2 -0
  8. data/lib/active_support/benchmarkable.rb +2 -0
  9. data/lib/active_support/builder.rb +2 -0
  10. data/lib/active_support/cache.rb +127 -58
  11. data/lib/active_support/cache/file_store.rb +4 -3
  12. data/lib/active_support/cache/mem_cache_store.rb +12 -4
  13. data/lib/active_support/cache/memory_store.rb +2 -0
  14. data/lib/active_support/cache/null_store.rb +2 -0
  15. data/lib/active_support/cache/redis_cache_store.rb +404 -0
  16. data/lib/active_support/cache/strategy/local_cache.rb +9 -2
  17. data/lib/active_support/cache/strategy/local_cache_middleware.rb +2 -0
  18. data/lib/active_support/callbacks.rb +26 -37
  19. data/lib/active_support/concern.rb +3 -1
  20. data/lib/active_support/concurrency/share_lock.rb +2 -0
  21. data/lib/active_support/configurable.rb +2 -0
  22. data/lib/active_support/core_ext.rb +3 -1
  23. data/lib/active_support/core_ext/array.rb +2 -0
  24. data/lib/active_support/core_ext/array/access.rb +4 -2
  25. data/lib/active_support/core_ext/array/conversions.rb +2 -0
  26. data/lib/active_support/core_ext/array/extract_options.rb +2 -0
  27. data/lib/active_support/core_ext/array/grouping.rb +2 -0
  28. data/lib/active_support/core_ext/array/inquiry.rb +2 -0
  29. data/lib/active_support/core_ext/array/prepend_and_append.rb +4 -2
  30. data/lib/active_support/core_ext/array/wrap.rb +2 -0
  31. data/lib/active_support/core_ext/benchmark.rb +2 -0
  32. data/lib/active_support/core_ext/big_decimal.rb +2 -0
  33. data/lib/active_support/core_ext/big_decimal/conversions.rb +2 -0
  34. data/lib/active_support/core_ext/class.rb +2 -0
  35. data/lib/active_support/core_ext/class/attribute.rb +34 -16
  36. data/lib/active_support/core_ext/class/attribute_accessors.rb +2 -0
  37. data/lib/active_support/core_ext/class/subclasses.rb +1 -2
  38. data/lib/active_support/core_ext/date.rb +2 -0
  39. data/lib/active_support/core_ext/date/acts_like.rb +2 -0
  40. data/lib/active_support/core_ext/date/blank.rb +2 -0
  41. data/lib/active_support/core_ext/date/calculations.rb +2 -0
  42. data/lib/active_support/core_ext/date/conversions.rb +10 -9
  43. data/lib/active_support/core_ext/date/zones.rb +2 -0
  44. data/lib/active_support/core_ext/date_and_time/calculations.rb +42 -16
  45. data/lib/active_support/core_ext/date_and_time/compatibility.rb +3 -1
  46. data/lib/active_support/core_ext/date_and_time/zones.rb +2 -0
  47. data/lib/active_support/core_ext/date_time.rb +2 -0
  48. data/lib/active_support/core_ext/date_time/acts_like.rb +2 -0
  49. data/lib/active_support/core_ext/date_time/blank.rb +2 -0
  50. data/lib/active_support/core_ext/date_time/calculations.rb +2 -0
  51. data/lib/active_support/core_ext/date_time/compatibility.rb +6 -4
  52. data/lib/active_support/core_ext/date_time/conversions.rb +2 -0
  53. data/lib/active_support/core_ext/digest/uuid.rb +3 -1
  54. data/lib/active_support/core_ext/enumerable.rb +3 -1
  55. data/lib/active_support/core_ext/file.rb +2 -0
  56. data/lib/active_support/core_ext/file/atomic.rb +2 -0
  57. data/lib/active_support/core_ext/hash.rb +2 -0
  58. data/lib/active_support/core_ext/hash/compact.rb +2 -0
  59. data/lib/active_support/core_ext/hash/conversions.rb +2 -0
  60. data/lib/active_support/core_ext/hash/deep_merge.rb +8 -12
  61. data/lib/active_support/core_ext/hash/except.rb +2 -0
  62. data/lib/active_support/core_ext/hash/indifferent_access.rb +2 -0
  63. data/lib/active_support/core_ext/hash/keys.rb +2 -0
  64. data/lib/active_support/core_ext/hash/reverse_merge.rb +5 -2
  65. data/lib/active_support/core_ext/hash/slice.rb +4 -4
  66. data/lib/active_support/core_ext/hash/transform_values.rb +2 -0
  67. data/lib/active_support/core_ext/integer.rb +2 -0
  68. data/lib/active_support/core_ext/integer/inflections.rb +2 -0
  69. data/lib/active_support/core_ext/integer/multiple.rb +2 -0
  70. data/lib/active_support/core_ext/integer/time.rb +7 -14
  71. data/lib/active_support/core_ext/kernel.rb +2 -0
  72. data/lib/active_support/core_ext/kernel/agnostics.rb +2 -0
  73. data/lib/active_support/core_ext/kernel/concern.rb +2 -0
  74. data/lib/active_support/core_ext/kernel/reporting.rb +2 -0
  75. data/lib/active_support/core_ext/kernel/singleton_class.rb +2 -0
  76. data/lib/active_support/core_ext/load_error.rb +2 -7
  77. data/lib/active_support/core_ext/marshal.rb +2 -0
  78. data/lib/active_support/core_ext/module.rb +3 -0
  79. data/lib/active_support/core_ext/module/aliasing.rb +2 -0
  80. data/lib/active_support/core_ext/module/anonymous.rb +2 -0
  81. data/lib/active_support/core_ext/module/attr_internal.rb +2 -0
  82. data/lib/active_support/core_ext/module/attribute_accessors.rb +21 -24
  83. data/lib/active_support/core_ext/module/attribute_accessors_per_thread.rb +2 -0
  84. data/lib/active_support/core_ext/module/concerning.rb +2 -0
  85. data/lib/active_support/core_ext/module/delegation.rb +29 -24
  86. data/lib/active_support/core_ext/module/deprecation.rb +2 -0
  87. data/lib/active_support/core_ext/module/introspection.rb +2 -0
  88. data/lib/active_support/core_ext/module/reachable.rb +3 -0
  89. data/lib/active_support/core_ext/module/redefine_method.rb +49 -0
  90. data/lib/active_support/core_ext/module/remove_method.rb +5 -23
  91. data/lib/active_support/core_ext/name_error.rb +2 -0
  92. data/lib/active_support/core_ext/numeric.rb +2 -0
  93. data/lib/active_support/core_ext/numeric/bytes.rb +2 -0
  94. data/lib/active_support/core_ext/numeric/conversions.rb +9 -7
  95. data/lib/active_support/core_ext/numeric/inquiry.rb +2 -0
  96. data/lib/active_support/core_ext/numeric/time.rb +7 -15
  97. data/lib/active_support/core_ext/object.rb +2 -0
  98. data/lib/active_support/core_ext/object/acts_like.rb +12 -1
  99. data/lib/active_support/core_ext/object/blank.rb +2 -0
  100. data/lib/active_support/core_ext/object/conversions.rb +2 -0
  101. data/lib/active_support/core_ext/object/deep_dup.rb +2 -0
  102. data/lib/active_support/core_ext/object/duplicable.rb +10 -8
  103. data/lib/active_support/core_ext/object/inclusion.rb +2 -0
  104. data/lib/active_support/core_ext/object/instance_variables.rb +2 -0
  105. data/lib/active_support/core_ext/object/json.rb +8 -0
  106. data/lib/active_support/core_ext/object/to_param.rb +2 -0
  107. data/lib/active_support/core_ext/object/to_query.rb +4 -5
  108. data/lib/active_support/core_ext/object/try.rb +2 -0
  109. data/lib/active_support/core_ext/object/with_options.rb +3 -1
  110. data/lib/active_support/core_ext/range.rb +3 -0
  111. data/lib/active_support/core_ext/range/conversions.rb +9 -1
  112. data/lib/active_support/core_ext/range/each.rb +5 -1
  113. data/lib/active_support/core_ext/range/include_range.rb +2 -0
  114. data/lib/active_support/core_ext/range/include_time_with_zone.rb +23 -0
  115. data/lib/active_support/core_ext/range/overlaps.rb +2 -0
  116. data/lib/active_support/core_ext/regexp.rb +2 -0
  117. data/lib/active_support/core_ext/securerandom.rb +2 -0
  118. data/lib/active_support/core_ext/string.rb +2 -0
  119. data/lib/active_support/core_ext/string/access.rb +2 -0
  120. data/lib/active_support/core_ext/string/behavior.rb +2 -0
  121. data/lib/active_support/core_ext/string/conversions.rb +2 -0
  122. data/lib/active_support/core_ext/string/exclude.rb +2 -0
  123. data/lib/active_support/core_ext/string/filters.rb +2 -0
  124. data/lib/active_support/core_ext/string/indent.rb +2 -0
  125. data/lib/active_support/core_ext/string/inflections.rb +26 -12
  126. data/lib/active_support/core_ext/string/inquiry.rb +2 -0
  127. data/lib/active_support/core_ext/string/multibyte.rb +2 -0
  128. data/lib/active_support/core_ext/string/output_safety.rb +6 -7
  129. data/lib/active_support/core_ext/string/starts_ends_with.rb +2 -0
  130. data/lib/active_support/core_ext/string/strip.rb +2 -0
  131. data/lib/active_support/core_ext/string/zones.rb +2 -0
  132. data/lib/active_support/core_ext/time.rb +2 -0
  133. data/lib/active_support/core_ext/time/acts_like.rb +2 -0
  134. data/lib/active_support/core_ext/time/calculations.rb +23 -15
  135. data/lib/active_support/core_ext/time/compatibility.rb +4 -2
  136. data/lib/active_support/core_ext/time/conversions.rb +2 -0
  137. data/lib/active_support/core_ext/time/zones.rb +6 -4
  138. data/lib/active_support/core_ext/uri.rb +4 -1
  139. data/lib/active_support/current_attributes.rb +195 -0
  140. data/lib/active_support/dependencies.rb +15 -25
  141. data/lib/active_support/dependencies/autoload.rb +2 -0
  142. data/lib/active_support/dependencies/interlock.rb +2 -0
  143. data/lib/active_support/deprecation.rb +4 -2
  144. data/lib/active_support/deprecation/behaviors.rb +23 -8
  145. data/lib/active_support/deprecation/constant_accessor.rb +3 -1
  146. data/lib/active_support/deprecation/instance_delegator.rb +2 -0
  147. data/lib/active_support/deprecation/method_wrappers.rb +2 -7
  148. data/lib/active_support/deprecation/proxy_wrappers.rb +4 -1
  149. data/lib/active_support/deprecation/reporting.rb +4 -2
  150. data/lib/active_support/descendants_tracker.rb +2 -0
  151. data/lib/active_support/duration.rb +8 -14
  152. data/lib/active_support/duration/iso8601_parser.rb +4 -2
  153. data/lib/active_support/duration/iso8601_serializer.rb +4 -2
  154. data/lib/active_support/encrypted_configuration.rb +48 -0
  155. data/lib/active_support/encrypted_file.rb +99 -0
  156. data/lib/active_support/evented_file_update_checker.rb +2 -0
  157. data/lib/active_support/execution_wrapper.rb +2 -0
  158. data/lib/active_support/executor.rb +2 -0
  159. data/lib/active_support/file_update_checker.rb +2 -0
  160. data/lib/active_support/gem_version.rb +5 -3
  161. data/lib/active_support/gzip.rb +2 -0
  162. data/lib/active_support/hash_with_indifferent_access.rb +33 -1
  163. data/lib/active_support/i18n.rb +3 -1
  164. data/lib/active_support/i18n_railtie.rb +5 -11
  165. data/lib/active_support/inflections.rb +2 -0
  166. data/lib/active_support/inflector.rb +2 -0
  167. data/lib/active_support/inflector/inflections.rb +19 -3
  168. data/lib/active_support/inflector/methods.rb +40 -23
  169. data/lib/active_support/inflector/transliterate.rb +17 -8
  170. data/lib/active_support/json.rb +2 -0
  171. data/lib/active_support/json/decoding.rb +2 -0
  172. data/lib/active_support/json/encoding.rb +2 -0
  173. data/lib/active_support/key_generator.rb +3 -1
  174. data/lib/active_support/lazy_load_hooks.rb +2 -0
  175. data/lib/active_support/log_subscriber.rb +3 -2
  176. data/lib/active_support/log_subscriber/test_helper.rb +2 -0
  177. data/lib/active_support/logger.rb +2 -0
  178. data/lib/active_support/logger_silence.rb +3 -2
  179. data/lib/active_support/logger_thread_safe_level.rb +2 -0
  180. data/lib/active_support/message_encryptor.rb +94 -22
  181. data/lib/active_support/message_verifier.rb +78 -7
  182. data/lib/active_support/messages/metadata.rb +71 -0
  183. data/lib/active_support/messages/rotation_configuration.rb +22 -0
  184. data/lib/active_support/messages/rotator.rb +56 -0
  185. data/lib/active_support/multibyte.rb +2 -0
  186. data/lib/active_support/multibyte/chars.rb +2 -0
  187. data/lib/active_support/multibyte/unicode.rb +3 -1
  188. data/lib/active_support/notifications.rb +2 -0
  189. data/lib/active_support/notifications/fanout.rb +2 -0
  190. data/lib/active_support/notifications/instrumenter.rb +2 -0
  191. data/lib/active_support/number_helper.rb +2 -0
  192. data/lib/active_support/number_helper/number_converter.rb +2 -0
  193. data/lib/active_support/number_helper/number_to_currency_converter.rb +2 -0
  194. data/lib/active_support/number_helper/number_to_delimited_converter.rb +2 -0
  195. data/lib/active_support/number_helper/number_to_human_converter.rb +2 -0
  196. data/lib/active_support/number_helper/number_to_human_size_converter.rb +2 -0
  197. data/lib/active_support/number_helper/number_to_percentage_converter.rb +2 -0
  198. data/lib/active_support/number_helper/number_to_phone_converter.rb +3 -1
  199. data/lib/active_support/number_helper/number_to_rounded_converter.rb +2 -20
  200. data/lib/active_support/number_helper/rounding_helper.rb +5 -3
  201. data/lib/active_support/option_merger.rb +2 -0
  202. data/lib/active_support/ordered_hash.rb +2 -0
  203. data/lib/active_support/ordered_options.rb +4 -2
  204. data/lib/active_support/per_thread_registry.rb +2 -0
  205. data/lib/active_support/proxy_object.rb +2 -0
  206. data/lib/active_support/rails.rb +2 -0
  207. data/lib/active_support/railtie.rb +27 -8
  208. data/lib/active_support/reloader.rb +7 -5
  209. data/lib/active_support/rescuable.rb +3 -2
  210. data/lib/active_support/security_utils.rb +15 -11
  211. data/lib/active_support/string_inquirer.rb +2 -0
  212. data/lib/active_support/subscriber.rb +2 -0
  213. data/lib/active_support/tagged_logging.rb +2 -0
  214. data/lib/active_support/test_case.rb +2 -1
  215. data/lib/active_support/testing/assertions.rb +6 -4
  216. data/lib/active_support/testing/autorun.rb +2 -0
  217. data/lib/active_support/testing/constant_lookup.rb +2 -0
  218. data/lib/active_support/testing/declarative.rb +2 -0
  219. data/lib/active_support/testing/deprecation.rb +2 -0
  220. data/lib/active_support/testing/file_fixtures.rb +2 -0
  221. data/lib/active_support/testing/isolation.rb +5 -5
  222. data/lib/active_support/testing/method_call_assertions.rb +2 -0
  223. data/lib/active_support/testing/setup_and_teardown.rb +2 -0
  224. data/lib/active_support/testing/stream.rb +2 -0
  225. data/lib/active_support/testing/tagged_logging.rb +2 -0
  226. data/lib/active_support/testing/time_helpers.rb +31 -2
  227. data/lib/active_support/time.rb +2 -0
  228. data/lib/active_support/time_with_zone.rb +38 -0
  229. data/lib/active_support/values/time_zone.rb +20 -12
  230. data/lib/active_support/version.rb +2 -0
  231. data/lib/active_support/xml_mini.rb +2 -0
  232. data/lib/active_support/xml_mini/jdom.rb +4 -2
  233. data/lib/active_support/xml_mini/libxml.rb +3 -1
  234. data/lib/active_support/xml_mini/libxmlsax.rb +4 -2
  235. data/lib/active_support/xml_mini/nokogiri.rb +3 -1
  236. data/lib/active_support/xml_mini/nokogirisax.rb +3 -1
  237. data/lib/active_support/xml_mini/rexml.rb +3 -1
  238. metadata +19 -15
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "active_support/inflector/methods"
2
4
 
3
5
  module ActiveSupport
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "active_support/concurrency/share_lock"
2
4
 
3
5
  module ActiveSupport #:nodoc:
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "singleton"
2
4
 
3
5
  module ActiveSupport
@@ -30,10 +32,10 @@ module ActiveSupport
30
32
  attr_accessor :deprecation_horizon
31
33
 
32
34
  # It accepts two parameters on initialization. The first is a version of library
33
- # and the second is a library name
35
+ # and the second is a library name.
34
36
  #
35
37
  # ActiveSupport::Deprecation.new('2.0', 'MyLibrary')
36
- def initialize(deprecation_horizon = "5.2", gem_name = "Rails")
38
+ def initialize(deprecation_horizon = "6.0", gem_name = "Rails")
37
39
  self.gem_name = gem_name
38
40
  self.deprecation_horizon = deprecation_horizon
39
41
  # By default, warnings are not silenced and debugging is off.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "active_support/notifications"
2
4
 
3
5
  module ActiveSupport
@@ -9,18 +11,18 @@ module ActiveSupport
9
11
  class Deprecation
10
12
  # Default warning behaviors per Rails.env.
11
13
  DEFAULT_BEHAVIORS = {
12
- raise: ->(message, callstack) {
14
+ raise: ->(message, callstack, deprecation_horizon, gem_name) {
13
15
  e = DeprecationException.new(message)
14
16
  e.set_backtrace(callstack.map(&:to_s))
15
17
  raise e
16
18
  },
17
19
 
18
- stderr: ->(message, callstack) {
20
+ stderr: ->(message, callstack, deprecation_horizon, gem_name) {
19
21
  $stderr.puts(message)
20
22
  $stderr.puts callstack.join("\n ") if debug
21
23
  },
22
24
 
23
- log: ->(message, callstack) {
25
+ log: ->(message, callstack, deprecation_horizon, gem_name) {
24
26
  logger =
25
27
  if defined?(Rails.logger) && Rails.logger
26
28
  Rails.logger
@@ -32,12 +34,16 @@ module ActiveSupport
32
34
  logger.debug callstack.join("\n ") if debug
33
35
  },
34
36
 
35
- notify: ->(message, callstack) {
36
- ActiveSupport::Notifications.instrument("deprecation.rails",
37
- message: message, callstack: callstack)
37
+ notify: ->(message, callstack, deprecation_horizon, gem_name) {
38
+ notification_name = "deprecation.#{gem_name.underscore.tr('/', '_')}"
39
+ ActiveSupport::Notifications.instrument(notification_name,
40
+ message: message,
41
+ callstack: callstack,
42
+ gem_name: gem_name,
43
+ deprecation_horizon: deprecation_horizon)
38
44
  },
39
45
 
40
- silence: ->(message, callstack) {},
46
+ silence: ->(message, callstack, deprecation_horizon, gem_name) {},
41
47
  }
42
48
 
43
49
  # Behavior module allows to determine how to display deprecation messages.
@@ -83,8 +89,17 @@ module ActiveSupport
83
89
  # # custom stuff
84
90
  # }
85
91
  def behavior=(behavior)
86
- @behavior = Array(behavior).map { |b| DEFAULT_BEHAVIORS[b] || b }
92
+ @behavior = Array(behavior).map { |b| DEFAULT_BEHAVIORS[b] || arity_coerce(b) }
87
93
  end
94
+
95
+ private
96
+ def arity_coerce(behavior)
97
+ if behavior.arity == 4 || behavior.arity == -1
98
+ behavior
99
+ else
100
+ -> message, callstack, _, _ { behavior.call(message, callstack) }
101
+ end
102
+ end
88
103
  end
89
104
  end
90
105
  end
@@ -1,4 +1,4 @@
1
- require "active_support/inflector/methods"
1
+ # frozen_string_literal: true
2
2
 
3
3
  module ActiveSupport
4
4
  class Deprecation
@@ -27,6 +27,8 @@ module ActiveSupport
27
27
  # ["Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune"]
28
28
  module DeprecatedConstantAccessor
29
29
  def self.included(base)
30
+ require "active_support/inflector/methods"
31
+
30
32
  extension = Module.new do
31
33
  def const_missing(missing_const_name)
32
34
  if class_variable_defined?(:@@_deprecated_constants)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "active_support/core_ext/kernel/singleton_class"
2
4
  require "active_support/core_ext/module/delegation"
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "active_support/core_ext/module/aliasing"
2
4
  require "active_support/core_ext/array/extract_options"
3
5
 
@@ -60,13 +62,6 @@ module ActiveSupport
60
62
  deprecator.deprecation_warning(method_name, options[method_name])
61
63
  super(*args, &block)
62
64
  end
63
-
64
- case
65
- when target_module.protected_method_defined?(method_name)
66
- protected method_name
67
- when target_module.private_method_defined?(method_name)
68
- private method_name
69
- end
70
65
  end
71
66
  end
72
67
 
@@ -1,4 +1,5 @@
1
- require "active_support/inflector/methods"
1
+ # frozen_string_literal: true
2
+
2
3
  require "active_support/core_ext/regexp"
3
4
 
4
5
  module ActiveSupport
@@ -123,6 +124,8 @@ module ActiveSupport
123
124
  # ["Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune"]
124
125
  class DeprecatedConstantProxy < DeprecationProxy
125
126
  def initialize(old_const, new_const, deprecator = ActiveSupport::Deprecation.instance, message: "#{old_const} is deprecated! Use #{new_const} instead.")
127
+ require "active_support/inflector/methods"
128
+
126
129
  @old_const = old_const
127
130
  @new_const = new_const
128
131
  @deprecator = deprecator
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "rbconfig"
2
4
 
3
5
  module ActiveSupport
@@ -18,7 +20,7 @@ module ActiveSupport
18
20
 
19
21
  callstack ||= caller_locations(2)
20
22
  deprecation_message(callstack, message).tap do |m|
21
- behavior.each { |b| b.call(m, callstack) }
23
+ behavior.each { |b| b.call(m, callstack, deprecation_horizon, gem_name) }
22
24
  end
23
25
  end
24
26
 
@@ -102,7 +104,7 @@ module ActiveSupport
102
104
  end
103
105
  end
104
106
 
105
- RAILS_GEM_ROOT = File.expand_path("../../../../..", __FILE__) + "/"
107
+ RAILS_GEM_ROOT = File.expand_path("../../../..", __dir__)
106
108
 
107
109
  def ignored_callstack(path)
108
110
  path.start_with?(RAILS_GEM_ROOT) || path.start_with?(RbConfig::CONFIG["rubylibdir"])
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActiveSupport
2
4
  # This module provides an internal implementation to track descendants
3
5
  # which is faster than iterating through ObjectSpace.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "active_support/core_ext/array/conversions"
2
4
  require "active_support/core_ext/module/delegation"
3
5
  require "active_support/core_ext/object/acts_like"
@@ -131,7 +133,7 @@ module ActiveSupport
131
133
  class << self
132
134
  # Creates a new Duration from string formatted according to ISO 8601 Duration.
133
135
  #
134
- # See {ISO 8601}[http://en.wikipedia.org/wiki/ISO_8601#Durations] for more information.
136
+ # See {ISO 8601}[https://en.wikipedia.org/wiki/ISO_8601#Durations] for more information.
135
137
  # This method allows negative parts to be present in pattern.
136
138
  # If invalid string is provided, it will raise +ActiveSupport::Duration::ISO8601Parser::ParsingError+.
137
139
  def parse(iso8601duration)
@@ -379,18 +381,6 @@ module ActiveSupport
379
381
  to_i
380
382
  end
381
383
 
382
- def respond_to_missing?(method, include_private = false) #:nodoc:
383
- @value.respond_to?(method, include_private)
384
- end
385
-
386
- def init_with(coder) #:nodoc:
387
- initialize(coder["value"], coder["parts"])
388
- end
389
-
390
- def encode_with(coder) #:nodoc:
391
- coder.map = { "value" => @value, "parts" => @parts }
392
- end
393
-
394
384
  # Build ISO 8601 Duration string for this duration.
395
385
  # The +precision+ parameter can be used to limit seconds' precision of duration.
396
386
  def iso8601(precision: nil)
@@ -417,8 +407,12 @@ module ActiveSupport
417
407
  end
418
408
  end
419
409
 
410
+ def respond_to_missing?(method, _)
411
+ value.respond_to?(method)
412
+ end
413
+
420
414
  def method_missing(method, *args, &block)
421
- value.send(method, *args, &block)
415
+ value.public_send(method, *args, &block)
422
416
  end
423
417
 
424
418
  def raise_type_error(other)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "strscan"
2
4
  require "active_support/core_ext/regexp"
3
5
 
@@ -5,7 +7,7 @@ module ActiveSupport
5
7
  class Duration
6
8
  # Parses a string formatted according to ISO 8601 Duration into the hash.
7
9
  #
8
- # See {ISO 8601}[http://en.wikipedia.org/wiki/ISO_8601#Durations] for more information.
10
+ # See {ISO 8601}[https://en.wikipedia.org/wiki/ISO_8601#Durations] for more information.
9
11
  #
10
12
  # This parser allows negative parts to be present in pattern.
11
13
  class ISO8601Parser # :nodoc:
@@ -116,7 +118,7 @@ module ActiveSupport
116
118
  raise_parsing_error "(only last part can be fractional)"
117
119
  end
118
120
 
119
- return true
121
+ true
120
122
  end
121
123
  end
122
124
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "active_support/core_ext/object/blank"
2
4
  require "active_support/core_ext/hash/transform_values"
3
5
 
@@ -15,12 +17,12 @@ module ActiveSupport
15
17
  parts, sign = normalize
16
18
  return "PT0S".freeze if parts.empty?
17
19
 
18
- output = "P"
20
+ output = "P".dup
19
21
  output << "#{parts[:years]}Y" if parts.key?(:years)
20
22
  output << "#{parts[:months]}M" if parts.key?(:months)
21
23
  output << "#{parts[:weeks]}W" if parts.key?(:weeks)
22
24
  output << "#{parts[:days]}D" if parts.key?(:days)
23
- time = ""
25
+ time = "".dup
24
26
  time << "#{parts[:hours]}H" if parts.key?(:hours)
25
27
  time << "#{parts[:minutes]}M" if parts.key?(:minutes)
26
28
  if parts.key?(:seconds)
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "yaml"
4
+ require "active_support/encrypted_file"
5
+ require "active_support/ordered_options"
6
+ require "active_support/core_ext/object/inclusion"
7
+ require "active_support/core_ext/module/delegation"
8
+
9
+ module ActiveSupport
10
+ class EncryptedConfiguration < EncryptedFile
11
+ delegate :[], :fetch, to: :config
12
+ delegate_missing_to :options
13
+
14
+ def initialize(config_path:, key_path:, env_key:)
15
+ super content_path: config_path, key_path: key_path, env_key: env_key
16
+ end
17
+
18
+ # Allow a config to be started without a file present
19
+ def read
20
+ super
21
+ rescue ActiveSupport::EncryptedFile::MissingContentError
22
+ ""
23
+ end
24
+
25
+ def write(contents)
26
+ deserialize(contents)
27
+
28
+ super
29
+ end
30
+
31
+ def config
32
+ @config ||= deserialize(read).deep_symbolize_keys
33
+ end
34
+
35
+ private
36
+ def options
37
+ @options ||= ActiveSupport::InheritableOptions.new(config)
38
+ end
39
+
40
+ def serialize(config)
41
+ config.present? ? YAML.dump(config) : ""
42
+ end
43
+
44
+ def deserialize(config)
45
+ config.present? ? YAML.load(config, content_path) : {}
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,99 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "pathname"
4
+ require "active_support/message_encryptor"
5
+
6
+ module ActiveSupport
7
+ class EncryptedFile
8
+ class MissingContentError < RuntimeError
9
+ def initialize(content_path)
10
+ super "Missing encrypted content file in #{content_path}."
11
+ end
12
+ end
13
+
14
+ class MissingKeyError < RuntimeError
15
+ def initialize(key_path:, env_key:)
16
+ super \
17
+ "Missing encryption key to decrypt file with. " +
18
+ "Ask your team for your master key and write it to #{key_path} or put it in the ENV['#{env_key}']."
19
+ end
20
+ end
21
+
22
+ CIPHER = "aes-128-gcm"
23
+
24
+ def self.generate_key
25
+ SecureRandom.hex(ActiveSupport::MessageEncryptor.key_len(CIPHER))
26
+ end
27
+
28
+
29
+ attr_reader :content_path, :key_path, :env_key
30
+
31
+ def initialize(content_path:, key_path:, env_key:)
32
+ @content_path, @key_path = Pathname.new(content_path), Pathname.new(key_path)
33
+ @env_key = env_key
34
+ end
35
+
36
+ def key
37
+ read_env_key || read_key_file || handle_missing_key
38
+ end
39
+
40
+ def read
41
+ if content_path.exist?
42
+ decrypt content_path.binread
43
+ else
44
+ raise MissingContentError, content_path
45
+ end
46
+ end
47
+
48
+ def write(contents)
49
+ IO.binwrite "#{content_path}.tmp", encrypt(contents)
50
+ FileUtils.mv "#{content_path}.tmp", content_path
51
+ end
52
+
53
+ def change(&block)
54
+ writing read, &block
55
+ end
56
+
57
+
58
+ private
59
+ def writing(contents)
60
+ tmp_file = "#{content_path.basename}.#{Process.pid}"
61
+ tmp_path = Pathname.new File.join(Dir.tmpdir, tmp_file)
62
+ tmp_path.binwrite contents
63
+
64
+ yield tmp_path
65
+
66
+ updated_contents = tmp_path.binread
67
+
68
+ write(updated_contents) if updated_contents != contents
69
+ ensure
70
+ FileUtils.rm(tmp_path) if tmp_path.exist?
71
+ end
72
+
73
+
74
+ def encrypt(contents)
75
+ encryptor.encrypt_and_sign contents
76
+ end
77
+
78
+ def decrypt(contents)
79
+ encryptor.decrypt_and_verify contents
80
+ end
81
+
82
+ def encryptor
83
+ @encryptor ||= ActiveSupport::MessageEncryptor.new([ key ].pack("H*"), cipher: CIPHER)
84
+ end
85
+
86
+
87
+ def read_env_key
88
+ ENV[env_key]
89
+ end
90
+
91
+ def read_key_file
92
+ key_path.binread.strip if key_path.exist?
93
+ end
94
+
95
+ def handle_missing_key
96
+ raise MissingKeyError, key_path: key_path, env_key: env_key
97
+ end
98
+ end
99
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "set"
2
4
  require "pathname"
3
5
  require "concurrent/atomic/atomic_boolean"
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "active_support/callbacks"
2
4
 
3
5
  module ActiveSupport
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "active_support/execution_wrapper"
2
4
 
3
5
  module ActiveSupport