activesupport 6.0.4 → 6.1.0.rc1
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +337 -508
- data/MIT-LICENSE +1 -1
- data/README.rdoc +1 -1
- data/lib/active_support.rb +13 -1
- data/lib/active_support/array_inquirer.rb +4 -2
- data/lib/active_support/backtrace_cleaner.rb +3 -3
- data/lib/active_support/benchmarkable.rb +1 -1
- data/lib/active_support/cache.rb +75 -34
- data/lib/active_support/cache/file_store.rb +2 -2
- data/lib/active_support/cache/mem_cache_store.rb +20 -14
- data/lib/active_support/cache/memory_store.rb +38 -26
- data/lib/active_support/cache/redis_cache_store.rb +25 -25
- data/lib/active_support/cache/strategy/local_cache.rb +13 -4
- data/lib/active_support/callbacks.rb +65 -56
- data/lib/active_support/concern.rb +46 -2
- data/lib/active_support/configurable.rb +3 -3
- data/lib/active_support/configuration_file.rb +46 -0
- data/lib/active_support/core_ext/benchmark.rb +2 -2
- data/lib/active_support/core_ext/class/attribute.rb +34 -44
- data/lib/active_support/core_ext/class/subclasses.rb +17 -38
- data/lib/active_support/core_ext/date/conversions.rb +2 -1
- data/lib/active_support/core_ext/date_and_time/calculations.rb +13 -0
- data/lib/active_support/core_ext/date_and_time/compatibility.rb +15 -0
- data/lib/active_support/core_ext/enumerable.rb +76 -4
- data/lib/active_support/core_ext/hash/conversions.rb +2 -2
- data/lib/active_support/core_ext/hash/deep_transform_values.rb +1 -1
- data/lib/active_support/core_ext/hash/keys.rb +1 -1
- data/lib/active_support/core_ext/hash/slice.rb +3 -2
- data/lib/active_support/core_ext/load_error.rb +1 -1
- data/lib/active_support/core_ext/marshal.rb +2 -0
- data/lib/active_support/core_ext/module/attr_internal.rb +2 -2
- data/lib/active_support/core_ext/module/attribute_accessors.rb +23 -29
- data/lib/active_support/core_ext/module/attribute_accessors_per_thread.rb +8 -4
- data/lib/active_support/core_ext/module/concerning.rb +8 -2
- data/lib/active_support/core_ext/module/delegation.rb +38 -28
- data/lib/active_support/core_ext/module/introspection.rb +1 -25
- data/lib/active_support/core_ext/name_error.rb +29 -2
- data/lib/active_support/core_ext/numeric/conversions.rb +22 -18
- data/lib/active_support/core_ext/object/deep_dup.rb +1 -1
- data/lib/active_support/core_ext/object/json.rb +5 -1
- data/lib/active_support/core_ext/object/try.rb +2 -2
- data/lib/active_support/core_ext/range/compare_range.rb +9 -3
- data/lib/active_support/core_ext/range/include_time_with_zone.rb +8 -3
- data/lib/active_support/core_ext/string/access.rb +5 -24
- data/lib/active_support/core_ext/string/inflections.rb +38 -4
- data/lib/active_support/core_ext/string/inquiry.rb +1 -0
- data/lib/active_support/core_ext/string/multibyte.rb +2 -2
- data/lib/active_support/core_ext/string/output_safety.rb +8 -10
- data/lib/active_support/core_ext/string/starts_ends_with.rb +2 -2
- data/lib/active_support/core_ext/symbol.rb +3 -0
- data/lib/active_support/core_ext/symbol/starts_ends_with.rb +14 -0
- data/lib/active_support/core_ext/time/calculations.rb +16 -0
- data/lib/active_support/core_ext/time/conversions.rb +1 -0
- data/lib/active_support/core_ext/uri.rb +5 -1
- data/lib/active_support/current_attributes.rb +7 -2
- data/lib/active_support/current_attributes/test_helper.rb +13 -0
- data/lib/active_support/dependencies.rb +38 -24
- data/lib/active_support/deprecation.rb +6 -1
- data/lib/active_support/deprecation/behaviors.rb +15 -2
- data/lib/active_support/deprecation/disallowed.rb +56 -0
- data/lib/active_support/deprecation/instance_delegator.rb +0 -1
- data/lib/active_support/deprecation/method_wrappers.rb +3 -2
- data/lib/active_support/deprecation/proxy_wrappers.rb +2 -2
- data/lib/active_support/deprecation/reporting.rb +50 -7
- data/lib/active_support/descendants_tracker.rb +6 -2
- data/lib/active_support/duration.rb +71 -22
- data/lib/active_support/duration/iso8601_serializer.rb +15 -9
- data/lib/active_support/encrypted_file.rb +19 -2
- data/lib/active_support/environment_inquirer.rb +20 -0
- data/lib/active_support/evented_file_update_checker.rb +69 -133
- data/lib/active_support/fork_tracker.rb +58 -0
- data/lib/active_support/gem_version.rb +3 -3
- data/lib/active_support/hash_with_indifferent_access.rb +35 -22
- data/lib/active_support/i18n_railtie.rb +14 -19
- data/lib/active_support/inflector/inflections.rb +1 -2
- data/lib/active_support/inflector/methods.rb +35 -31
- data/lib/active_support/inflector/transliterate.rb +4 -4
- data/lib/active_support/json/decoding.rb +4 -4
- data/lib/active_support/json/encoding.rb +5 -1
- data/lib/active_support/key_generator.rb +1 -1
- data/lib/active_support/locale/en.yml +7 -3
- data/lib/active_support/log_subscriber.rb +8 -0
- data/lib/active_support/logger.rb +1 -1
- data/lib/active_support/logger_silence.rb +2 -26
- data/lib/active_support/logger_thread_safe_level.rb +34 -12
- data/lib/active_support/message_encryptor.rb +4 -7
- data/lib/active_support/message_verifier.rb +5 -5
- data/lib/active_support/messages/rotation_configuration.rb +2 -1
- data/lib/active_support/messages/rotator.rb +6 -5
- data/lib/active_support/multibyte/chars.rb +4 -42
- data/lib/active_support/multibyte/unicode.rb +9 -83
- data/lib/active_support/notifications.rb +31 -4
- data/lib/active_support/notifications/fanout.rb +23 -8
- data/lib/active_support/notifications/instrumenter.rb +6 -15
- data/lib/active_support/number_helper.rb +29 -14
- data/lib/active_support/number_helper/number_converter.rb +1 -1
- data/lib/active_support/number_helper/number_to_human_converter.rb +1 -1
- data/lib/active_support/number_helper/number_to_human_size_converter.rb +1 -1
- data/lib/active_support/number_helper/number_to_rounded_converter.rb +3 -3
- data/lib/active_support/number_helper/rounding_helper.rb +12 -28
- data/lib/active_support/option_merger.rb +2 -1
- data/lib/active_support/ordered_options.rb +8 -2
- data/lib/active_support/parameter_filter.rb +15 -10
- data/lib/active_support/per_thread_registry.rb +1 -1
- data/lib/active_support/rails.rb +1 -4
- data/lib/active_support/railtie.rb +23 -1
- data/lib/active_support/secure_compare_rotator.rb +51 -0
- data/lib/active_support/security_utils.rb +19 -12
- data/lib/active_support/string_inquirer.rb +4 -2
- data/lib/active_support/subscriber.rb +12 -7
- data/lib/active_support/tagged_logging.rb +29 -4
- data/lib/active_support/testing/assertions.rb +18 -11
- data/lib/active_support/testing/parallelization.rb +12 -95
- data/lib/active_support/testing/parallelization/server.rb +78 -0
- data/lib/active_support/testing/parallelization/worker.rb +100 -0
- data/lib/active_support/testing/time_helpers.rb +40 -3
- data/lib/active_support/time_with_zone.rb +66 -42
- data/lib/active_support/values/time_zone.rb +20 -10
- data/lib/active_support/xml_mini/rexml.rb +8 -1
- metadata +36 -38
- data/lib/active_support/core_ext/array/prepend_and_append.rb +0 -5
- data/lib/active_support/core_ext/hash/compact.rb +0 -5
- data/lib/active_support/core_ext/hash/transform_values.rb +0 -5
- data/lib/active_support/core_ext/module/reachable.rb +0 -6
- data/lib/active_support/core_ext/numeric/inquiry.rb +0 -5
- data/lib/active_support/core_ext/range/include_range.rb +0 -9
@@ -169,7 +169,11 @@ class Hash
|
|
169
169
|
self
|
170
170
|
end
|
171
171
|
|
172
|
-
|
172
|
+
result = {}
|
173
|
+
subset.each do |k, v|
|
174
|
+
result[k.to_s] = options ? v.as_json(options.dup) : v.as_json
|
175
|
+
end
|
176
|
+
result
|
173
177
|
end
|
174
178
|
end
|
175
179
|
|
@@ -145,14 +145,14 @@ class NilClass
|
|
145
145
|
#
|
146
146
|
# With +try+
|
147
147
|
# @person.try(:children).try(:first).try(:name)
|
148
|
-
def try(
|
148
|
+
def try(_method_name = nil, *)
|
149
149
|
nil
|
150
150
|
end
|
151
151
|
|
152
152
|
# Calling +try!+ on +nil+ always returns +nil+.
|
153
153
|
#
|
154
154
|
# nil.try!(:name) # => nil
|
155
|
-
def try!(
|
155
|
+
def try!(_method_name = nil, *)
|
156
156
|
nil
|
157
157
|
end
|
158
158
|
end
|
@@ -15,11 +15,13 @@ module ActiveSupport
|
|
15
15
|
# The given range must be fully bounded, with both start and end.
|
16
16
|
def ===(value)
|
17
17
|
if value.is_a?(::Range)
|
18
|
+
is_backwards_op = value.exclude_end? ? :>= : :>
|
19
|
+
return false if value.begin && value.end && value.begin.public_send(is_backwards_op, value.end)
|
18
20
|
# 1...10 includes 1..9 but it does not include 1..10.
|
19
21
|
# 1..10 includes 1...11 but it does not include 1...12.
|
20
22
|
operator = exclude_end? && !value.exclude_end? ? :< : :<=
|
21
23
|
value_max = !exclude_end? && value.exclude_end? ? value.max : value.last
|
22
|
-
super(value.first) && (self.end.nil? || value_max.
|
24
|
+
super(value.first) && (self.end.nil? || value_max.public_send(operator, last))
|
23
25
|
else
|
24
26
|
super
|
25
27
|
end
|
@@ -38,11 +40,13 @@ module ActiveSupport
|
|
38
40
|
# The given range must be fully bounded, with both start and end.
|
39
41
|
def include?(value)
|
40
42
|
if value.is_a?(::Range)
|
43
|
+
is_backwards_op = value.exclude_end? ? :>= : :>
|
44
|
+
return false if value.begin && value.end && value.begin.public_send(is_backwards_op, value.end)
|
41
45
|
# 1...10 includes 1..9 but it does not include 1..10.
|
42
46
|
# 1..10 includes 1...11 but it does not include 1...12.
|
43
47
|
operator = exclude_end? && !value.exclude_end? ? :< : :<=
|
44
48
|
value_max = !exclude_end? && value.exclude_end? ? value.max : value.last
|
45
|
-
super(value.first) && (self.end.nil? || value_max.
|
49
|
+
super(value.first) && (self.end.nil? || value_max.public_send(operator, last))
|
46
50
|
else
|
47
51
|
super
|
48
52
|
end
|
@@ -61,11 +65,13 @@ module ActiveSupport
|
|
61
65
|
# The given range must be fully bounded, with both start and end.
|
62
66
|
def cover?(value)
|
63
67
|
if value.is_a?(::Range)
|
68
|
+
is_backwards_op = value.exclude_end? ? :>= : :>
|
69
|
+
return false if value.begin && value.end && value.begin.public_send(is_backwards_op, value.end)
|
64
70
|
# 1...10 covers 1..9 but it does not cover 1..10.
|
65
71
|
# 1..10 covers 1...11 but it does not cover 1...12.
|
66
72
|
operator = exclude_end? && !value.exclude_end? ? :< : :<=
|
67
73
|
value_max = !exclude_end? && value.exclude_end? ? value.max : value.last
|
68
|
-
super(value.first) && (self.end.nil? || value_max.
|
74
|
+
super(value.first) && (self.end.nil? || value_max.public_send(operator, last))
|
69
75
|
else
|
70
76
|
super
|
71
77
|
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "active_support/time_with_zone"
|
4
|
+
require "active_support/deprecation"
|
4
5
|
|
5
6
|
module ActiveSupport
|
6
7
|
module IncludeTimeWithZone #:nodoc:
|
@@ -9,9 +10,13 @@ module ActiveSupport
|
|
9
10
|
# (1.hour.ago..1.hour.from_now).include?(Time.current) # => true
|
10
11
|
#
|
11
12
|
def include?(value)
|
12
|
-
if self.begin.is_a?(TimeWithZone)
|
13
|
-
|
14
|
-
|
13
|
+
if self.begin.is_a?(TimeWithZone) || self.end.is_a?(TimeWithZone)
|
14
|
+
ActiveSupport::Deprecation.warn(<<-MSG.squish)
|
15
|
+
Using `Range#include?` to check the inclusion of a value in
|
16
|
+
a date time range is deprecated.
|
17
|
+
It is recommended to use `Range#cover?` instead of `Range#include?` to
|
18
|
+
check the inclusion of a value in a date time range.
|
19
|
+
MSG
|
15
20
|
cover?(value)
|
16
21
|
else
|
17
22
|
super
|
@@ -44,7 +44,7 @@ class String
|
|
44
44
|
# str.from(0).to(-1) # => "hello"
|
45
45
|
# str.from(1).to(-2) # => "ell"
|
46
46
|
def from(position)
|
47
|
-
self[position
|
47
|
+
self[position, length]
|
48
48
|
end
|
49
49
|
|
50
50
|
# Returns a substring from the beginning of the string to the given position.
|
@@ -61,7 +61,8 @@ class String
|
|
61
61
|
# str.from(0).to(-1) # => "hello"
|
62
62
|
# str.from(1).to(-2) # => "ell"
|
63
63
|
def to(position)
|
64
|
-
|
64
|
+
position += size if position < 0
|
65
|
+
self[0, position + 1] || +""
|
65
66
|
end
|
66
67
|
|
67
68
|
# Returns the first character. If a limit is supplied, returns a substring
|
@@ -75,17 +76,7 @@ class String
|
|
75
76
|
# str.first(0) # => ""
|
76
77
|
# str.first(6) # => "hello"
|
77
78
|
def first(limit = 1)
|
78
|
-
|
79
|
-
"Calling String#first with a negative integer limit " \
|
80
|
-
"will raise an ArgumentError in Rails 6.1."
|
81
|
-
) if limit < 0
|
82
|
-
if limit == 0
|
83
|
-
""
|
84
|
-
elsif limit >= size
|
85
|
-
dup
|
86
|
-
else
|
87
|
-
to(limit - 1)
|
88
|
-
end
|
79
|
+
self[0, limit] || raise(ArgumentError, "negative limit")
|
89
80
|
end
|
90
81
|
|
91
82
|
# Returns the last character of the string. If a limit is supplied, returns a substring
|
@@ -99,16 +90,6 @@ class String
|
|
99
90
|
# str.last(0) # => ""
|
100
91
|
# str.last(6) # => "hello"
|
101
92
|
def last(limit = 1)
|
102
|
-
|
103
|
-
"Calling String#last with a negative integer limit " \
|
104
|
-
"will raise an ArgumentError in Rails 6.1."
|
105
|
-
) if limit < 0
|
106
|
-
if limit == 0
|
107
|
-
""
|
108
|
-
elsif limit >= size
|
109
|
-
dup
|
110
|
-
else
|
111
|
-
from(-limit)
|
112
|
-
end
|
93
|
+
self[[length - limit, 0].max, limit] || raise(ArgumentError, "negative limit")
|
113
94
|
end
|
114
95
|
end
|
@@ -30,6 +30,8 @@ class String
|
|
30
30
|
# 'apple'.pluralize(2) # => "apples"
|
31
31
|
# 'ley'.pluralize(:es) # => "leyes"
|
32
32
|
# 'ley'.pluralize(1, :es) # => "ley"
|
33
|
+
#
|
34
|
+
# See ActiveSupport::Inflector.pluralize.
|
33
35
|
def pluralize(count = nil, locale = :en)
|
34
36
|
locale = count if count.is_a?(Symbol)
|
35
37
|
if count == 1
|
@@ -53,28 +55,34 @@ class String
|
|
53
55
|
# 'the blue mailmen'.singularize # => "the blue mailman"
|
54
56
|
# 'CamelOctopi'.singularize # => "CamelOctopus"
|
55
57
|
# 'leyes'.singularize(:es) # => "ley"
|
58
|
+
#
|
59
|
+
# See ActiveSupport::Inflector.singularize.
|
56
60
|
def singularize(locale = :en)
|
57
61
|
ActiveSupport::Inflector.singularize(self, locale)
|
58
62
|
end
|
59
63
|
|
60
64
|
# +constantize+ tries to find a declared constant with the name specified
|
61
65
|
# in the string. It raises a NameError when the name is not in CamelCase
|
62
|
-
# or is not initialized.
|
66
|
+
# or is not initialized.
|
63
67
|
#
|
64
68
|
# 'Module'.constantize # => Module
|
65
69
|
# 'Class'.constantize # => Class
|
66
70
|
# 'blargle'.constantize # => NameError: wrong constant name blargle
|
71
|
+
#
|
72
|
+
# See ActiveSupport::Inflector.constantize.
|
67
73
|
def constantize
|
68
74
|
ActiveSupport::Inflector.constantize(self)
|
69
75
|
end
|
70
76
|
|
71
77
|
# +safe_constantize+ tries to find a declared constant with the name specified
|
72
78
|
# in the string. It returns +nil+ when the name is not in CamelCase
|
73
|
-
# or is not initialized.
|
79
|
+
# or is not initialized.
|
74
80
|
#
|
75
81
|
# 'Module'.safe_constantize # => Module
|
76
82
|
# 'Class'.safe_constantize # => Class
|
77
83
|
# 'blargle'.safe_constantize # => nil
|
84
|
+
#
|
85
|
+
# See ActiveSupport::Inflector.safe_constantize.
|
78
86
|
def safe_constantize
|
79
87
|
ActiveSupport::Inflector.safe_constantize(self)
|
80
88
|
end
|
@@ -88,6 +96,10 @@ class String
|
|
88
96
|
# 'active_record'.camelize(:lower) # => "activeRecord"
|
89
97
|
# 'active_record/errors'.camelize # => "ActiveRecord::Errors"
|
90
98
|
# 'active_record/errors'.camelize(:lower) # => "activeRecord::Errors"
|
99
|
+
#
|
100
|
+
# +camelize+ is also aliased as +camelcase+.
|
101
|
+
#
|
102
|
+
# See ActiveSupport::Inflector.camelize.
|
91
103
|
def camelize(first_letter = :upper)
|
92
104
|
case first_letter
|
93
105
|
when :upper
|
@@ -108,11 +120,13 @@ class String
|
|
108
120
|
# optional parameter +keep_id_suffix+ to true.
|
109
121
|
# By default, this parameter is false.
|
110
122
|
#
|
111
|
-
# +titleize+ is also aliased as +titlecase+.
|
112
|
-
#
|
113
123
|
# 'man from the boondocks'.titleize # => "Man From The Boondocks"
|
114
124
|
# 'x-men: the last stand'.titleize # => "X Men: The Last Stand"
|
115
125
|
# 'string_ending_with_id'.titleize(keep_id_suffix: true) # => "String Ending With Id"
|
126
|
+
#
|
127
|
+
# +titleize+ is also aliased as +titlecase+.
|
128
|
+
#
|
129
|
+
# See ActiveSupport::Inflector.titleize.
|
116
130
|
def titleize(keep_id_suffix: false)
|
117
131
|
ActiveSupport::Inflector.titleize(self, keep_id_suffix: keep_id_suffix)
|
118
132
|
end
|
@@ -124,6 +138,8 @@ class String
|
|
124
138
|
#
|
125
139
|
# 'ActiveModel'.underscore # => "active_model"
|
126
140
|
# 'ActiveModel::Errors'.underscore # => "active_model/errors"
|
141
|
+
#
|
142
|
+
# See ActiveSupport::Inflector.underscore.
|
127
143
|
def underscore
|
128
144
|
ActiveSupport::Inflector.underscore(self)
|
129
145
|
end
|
@@ -131,6 +147,8 @@ class String
|
|
131
147
|
# Replaces underscores with dashes in the string.
|
132
148
|
#
|
133
149
|
# 'puni_puni'.dasherize # => "puni-puni"
|
150
|
+
#
|
151
|
+
# See ActiveSupport::Inflector.dasherize.
|
134
152
|
def dasherize
|
135
153
|
ActiveSupport::Inflector.dasherize(self)
|
136
154
|
end
|
@@ -142,6 +160,8 @@ class String
|
|
142
160
|
# '::Inflections'.demodulize # => "Inflections"
|
143
161
|
# ''.demodulize # => ''
|
144
162
|
#
|
163
|
+
# See ActiveSupport::Inflector.demodulize.
|
164
|
+
#
|
145
165
|
# See also +deconstantize+.
|
146
166
|
def demodulize
|
147
167
|
ActiveSupport::Inflector.demodulize(self)
|
@@ -155,6 +175,8 @@ class String
|
|
155
175
|
# '::String'.deconstantize # => ""
|
156
176
|
# ''.deconstantize # => ""
|
157
177
|
#
|
178
|
+
# See ActiveSupport::Inflector.deconstantize.
|
179
|
+
#
|
158
180
|
# See also +demodulize+.
|
159
181
|
def deconstantize
|
160
182
|
ActiveSupport::Inflector.deconstantize(self)
|
@@ -192,6 +214,8 @@ class String
|
|
192
214
|
#
|
193
215
|
# <%= link_to(@person.name, person_path) %>
|
194
216
|
# # => <a href="/person/1-Donald-E-Knuth">Donald E. Knuth</a>
|
217
|
+
#
|
218
|
+
# See ActiveSupport::Inflector.parameterize.
|
195
219
|
def parameterize(separator: "-", preserve_case: false, locale: nil)
|
196
220
|
ActiveSupport::Inflector.parameterize(self, separator: separator, preserve_case: preserve_case, locale: locale)
|
197
221
|
end
|
@@ -202,6 +226,8 @@ class String
|
|
202
226
|
# 'RawScaledScorer'.tableize # => "raw_scaled_scorers"
|
203
227
|
# 'ham_and_egg'.tableize # => "ham_and_eggs"
|
204
228
|
# 'fancyCategory'.tableize # => "fancy_categories"
|
229
|
+
#
|
230
|
+
# See ActiveSupport::Inflector.tableize.
|
205
231
|
def tableize
|
206
232
|
ActiveSupport::Inflector.tableize(self)
|
207
233
|
end
|
@@ -212,6 +238,8 @@ class String
|
|
212
238
|
#
|
213
239
|
# 'ham_and_eggs'.classify # => "HamAndEgg"
|
214
240
|
# 'posts'.classify # => "Post"
|
241
|
+
#
|
242
|
+
# See ActiveSupport::Inflector.classify.
|
215
243
|
def classify
|
216
244
|
ActiveSupport::Inflector.classify(self)
|
217
245
|
end
|
@@ -233,6 +261,8 @@ class String
|
|
233
261
|
# 'author_id'.humanize(capitalize: false) # => "author"
|
234
262
|
# '_id'.humanize # => "Id"
|
235
263
|
# 'author_id'.humanize(keep_id_suffix: true) # => "Author Id"
|
264
|
+
#
|
265
|
+
# See ActiveSupport::Inflector.humanize.
|
236
266
|
def humanize(capitalize: true, keep_id_suffix: false)
|
237
267
|
ActiveSupport::Inflector.humanize(self, capitalize: capitalize, keep_id_suffix: keep_id_suffix)
|
238
268
|
end
|
@@ -242,6 +272,8 @@ class String
|
|
242
272
|
# 'what a Lovely Day'.upcase_first # => "What a Lovely Day"
|
243
273
|
# 'w'.upcase_first # => "W"
|
244
274
|
# ''.upcase_first # => ""
|
275
|
+
#
|
276
|
+
# See ActiveSupport::Inflector.upcase_first.
|
245
277
|
def upcase_first
|
246
278
|
ActiveSupport::Inflector.upcase_first(self)
|
247
279
|
end
|
@@ -253,6 +285,8 @@ class String
|
|
253
285
|
# 'Message'.foreign_key # => "message_id"
|
254
286
|
# 'Message'.foreign_key(false) # => "messageid"
|
255
287
|
# 'Admin::Post'.foreign_key # => "post_id"
|
288
|
+
#
|
289
|
+
# See ActiveSupport::Inflector.foreign_key.
|
256
290
|
def foreign_key(separate_class_name_and_id_with_underscore = true)
|
257
291
|
ActiveSupport::Inflector.foreign_key(self, separate_class_name_and_id_with_underscore)
|
258
292
|
end
|
@@ -47,9 +47,9 @@ class String
|
|
47
47
|
# iso_str.is_utf8? # => false
|
48
48
|
def is_utf8?
|
49
49
|
case encoding
|
50
|
-
when Encoding::UTF_8
|
50
|
+
when Encoding::UTF_8, Encoding::US_ASCII
|
51
51
|
valid_encoding?
|
52
|
-
when Encoding::ASCII_8BIT
|
52
|
+
when Encoding::ASCII_8BIT
|
53
53
|
dup.force_encoding(Encoding::UTF_8).valid_encoding?
|
54
54
|
else
|
55
55
|
false
|
@@ -1,7 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "erb"
|
4
|
-
require "active_support/core_ext/kernel/singleton_class"
|
5
4
|
require "active_support/core_ext/module/redefine_method"
|
6
5
|
require "active_support/multibyte/unicode"
|
7
6
|
|
@@ -135,7 +134,7 @@ module ActiveSupport #:nodoc:
|
|
135
134
|
class SafeBuffer < String
|
136
135
|
UNSAFE_STRING_METHODS = %w(
|
137
136
|
capitalize chomp chop delete delete_prefix delete_suffix
|
138
|
-
downcase lstrip next reverse rstrip
|
137
|
+
downcase lstrip next reverse rstrip slice squeeze strip
|
139
138
|
succ swapcase tr tr_s unicode_normalize upcase
|
140
139
|
)
|
141
140
|
|
@@ -153,12 +152,12 @@ module ActiveSupport #:nodoc:
|
|
153
152
|
|
154
153
|
def [](*args)
|
155
154
|
if html_safe?
|
156
|
-
|
155
|
+
new_safe_buffer = super
|
157
156
|
|
158
|
-
|
157
|
+
if new_safe_buffer
|
158
|
+
new_safe_buffer.instance_variable_set :@html_safe, true
|
159
|
+
end
|
159
160
|
|
160
|
-
new_safe_buffer = new_string.is_a?(SafeBuffer) ? new_string : SafeBuffer.new(new_string)
|
161
|
-
new_safe_buffer.instance_variable_set :@html_safe, true
|
162
161
|
new_safe_buffer
|
163
162
|
else
|
164
163
|
to_str[*args]
|
@@ -202,7 +201,7 @@ module ActiveSupport #:nodoc:
|
|
202
201
|
end
|
203
202
|
|
204
203
|
def []=(*args)
|
205
|
-
if args.
|
204
|
+
if args.length == 3
|
206
205
|
super(args[0], args[1], html_escape_interpolated_argument(args[2]))
|
207
206
|
else
|
208
207
|
super(args[0], html_escape_interpolated_argument(args[1]))
|
@@ -214,8 +213,7 @@ module ActiveSupport #:nodoc:
|
|
214
213
|
end
|
215
214
|
|
216
215
|
def *(*)
|
217
|
-
|
218
|
-
new_safe_buffer = new_string.is_a?(SafeBuffer) ? new_string : SafeBuffer.new(new_string)
|
216
|
+
new_safe_buffer = super
|
219
217
|
new_safe_buffer.instance_variable_set(:@html_safe, @html_safe)
|
220
218
|
new_safe_buffer
|
221
219
|
end
|
@@ -223,7 +221,7 @@ module ActiveSupport #:nodoc:
|
|
223
221
|
def %(args)
|
224
222
|
case args
|
225
223
|
when Hash
|
226
|
-
escaped_args =
|
224
|
+
escaped_args = args.transform_values { |arg| html_escape_interpolated_argument(arg) }
|
227
225
|
else
|
228
226
|
escaped_args = Array(args).map { |arg| html_escape_interpolated_argument(arg) }
|
229
227
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Symbol
|
4
|
+
def start_with?(*prefixes)
|
5
|
+
to_s.start_with?(*prefixes)
|
6
|
+
end unless method_defined?(:start_with?)
|
7
|
+
|
8
|
+
def end_with?(*suffixes)
|
9
|
+
to_s.end_with?(*suffixes)
|
10
|
+
end unless method_defined?(:end_with?)
|
11
|
+
|
12
|
+
alias :starts_with? :start_with?
|
13
|
+
alias :ends_with? :end_with?
|
14
|
+
end
|
@@ -6,6 +6,7 @@ require "active_support/time_with_zone"
|
|
6
6
|
require "active_support/core_ext/time/zones"
|
7
7
|
require "active_support/core_ext/date_and_time/calculations"
|
8
8
|
require "active_support/core_ext/date/calculations"
|
9
|
+
require "active_support/core_ext/module/remove_method"
|
9
10
|
|
10
11
|
class Time
|
11
12
|
include DateAndTime::Calculations
|
@@ -107,6 +108,21 @@ class Time
|
|
107
108
|
subsec
|
108
109
|
end
|
109
110
|
|
111
|
+
unless Time.method_defined?(:floor)
|
112
|
+
def floor(precision = 0)
|
113
|
+
change(nsec: 0) + subsec.floor(precision)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
# Restricted Ruby version due to a bug in `Time#ceil`
|
118
|
+
# See https://bugs.ruby-lang.org/issues/17025 for more details
|
119
|
+
if RUBY_VERSION <= "2.8"
|
120
|
+
remove_possible_method :ceil
|
121
|
+
def ceil(precision = 0)
|
122
|
+
change(nsec: 0) + subsec.ceil(precision)
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
110
126
|
# Returns a new Time where one or more of the elements have been changed according
|
111
127
|
# to the +options+ parameter. The time options (<tt>:hour</tt>, <tt>:min</tt>,
|
112
128
|
# <tt>:sec</tt>, <tt>:usec</tt>, <tt>:nsec</tt>) reset cascadingly, so if only
|