activesupport 5.2.8.1 → 6.0.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 (128) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +182 -586
  3. data/MIT-LICENSE +1 -1
  4. data/README.rdoc +1 -1
  5. data/lib/active_support/backtrace_cleaner.rb +23 -0
  6. data/lib/active_support/cache/file_store.rb +19 -12
  7. data/lib/active_support/cache/mem_cache_store.rb +16 -2
  8. data/lib/active_support/cache/memory_store.rb +5 -0
  9. data/lib/active_support/cache/null_store.rb +5 -0
  10. data/lib/active_support/cache/redis_cache_store.rb +39 -20
  11. data/lib/active_support/cache.rb +40 -18
  12. data/lib/active_support/callbacks.rb +16 -5
  13. data/lib/active_support/concurrency/load_interlock_aware_monitor.rb +0 -18
  14. data/lib/active_support/configurable.rb +4 -8
  15. data/lib/active_support/core_ext/array/extract.rb +21 -0
  16. data/lib/active_support/core_ext/array/prepend_and_append.rb +2 -6
  17. data/lib/active_support/core_ext/array.rb +1 -1
  18. data/lib/active_support/core_ext/class/attribute.rb +1 -1
  19. data/lib/active_support/core_ext/class/subclasses.rb +1 -1
  20. data/lib/active_support/core_ext/date/calculations.rb +6 -5
  21. data/lib/active_support/core_ext/date_and_time/calculations.rb +24 -17
  22. data/lib/active_support/core_ext/date_time/calculations.rb +1 -1
  23. data/lib/active_support/core_ext/enumerable.rb +71 -67
  24. data/lib/active_support/core_ext/hash/compact.rb +2 -26
  25. data/lib/active_support/core_ext/hash/keys.rb +0 -29
  26. data/lib/active_support/core_ext/hash/slice.rb +3 -25
  27. data/lib/active_support/core_ext/hash/transform_values.rb +2 -29
  28. data/lib/active_support/core_ext/hash.rb +0 -2
  29. data/lib/active_support/core_ext/integer/multiple.rb +1 -1
  30. data/lib/active_support/core_ext/load_error.rb +1 -1
  31. data/lib/active_support/core_ext/module/attribute_accessors.rb +2 -5
  32. data/lib/active_support/core_ext/module/attribute_accessors_per_thread.rb +8 -14
  33. data/lib/active_support/core_ext/module/delegation.rb +27 -7
  34. data/lib/active_support/core_ext/module/introspection.rb +37 -13
  35. data/lib/active_support/core_ext/module/reachable.rb +1 -6
  36. data/lib/active_support/core_ext/module/redefine_method.rb +8 -17
  37. data/lib/active_support/core_ext/module.rb +0 -1
  38. data/lib/active_support/core_ext/numeric/conversions.rb +124 -128
  39. data/lib/active_support/core_ext/numeric/inquiry.rb +2 -25
  40. data/lib/active_support/core_ext/numeric.rb +0 -1
  41. data/lib/active_support/core_ext/object/blank.rb +1 -2
  42. data/lib/active_support/core_ext/object/duplicable.rb +5 -2
  43. data/lib/active_support/core_ext/object/json.rb +1 -0
  44. data/lib/active_support/core_ext/object/try.rb +15 -7
  45. data/lib/active_support/core_ext/object/with_options.rb +1 -1
  46. data/lib/active_support/core_ext/range/compare_range.rb +1 -1
  47. data/lib/active_support/core_ext/range/conversions.rb +31 -29
  48. data/lib/active_support/core_ext/range/include_range.rb +6 -0
  49. data/lib/active_support/core_ext/regexp.rb +0 -4
  50. data/lib/active_support/core_ext/securerandom.rb +23 -3
  51. data/lib/active_support/core_ext/string/access.rb +8 -0
  52. data/lib/active_support/core_ext/string/filters.rb +41 -0
  53. data/lib/active_support/core_ext/string/multibyte.rb +4 -3
  54. data/lib/active_support/core_ext/string/output_safety.rb +16 -33
  55. data/lib/active_support/core_ext/string/strip.rb +3 -1
  56. data/lib/active_support/core_ext/uri.rb +1 -0
  57. data/lib/active_support/current_attributes.rb +2 -0
  58. data/lib/active_support/dependencies.rb +28 -11
  59. data/lib/active_support/deprecation/behaviors.rb +1 -1
  60. data/lib/active_support/deprecation/method_wrappers.rb +4 -5
  61. data/lib/active_support/deprecation/proxy_wrappers.rb +0 -2
  62. data/lib/active_support/deprecation.rb +1 -1
  63. data/lib/active_support/descendants_tracker.rb +6 -5
  64. data/lib/active_support/duration/iso8601_parser.rb +2 -3
  65. data/lib/active_support/duration/iso8601_serializer.rb +3 -4
  66. data/lib/active_support/duration.rb +12 -14
  67. data/lib/active_support/encrypted_configuration.rb +0 -4
  68. data/lib/active_support/evented_file_update_checker.rb +25 -7
  69. data/lib/active_support/execution_wrapper.rb +14 -16
  70. data/lib/active_support/gem_version.rb +4 -4
  71. data/lib/active_support/hash_with_indifferent_access.rb +16 -28
  72. data/lib/active_support/i18n.rb +1 -0
  73. data/lib/active_support/i18n_railtie.rb +8 -1
  74. data/lib/active_support/inflector/inflections.rb +1 -4
  75. data/lib/active_support/inflector/methods.rb +15 -27
  76. data/lib/active_support/inflector/transliterate.rb +6 -6
  77. data/lib/active_support/json/decoding.rb +23 -23
  78. data/lib/active_support/json/encoding.rb +6 -2
  79. data/lib/active_support/key_generator.rb +0 -32
  80. data/lib/active_support/lazy_load_hooks.rb +5 -1
  81. data/lib/active_support/locale/en.rb +31 -0
  82. data/lib/active_support/log_subscriber.rb +31 -8
  83. data/lib/active_support/logger.rb +0 -15
  84. data/lib/active_support/logger_silence.rb +28 -12
  85. data/lib/active_support/logger_thread_safe_level.rb +27 -6
  86. data/lib/active_support/message_encryptor.rb +2 -4
  87. data/lib/active_support/message_verifier.rb +2 -2
  88. data/lib/active_support/multibyte/chars.rb +29 -48
  89. data/lib/active_support/multibyte/unicode.rb +44 -281
  90. data/lib/active_support/notifications/fanout.rb +42 -4
  91. data/lib/active_support/notifications/instrumenter.rb +73 -2
  92. data/lib/active_support/notifications.rb +32 -4
  93. data/lib/active_support/number_helper/number_to_currency_converter.rb +2 -2
  94. data/lib/active_support/number_helper/number_to_delimited_converter.rb +3 -1
  95. data/lib/active_support/number_helper/number_to_human_converter.rb +3 -1
  96. data/lib/active_support/number_helper/number_to_human_size_converter.rb +3 -1
  97. data/lib/active_support/number_helper/number_to_percentage_converter.rb +3 -1
  98. data/lib/active_support/number_helper/number_to_phone_converter.rb +2 -0
  99. data/lib/active_support/number_helper/number_to_rounded_converter.rb +5 -3
  100. data/lib/active_support/number_helper.rb +7 -0
  101. data/lib/active_support/ordered_options.rb +1 -1
  102. data/lib/active_support/parameter_filter.rb +124 -0
  103. data/lib/active_support/rails.rb +0 -6
  104. data/lib/active_support/reloader.rb +5 -6
  105. data/lib/active_support/subscriber.rb +16 -26
  106. data/lib/active_support/tagged_logging.rb +13 -4
  107. data/lib/active_support/test_case.rb +91 -0
  108. data/lib/active_support/testing/assertions.rb +15 -1
  109. data/lib/active_support/testing/deprecation.rb +0 -1
  110. data/lib/active_support/testing/file_fixtures.rb +2 -0
  111. data/lib/active_support/testing/isolation.rb +2 -2
  112. data/lib/active_support/testing/method_call_assertions.rb +28 -1
  113. data/lib/active_support/testing/parallelization.rb +109 -0
  114. data/lib/active_support/testing/stream.rb +1 -1
  115. data/lib/active_support/testing/time_helpers.rb +7 -7
  116. data/lib/active_support/time_with_zone.rb +15 -5
  117. data/lib/active_support/values/time_zone.rb +12 -7
  118. data/lib/active_support/xml_mini/jdom.rb +2 -2
  119. data/lib/active_support/xml_mini/libxml.rb +2 -2
  120. data/lib/active_support/xml_mini/libxmlsax.rb +4 -4
  121. data/lib/active_support/xml_mini/nokogiri.rb +2 -2
  122. data/lib/active_support/xml_mini/nokogirisax.rb +3 -3
  123. data/lib/active_support/xml_mini/rexml.rb +2 -2
  124. data/lib/active_support/xml_mini.rb +2 -9
  125. data/lib/active_support.rb +1 -1
  126. metadata +15 -13
  127. data/lib/active_support/core_ext/digest.rb +0 -3
  128. data/lib/active_support/values/unicode_tables.dat +0 -0
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "active_support/callbacks"
4
+ require "concurrent/hash"
4
5
 
5
6
  module ActiveSupport
6
7
  class ExecutionWrapper
@@ -62,21 +63,18 @@ module ActiveSupport
62
63
  # after the work has been performed.
63
64
  #
64
65
  # Where possible, prefer +wrap+.
65
- def self.run!(reset: false)
66
- if reset
67
- lost_instance = active.delete(Thread.current)
68
- lost_instance.complete! unless lost_instance.nil?
66
+ def self.run!
67
+ if active?
68
+ Null
69
69
  else
70
- return Null if active?
71
- end
72
-
73
- new.tap do |instance|
74
- success = nil
75
- begin
76
- instance.run!
77
- success = true
78
- ensure
79
- instance.complete! unless success
70
+ new.tap do |instance|
71
+ success = nil
72
+ begin
73
+ instance.run!
74
+ success = true
75
+ ensure
76
+ instance.complete! unless success
77
+ end
80
78
  end
81
79
  end
82
80
  end
@@ -105,11 +103,11 @@ module ActiveSupport
105
103
  self.active = Concurrent::Hash.new
106
104
 
107
105
  def self.active? # :nodoc:
108
- @active.key?(Thread.current)
106
+ @active[Thread.current]
109
107
  end
110
108
 
111
109
  def run! # :nodoc:
112
- self.class.active[Thread.current] = self
110
+ self.class.active[Thread.current] = true
113
111
  run_callbacks(:run)
114
112
  end
115
113
 
@@ -7,10 +7,10 @@ module ActiveSupport
7
7
  end
8
8
 
9
9
  module VERSION
10
- MAJOR = 5
11
- MINOR = 2
12
- TINY = 8
13
- PRE = "1"
10
+ MAJOR = 6
11
+ MINOR = 0
12
+ TINY = 0
13
+ PRE = "beta1"
14
14
 
15
15
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
16
16
  end
@@ -2,6 +2,7 @@
2
2
 
3
3
  require "active_support/core_ext/hash/keys"
4
4
  require "active_support/core_ext/hash/reverse_merge"
5
+ require "active_support/core_ext/hash/except"
5
6
 
6
7
  module ActiveSupport
7
8
  # Implements a hash where keys <tt>:foo</tt> and <tt>"foo"</tt> are considered
@@ -163,19 +164,6 @@ module ActiveSupport
163
164
  super(convert_key(key))
164
165
  end
165
166
 
166
- # Same as <tt>Hash#assoc</tt> where the key passed as argument can be
167
- # either a string or a symbol:
168
- #
169
- # counters = ActiveSupport::HashWithIndifferentAccess.new
170
- # counters[:foo] = 1
171
- #
172
- # counters.assoc('foo') # => ["foo", 1]
173
- # counters.assoc(:foo) # => ["foo", 1]
174
- # counters.assoc(:zoo) # => nil
175
- def assoc(key)
176
- super(convert_key(key))
177
- end
178
-
179
167
  # Same as <tt>Hash#fetch</tt> where the key passed as argument can be
180
168
  # either a string or a symbol:
181
169
  #
@@ -190,20 +178,18 @@ module ActiveSupport
190
178
  super(convert_key(key), *extras)
191
179
  end
192
180
 
193
- if Hash.new.respond_to?(:dig)
194
- # Same as <tt>Hash#dig</tt> where the key passed as argument can be
195
- # either a string or a symbol:
196
- #
197
- # counters = ActiveSupport::HashWithIndifferentAccess.new
198
- # counters[:foo] = { bar: 1 }
199
- #
200
- # counters.dig('foo', 'bar') # => 1
201
- # counters.dig(:foo, :bar) # => 1
202
- # counters.dig(:zoo) # => nil
203
- def dig(*args)
204
- args[0] = convert_key(args[0]) if args.size > 0
205
- super(*args)
206
- end
181
+ # Same as <tt>Hash#dig</tt> where the key passed as argument can be
182
+ # either a string or a symbol:
183
+ #
184
+ # counters = ActiveSupport::HashWithIndifferentAccess.new
185
+ # counters[:foo] = { bar: 1 }
186
+ #
187
+ # counters.dig('foo', 'bar') # => 1
188
+ # counters.dig(:foo, :bar) # => 1
189
+ # counters.dig(:zoo) # => nil
190
+ def dig(*args)
191
+ args[0] = convert_key(args[0]) if args.size > 0
192
+ super(*args)
207
193
  end
208
194
 
209
195
  # Same as <tt>Hash#default</tt> where the key passed as argument can be
@@ -241,7 +227,7 @@ module ActiveSupport
241
227
  # hash.fetch_values('a', 'c') # => KeyError: key not found: "c"
242
228
  def fetch_values(*indices, &block)
243
229
  indices.collect { |key| fetch(key, &block) }
244
- end if Hash.method_defined?(:fetch_values)
230
+ end
245
231
 
246
232
  # Returns a shallow copy of the hash.
247
233
  #
@@ -294,6 +280,8 @@ module ActiveSupport
294
280
  super(convert_key(key))
295
281
  end
296
282
 
283
+ alias_method :without, :except
284
+
297
285
  def stringify_keys!; self end
298
286
  def deep_stringify_keys!; self end
299
287
  def stringify_keys; dup end
@@ -13,3 +13,4 @@ require "active_support/lazy_load_hooks"
13
13
 
14
14
  ActiveSupport.run_load_hooks(:i18n)
15
15
  I18n.load_path << File.expand_path("locale/en.yml", __dir__)
16
+ I18n.load_path << File.expand_path("locale/en.rb", __dir__)
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "active_support"
4
- require "active_support/file_update_checker"
5
4
  require "active_support/core_ext/array/wrap"
6
5
 
7
6
  # :enddoc:
@@ -92,6 +91,14 @@ module I18n
92
91
  end
93
92
 
94
93
  if args.empty? || args.first.is_a?(Hash)
94
+ ActiveSupport::Deprecation.warn(<<-MSG.squish)
95
+ Using I18n fallbacks with an empty `defaults` sets the defaults to
96
+ include the `default_locale`. This behavior will change in Rails 6.1.
97
+ If you desire the default locale to be included in the defaults, please
98
+ explicitly configure it with `config.i18n.fallbacks.defaults =
99
+ [I18n.default_locale]` or `config.i18n.fallbacks = [I18n.default_locale,
100
+ {...}]`
101
+ MSG
95
102
  args.unshift I18n.default_locale
96
103
  end
97
104
 
@@ -1,8 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "concurrent/map"
4
- require "active_support/core_ext/array/prepend_and_append"
5
- require "active_support/core_ext/regexp"
6
4
  require "active_support/i18n"
7
5
  require "active_support/deprecation"
8
6
 
@@ -67,8 +65,7 @@ module ActiveSupport
67
65
  @__instance__[locale] ||= new
68
66
  end
69
67
 
70
- attr_reader :plurals, :singulars, :uncountables, :humans, :acronyms, :acronym_regex
71
- deprecate :acronym_regex
68
+ attr_reader :plurals, :singulars, :uncountables, :humans, :acronyms
72
69
 
73
70
  attr_reader :acronyms_camelize_regex, :acronyms_underscore_regex # :nodoc:
74
71
 
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "active_support/inflections"
4
- require "active_support/core_ext/regexp"
5
4
 
6
5
  module ActiveSupport
7
6
  # The Inflector transforms words from singular to plural, class names to table
@@ -74,7 +73,7 @@ module ActiveSupport
74
73
  string = string.sub(inflections.acronyms_camelize_regex) { |match| match.downcase }
75
74
  end
76
75
  string.gsub!(/(?:_|(\/))([a-z\d]*)/i) { "#{$1}#{inflections.acronyms[$2] || $2.capitalize}" }
77
- string.gsub!("/".freeze, "::".freeze)
76
+ string.gsub!("/", "::")
78
77
  string
79
78
  end
80
79
 
@@ -91,11 +90,11 @@ module ActiveSupport
91
90
  # camelize(underscore('SSLError')) # => "SslError"
92
91
  def underscore(camel_cased_word)
93
92
  return camel_cased_word unless /[A-Z-]|::/.match?(camel_cased_word)
94
- word = camel_cased_word.to_s.gsub("::".freeze, "/".freeze)
95
- word.gsub!(inflections.acronyms_underscore_regex) { "#{$1 && '_'.freeze }#{$2.downcase}" }
96
- word.gsub!(/([A-Z\d]+)([A-Z][a-z])/, '\1_\2'.freeze)
97
- word.gsub!(/([a-z\d])([A-Z])/, '\1_\2'.freeze)
98
- word.tr!("-".freeze, "_".freeze)
93
+ word = camel_cased_word.to_s.gsub("::", "/")
94
+ word.gsub!(inflections.acronyms_underscore_regex) { "#{$1 && '_' }#{$2.downcase}" }
95
+ word.gsub!(/([A-Z\d]+)([A-Z][a-z])/, '\1_\2')
96
+ word.gsub!(/([a-z\d])([A-Z])/, '\1_\2')
97
+ word.tr!("-", "_")
99
98
  word.downcase!
100
99
  word
101
100
  end
@@ -131,11 +130,11 @@ module ActiveSupport
131
130
 
132
131
  inflections.humans.each { |(rule, replacement)| break if result.sub!(rule, replacement) }
133
132
 
134
- result.sub!(/\A_+/, "".freeze)
133
+ result.sub!(/\A_+/, "")
135
134
  unless keep_id_suffix
136
- result.sub!(/_id\z/, "".freeze)
135
+ result.sub!(/_id\z/, "")
137
136
  end
138
- result.tr!("_".freeze, " ".freeze)
137
+ result.tr!("_", " ")
139
138
 
140
139
  result.gsub!(/([a-z\d]*)/i) do |match|
141
140
  "#{inflections.acronyms[match.downcase] || match.downcase}"
@@ -200,14 +199,14 @@ module ActiveSupport
200
199
  # classify('calculus') # => "Calculus"
201
200
  def classify(table_name)
202
201
  # strip out any leading schema name
203
- camelize(singularize(table_name.to_s.sub(/.*\./, "".freeze)))
202
+ camelize(singularize(table_name.to_s.sub(/.*\./, "")))
204
203
  end
205
204
 
206
205
  # Replaces underscores with dashes in the string.
207
206
  #
208
207
  # dasherize('puni_puni') # => "puni-puni"
209
208
  def dasherize(underscored_word)
210
- underscored_word.tr("_".freeze, "-".freeze)
209
+ underscored_word.tr("_", "-")
211
210
  end
212
211
 
213
212
  # Removes the module part from the expression in the string.
@@ -270,7 +269,7 @@ module ActiveSupport
270
269
  # NameError is raised when the name is not in CamelCase or the constant is
271
270
  # unknown.
272
271
  def constantize(camel_cased_word)
273
- names = camel_cased_word.split("::".freeze)
272
+ names = camel_cased_word.split("::")
274
273
 
275
274
  # Trigger a built-in NameError exception including the ill-formed constant in the message.
276
275
  Object.const_get(camel_cased_word) if names.empty?
@@ -343,18 +342,7 @@ module ActiveSupport
343
342
  # ordinal(-11) # => "th"
344
343
  # ordinal(-1021) # => "st"
345
344
  def ordinal(number)
346
- abs_number = number.to_i.abs
347
-
348
- if (11..13).include?(abs_number % 100)
349
- "th"
350
- else
351
- case abs_number % 10
352
- when 1; "st"
353
- when 2; "nd"
354
- when 3; "rd"
355
- else "th"
356
- end
357
- end
345
+ I18n.translate("number.nth.ordinals", number: number)
358
346
  end
359
347
 
360
348
  # Turns a number into an ordinal string used to denote the position in an
@@ -367,7 +355,7 @@ module ActiveSupport
367
355
  # ordinalize(-11) # => "-11th"
368
356
  # ordinalize(-1021) # => "-1021st"
369
357
  def ordinalize(number)
370
- "#{number}#{ordinal(number)}"
358
+ I18n.translate("number.nth.ordinalized", number: number)
371
359
  end
372
360
 
373
361
  private
@@ -378,7 +366,7 @@ module ActiveSupport
378
366
  # const_regexp("Foo::Bar::Baz") # => "Foo(::Bar(::Baz)?)?"
379
367
  # const_regexp("::") # => "::"
380
368
  def const_regexp(camel_cased_word)
381
- parts = camel_cased_word.split("::".freeze)
369
+ parts = camel_cased_word.split("::")
382
370
 
383
371
  return Regexp.escape(camel_cased_word) if parts.blank?
384
372
 
@@ -58,13 +58,13 @@ module ActiveSupport
58
58
  # I18n.locale = :de
59
59
  # transliterate('Jürgen')
60
60
  # # => "Juergen"
61
- def transliterate(string, replacement = "?".freeze)
61
+ def transliterate(string, replacement = "?")
62
62
  raise ArgumentError, "Can only transliterate strings. Received #{string.class.name}" unless string.is_a?(String)
63
63
 
64
64
  I18n.transliterate(
65
- ActiveSupport::Multibyte::Unicode.normalize(
66
- ActiveSupport::Multibyte::Unicode.tidy_bytes(string), :c),
67
- replacement: replacement)
65
+ ActiveSupport::Multibyte::Unicode.tidy_bytes(string).unicode_normalize(:nfc),
66
+ replacement: replacement
67
+ )
68
68
  end
69
69
 
70
70
  # Replaces special characters in a string so that it may be used as part of
@@ -97,7 +97,7 @@ module ActiveSupport
97
97
  parameterized_string.gsub!(/[^a-z0-9\-_]+/i, separator)
98
98
 
99
99
  unless separator.nil? || separator.empty?
100
- if separator == "-".freeze
100
+ if separator == "-"
101
101
  re_duplicate_separator = /-{2,}/
102
102
  re_leading_trailing_separator = /^-|-$/i
103
103
  else
@@ -108,7 +108,7 @@ module ActiveSupport
108
108
  # No more than one of the separator in a row.
109
109
  parameterized_string.gsub!(re_duplicate_separator, separator)
110
110
  # Remove leading/trailing separator.
111
- parameterized_string.gsub!(re_leading_trailing_separator, "".freeze)
111
+ parameterized_string.gsub!(re_leading_trailing_separator, "")
112
112
  end
113
113
 
114
114
  parameterized_string.downcase! unless preserve_case
@@ -45,32 +45,32 @@ module ActiveSupport
45
45
 
46
46
  private
47
47
 
48
- def convert_dates_from(data)
49
- case data
50
- when nil
51
- nil
52
- when DATE_REGEX
53
- begin
54
- Date.parse(data)
55
- rescue ArgumentError
48
+ def convert_dates_from(data)
49
+ case data
50
+ when nil
51
+ nil
52
+ when DATE_REGEX
53
+ begin
54
+ Date.parse(data)
55
+ rescue ArgumentError
56
+ data
57
+ end
58
+ when DATETIME_REGEX
59
+ begin
60
+ Time.zone.parse(data)
61
+ rescue ArgumentError
62
+ data
63
+ end
64
+ when Array
65
+ data.map! { |d| convert_dates_from(d) }
66
+ when Hash
67
+ data.each do |key, value|
68
+ data[key] = convert_dates_from(value)
69
+ end
70
+ else
56
71
  data
57
72
  end
58
- when DATETIME_REGEX
59
- begin
60
- Time.zone.parse(data)
61
- rescue ArgumentError
62
- data
63
- end
64
- when Array
65
- data.map! { |d| convert_dates_from(d) }
66
- when Hash
67
- data.each do |key, value|
68
- data[key] = convert_dates_from(value)
69
- end
70
- else
71
- data
72
73
  end
73
- end
74
74
  end
75
75
  end
76
76
  end
@@ -54,9 +54,13 @@ module ActiveSupport
54
54
  class EscapedString < String #:nodoc:
55
55
  def to_json(*)
56
56
  if Encoding.escape_html_entities_in_json
57
- super.gsub ESCAPE_REGEX_WITH_HTML_ENTITIES, ESCAPED_CHARS
57
+ s = super
58
+ s.gsub! ESCAPE_REGEX_WITH_HTML_ENTITIES, ESCAPED_CHARS
59
+ s
58
60
  else
59
- super.gsub ESCAPE_REGEX_WITHOUT_HTML_ENTITIES, ESCAPED_CHARS
61
+ s = super
62
+ s.gsub! ESCAPE_REGEX_WITHOUT_HTML_ENTITIES, ESCAPED_CHARS
63
+ s
60
64
  end
61
65
  end
62
66
 
@@ -38,36 +38,4 @@ module ActiveSupport
38
38
  @cache_keys[args.join] ||= @key_generator.generate_key(*args)
39
39
  end
40
40
  end
41
-
42
- class LegacyKeyGenerator # :nodoc:
43
- SECRET_MIN_LENGTH = 30 # Characters
44
-
45
- def initialize(secret)
46
- ensure_secret_secure(secret)
47
- @secret = secret
48
- end
49
-
50
- def generate_key(salt)
51
- @secret
52
- end
53
-
54
- private
55
-
56
- # To prevent users from using something insecure like "Password" we make sure that the
57
- # secret they've provided is at least 30 characters in length.
58
- def ensure_secret_secure(secret)
59
- if secret.blank?
60
- raise ArgumentError, "A secret is required to generate an integrity hash " \
61
- "for cookie session data. Set a secret_key_base of at least " \
62
- "#{SECRET_MIN_LENGTH} characters in via `bin/rails credentials:edit`."
63
- end
64
-
65
- if secret.length < SECRET_MIN_LENGTH
66
- raise ArgumentError, "Secret should be something secure, " \
67
- "like \"#{SecureRandom.hex(16)}\". The value you " \
68
- "provided, \"#{secret}\", is shorter than the minimum length " \
69
- "of #{SECRET_MIN_LENGTH} characters."
70
- end
71
- end
72
- end
73
41
  end
@@ -68,7 +68,11 @@ module ActiveSupport
68
68
  if options[:yield]
69
69
  block.call(base)
70
70
  else
71
- base.instance_eval(&block)
71
+ if base.is_a?(Module)
72
+ base.class_eval(&block)
73
+ else
74
+ base.instance_eval(&block)
75
+ end
72
76
  end
73
77
  end
74
78
  end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ {
4
+ en: {
5
+ number: {
6
+ nth: {
7
+ ordinals: lambda do |_key, number:, **_options|
8
+ case number
9
+ when 1; "st"
10
+ when 2; "nd"
11
+ when 3; "rd"
12
+ when 4, 5, 6, 7, 8, 9, 10, 11, 12, 13; "th"
13
+ else
14
+ num_modulo = number.to_i.abs % 100
15
+ num_modulo %= 10 if num_modulo > 13
16
+ case num_modulo
17
+ when 1; "st"
18
+ when 2; "nd"
19
+ when 3; "rd"
20
+ else "th"
21
+ end
22
+ end
23
+ end,
24
+
25
+ ordinalized: lambda do |_key, number:, **_options|
26
+ "#{number}#{ActiveSupport::Inflector.ordinal(number)}"
27
+ end
28
+ }
29
+ }
30
+ }
31
+ }
@@ -5,8 +5,8 @@ require "active_support/core_ext/class/attribute"
5
5
  require "active_support/subscriber"
6
6
 
7
7
  module ActiveSupport
8
- # ActiveSupport::LogSubscriber is an object set to consume
9
- # ActiveSupport::Notifications with the sole purpose of logging them.
8
+ # <tt>ActiveSupport::LogSubscriber</tt> is an object set to consume
9
+ # <tt>ActiveSupport::Notifications</tt> with the sole purpose of logging them.
10
10
  # The log subscriber dispatches notifications to a registered object based
11
11
  # on its given namespace.
12
12
  #
@@ -16,7 +16,7 @@ module ActiveSupport
16
16
  # module ActiveRecord
17
17
  # class LogSubscriber < ActiveSupport::LogSubscriber
18
18
  # def sql(event)
19
- # "#{event.payload[:name]} (#{event.duration}) #{event.payload[:sql]}"
19
+ # info "#{event.payload[:name]} (#{event.duration}) #{event.payload[:sql]}"
20
20
  # end
21
21
  # end
22
22
  # end
@@ -29,13 +29,36 @@ module ActiveSupport
29
29
  # subscriber, the line above should be called after your
30
30
  # <tt>ActiveRecord::LogSubscriber</tt> definition.
31
31
  #
32
- # After configured, whenever a "sql.active_record" notification is published,
33
- # it will properly dispatch the event (ActiveSupport::Notifications::Event) to
34
- # the sql method.
32
+ # After configured, whenever a <tt>"sql.active_record"</tt> notification is published,
33
+ # it will properly dispatch the event
34
+ # (<tt>ActiveSupport::Notifications::Event</tt>) to the sql method.
35
+ #
36
+ # Being an <tt>ActiveSupport::Notifications</tt> consumer,
37
+ # <tt>ActiveSupport::LogSubscriber</tt> exposes a simple interface to check if
38
+ # instrumented code raises an exception. It is common to log a different
39
+ # message in case of an error, and this can be achieved by extending
40
+ # the previous example:
41
+ #
42
+ # module ActiveRecord
43
+ # class LogSubscriber < ActiveSupport::LogSubscriber
44
+ # def sql(event)
45
+ # exception = event.payload[:exception]
46
+ #
47
+ # if exception
48
+ # exception_object = event.payload[:exception_object]
49
+ #
50
+ # error "[ERROR] #{event.payload[:name]}: #{exception.join(', ')} " \
51
+ # "(#{exception_object.backtrace.first})"
52
+ # else
53
+ # # standard logger code
54
+ # end
55
+ # end
56
+ # end
57
+ # end
35
58
  #
36
59
  # Log subscriber also has some helpers to deal with logging and automatically
37
- # flushes all logs when the request finishes (via action_dispatch.callback
38
- # notification) in a Rails environment.
60
+ # flushes all logs when the request finishes
61
+ # (via <tt>action_dispatch.callback</tt> notification) in a Rails environment.
39
62
  class LogSubscriber < Subscriber
40
63
  # Embed in a String to clear all previous ANSI sequences.
41
64
  CLEAR = "\e[0m"
@@ -6,7 +6,6 @@ require "logger"
6
6
 
7
7
  module ActiveSupport
8
8
  class Logger < ::Logger
9
- include ActiveSupport::LoggerThreadSafeLevel
10
9
  include LoggerSilence
11
10
 
12
11
  # Returns true if the logger destination matches one of the sources
@@ -81,20 +80,6 @@ module ActiveSupport
81
80
  def initialize(*args)
82
81
  super
83
82
  @formatter = SimpleFormatter.new
84
- after_initialize if respond_to? :after_initialize
85
- end
86
-
87
- def add(severity, message = nil, progname = nil, &block)
88
- return true if @logdev.nil? || (severity || UNKNOWN) < level
89
- super
90
- end
91
-
92
- Logger::Severity.constants.each do |severity|
93
- class_eval(<<-EOT, __FILE__, __LINE__ + 1)
94
- def #{severity.downcase}? # def debug?
95
- Logger::#{severity} >= level # DEBUG >= level
96
- end # end
97
- EOT
98
83
  end
99
84
 
100
85
  # Simple formatter which only displays the message.
@@ -2,28 +2,44 @@
2
2
 
3
3
  require "active_support/concern"
4
4
  require "active_support/core_ext/module/attribute_accessors"
5
- require "concurrent"
5
+ require "active_support/logger_thread_safe_level"
6
6
 
7
7
  module LoggerSilence
8
8
  extend ActiveSupport::Concern
9
9
 
10
10
  included do
11
- cattr_accessor :silencer, default: true
11
+ ActiveSupport::Deprecation.warn(
12
+ "Including LoggerSilence is deprecated and will be removed in Rails 6.1. " \
13
+ "Please use `ActiveSupport::LoggerSilence` instead"
14
+ )
15
+
16
+ include ActiveSupport::LoggerSilence
12
17
  end
18
+ end
19
+
20
+ module ActiveSupport
21
+ module LoggerSilence
22
+ extend ActiveSupport::Concern
23
+
24
+ included do
25
+ cattr_accessor :silencer, default: true
26
+ include ActiveSupport::LoggerThreadSafeLevel
27
+ end
13
28
 
14
- # Silences the logger for the duration of the block.
15
- def silence(temporary_level = Logger::ERROR)
16
- if silencer
17
- begin
18
- old_local_level = local_level
19
- self.local_level = temporary_level
29
+ # Silences the logger for the duration of the block.
30
+ def silence(temporary_level = Logger::ERROR)
31
+ if silencer
32
+ begin
33
+ old_local_level = local_level
34
+ self.local_level = temporary_level
20
35
 
36
+ yield self
37
+ ensure
38
+ self.local_level = old_local_level
39
+ end
40
+ else
21
41
  yield self
22
- ensure
23
- self.local_level = old_local_level
24
42
  end
25
- else
26
- yield self
27
43
  end
28
44
  end
29
45
  end