activesupport 5.2.3.rc1 → 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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +183 -469
- data/MIT-LICENSE +1 -1
- data/README.rdoc +1 -1
- data/lib/active_support.rb +1 -1
- data/lib/active_support/backtrace_cleaner.rb +23 -0
- data/lib/active_support/cache.rb +40 -18
- data/lib/active_support/cache/file_store.rb +19 -12
- data/lib/active_support/cache/mem_cache_store.rb +5 -0
- data/lib/active_support/cache/memory_store.rb +5 -0
- data/lib/active_support/cache/null_store.rb +5 -0
- data/lib/active_support/cache/redis_cache_store.rb +28 -4
- data/lib/active_support/callbacks.rb +16 -5
- data/lib/active_support/configurable.rb +4 -8
- data/lib/active_support/core_ext/array.rb +1 -1
- data/lib/active_support/core_ext/array/extract.rb +21 -0
- data/lib/active_support/core_ext/array/prepend_and_append.rb +2 -6
- data/lib/active_support/core_ext/class/attribute.rb +1 -1
- data/lib/active_support/core_ext/class/subclasses.rb +1 -1
- data/lib/active_support/core_ext/date/calculations.rb +6 -5
- data/lib/active_support/core_ext/date_and_time/calculations.rb +24 -17
- data/lib/active_support/core_ext/date_time/calculations.rb +1 -1
- data/lib/active_support/core_ext/enumerable.rb +71 -67
- data/lib/active_support/core_ext/hash.rb +0 -2
- data/lib/active_support/core_ext/hash/compact.rb +2 -26
- data/lib/active_support/core_ext/hash/keys.rb +0 -29
- data/lib/active_support/core_ext/hash/slice.rb +3 -25
- data/lib/active_support/core_ext/hash/transform_values.rb +2 -29
- data/lib/active_support/core_ext/integer/multiple.rb +1 -1
- data/lib/active_support/core_ext/load_error.rb +1 -1
- data/lib/active_support/core_ext/module.rb +0 -1
- data/lib/active_support/core_ext/module/attribute_accessors.rb +2 -5
- data/lib/active_support/core_ext/module/attribute_accessors_per_thread.rb +8 -14
- data/lib/active_support/core_ext/module/delegation.rb +27 -7
- data/lib/active_support/core_ext/module/introspection.rb +37 -13
- data/lib/active_support/core_ext/module/reachable.rb +1 -6
- data/lib/active_support/core_ext/module/redefine_method.rb +8 -17
- data/lib/active_support/core_ext/numeric.rb +0 -1
- data/lib/active_support/core_ext/numeric/conversions.rb +124 -128
- data/lib/active_support/core_ext/numeric/inquiry.rb +2 -25
- data/lib/active_support/core_ext/object/blank.rb +1 -2
- data/lib/active_support/core_ext/object/duplicable.rb +5 -2
- data/lib/active_support/core_ext/object/json.rb +1 -0
- data/lib/active_support/core_ext/object/try.rb +15 -7
- data/lib/active_support/core_ext/object/with_options.rb +1 -1
- data/lib/active_support/core_ext/range/compare_range.rb +1 -1
- data/lib/active_support/core_ext/range/conversions.rb +31 -29
- data/lib/active_support/core_ext/range/include_range.rb +6 -0
- data/lib/active_support/core_ext/regexp.rb +0 -4
- data/lib/active_support/core_ext/securerandom.rb +23 -3
- data/lib/active_support/core_ext/string/access.rb +8 -0
- data/lib/active_support/core_ext/string/filters.rb +41 -0
- data/lib/active_support/core_ext/string/multibyte.rb +4 -3
- data/lib/active_support/core_ext/string/output_safety.rb +16 -5
- data/lib/active_support/core_ext/string/strip.rb +3 -1
- data/lib/active_support/core_ext/uri.rb +1 -0
- data/lib/active_support/current_attributes.rb +2 -0
- data/lib/active_support/dependencies.rb +28 -11
- data/lib/active_support/deprecation.rb +1 -1
- data/lib/active_support/deprecation/behaviors.rb +1 -1
- data/lib/active_support/deprecation/method_wrappers.rb +4 -5
- data/lib/active_support/deprecation/proxy_wrappers.rb +0 -2
- data/lib/active_support/descendants_tracker.rb +6 -5
- data/lib/active_support/duration.rb +4 -2
- data/lib/active_support/duration/iso8601_parser.rb +2 -3
- data/lib/active_support/duration/iso8601_serializer.rb +3 -4
- data/lib/active_support/encrypted_configuration.rb +0 -4
- data/lib/active_support/evented_file_update_checker.rb +25 -7
- data/lib/active_support/execution_wrapper.rb +1 -0
- data/lib/active_support/gem_version.rb +4 -4
- data/lib/active_support/hash_with_indifferent_access.rb +16 -28
- data/lib/active_support/i18n.rb +1 -0
- data/lib/active_support/i18n_railtie.rb +8 -1
- data/lib/active_support/inflector/inflections.rb +1 -4
- data/lib/active_support/inflector/methods.rb +15 -27
- data/lib/active_support/inflector/transliterate.rb +6 -6
- data/lib/active_support/json/decoding.rb +23 -23
- data/lib/active_support/json/encoding.rb +6 -2
- data/lib/active_support/key_generator.rb +0 -32
- data/lib/active_support/lazy_load_hooks.rb +5 -1
- data/lib/active_support/locale/en.rb +31 -0
- data/lib/active_support/log_subscriber.rb +31 -8
- data/lib/active_support/logger.rb +0 -15
- data/lib/active_support/logger_silence.rb +28 -12
- data/lib/active_support/logger_thread_safe_level.rb +26 -4
- data/lib/active_support/message_encryptor.rb +2 -4
- data/lib/active_support/message_verifier.rb +2 -2
- data/lib/active_support/multibyte/chars.rb +29 -48
- data/lib/active_support/multibyte/unicode.rb +44 -281
- data/lib/active_support/notifications.rb +32 -4
- data/lib/active_support/notifications/fanout.rb +40 -2
- data/lib/active_support/notifications/instrumenter.rb +73 -2
- data/lib/active_support/number_helper.rb +7 -0
- data/lib/active_support/number_helper/number_to_currency_converter.rb +2 -2
- data/lib/active_support/number_helper/number_to_delimited_converter.rb +3 -1
- data/lib/active_support/number_helper/number_to_human_converter.rb +3 -1
- data/lib/active_support/number_helper/number_to_human_size_converter.rb +3 -1
- data/lib/active_support/number_helper/number_to_percentage_converter.rb +3 -1
- data/lib/active_support/number_helper/number_to_phone_converter.rb +2 -0
- data/lib/active_support/number_helper/number_to_rounded_converter.rb +5 -3
- data/lib/active_support/parameter_filter.rb +124 -0
- data/lib/active_support/rails.rb +0 -6
- data/lib/active_support/reloader.rb +4 -5
- data/lib/active_support/subscriber.rb +16 -26
- data/lib/active_support/tagged_logging.rb +13 -4
- data/lib/active_support/test_case.rb +91 -0
- data/lib/active_support/testing/assertions.rb +15 -1
- data/lib/active_support/testing/deprecation.rb +0 -1
- data/lib/active_support/testing/file_fixtures.rb +2 -0
- data/lib/active_support/testing/isolation.rb +2 -2
- data/lib/active_support/testing/method_call_assertions.rb +28 -1
- data/lib/active_support/testing/parallelization.rb +109 -0
- data/lib/active_support/testing/stream.rb +1 -1
- data/lib/active_support/testing/time_helpers.rb +7 -7
- data/lib/active_support/time_with_zone.rb +15 -5
- data/lib/active_support/values/time_zone.rb +12 -7
- data/lib/active_support/xml_mini.rb +2 -9
- data/lib/active_support/xml_mini/jdom.rb +2 -2
- data/lib/active_support/xml_mini/libxml.rb +2 -2
- data/lib/active_support/xml_mini/libxmlsax.rb +4 -4
- data/lib/active_support/xml_mini/nokogiri.rb +2 -2
- data/lib/active_support/xml_mini/nokogirisax.rb +3 -3
- data/lib/active_support/xml_mini/rexml.rb +2 -2
- metadata +9 -6
- data/lib/active_support/values/unicode_tables.dat +0 -0
@@ -35,7 +35,7 @@ module ActiveSupport
|
|
35
35
|
# and the second is a library name.
|
36
36
|
#
|
37
37
|
# ActiveSupport::Deprecation.new('2.0', 'MyLibrary')
|
38
|
-
def initialize(deprecation_horizon = "6.
|
38
|
+
def initialize(deprecation_horizon = "6.1", gem_name = "Rails")
|
39
39
|
self.gem_name = gem_name
|
40
40
|
self.deprecation_horizon = deprecation_horizon
|
41
41
|
# By default, warnings are not silenced and debugging is off.
|
@@ -43,7 +43,7 @@ module ActiveSupport
|
|
43
43
|
deprecation_horizon: deprecation_horizon)
|
44
44
|
},
|
45
45
|
|
46
|
-
silence: ->(message, callstack, deprecation_horizon, gem_name) {},
|
46
|
+
silence: ->(message, callstack, deprecation_horizon, gem_name) { },
|
47
47
|
}
|
48
48
|
|
49
49
|
# Behavior module allows to determine how to display deprecation messages.
|
@@ -1,6 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "active_support/core_ext/module/aliasing"
|
4
3
|
require "active_support/core_ext/array/extract_options"
|
5
4
|
|
6
5
|
module ActiveSupport
|
@@ -61,13 +60,13 @@ module ActiveSupport
|
|
61
60
|
with_method = "#{aliased_method}_with_deprecation#{punctuation}"
|
62
61
|
without_method = "#{aliased_method}_without_deprecation#{punctuation}"
|
63
62
|
|
64
|
-
target_module.
|
63
|
+
target_module.define_method(with_method) do |*args, &block|
|
65
64
|
deprecator.deprecation_warning(method_name, options[method_name])
|
66
65
|
send(without_method, *args, &block)
|
67
66
|
end
|
68
67
|
|
69
|
-
target_module.
|
70
|
-
target_module.
|
68
|
+
target_module.alias_method(without_method, method_name)
|
69
|
+
target_module.alias_method(method_name, with_method)
|
71
70
|
|
72
71
|
case
|
73
72
|
when target_module.protected_method_defined?(without_method)
|
@@ -76,7 +75,7 @@ module ActiveSupport
|
|
76
75
|
target_module.send(:private, method_name)
|
77
76
|
end
|
78
77
|
else
|
79
|
-
mod.
|
78
|
+
mod.define_method(method_name) do |*args, &block|
|
80
79
|
deprecator.deprecation_warning(method_name, options[method_name])
|
81
80
|
super(*args, &block)
|
82
81
|
end
|
@@ -38,12 +38,13 @@ module ActiveSupport
|
|
38
38
|
end
|
39
39
|
|
40
40
|
private
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
41
|
+
|
42
|
+
def accumulate_descendants(klass, acc)
|
43
|
+
if direct_descendants = @@direct_descendants[klass]
|
44
|
+
acc.concat(direct_descendants)
|
45
|
+
direct_descendants.each { |direct_descendant| accumulate_descendants(direct_descendant, acc) }
|
46
|
+
end
|
45
47
|
end
|
46
|
-
end
|
47
48
|
end
|
48
49
|
|
49
50
|
def inherited(base)
|
@@ -214,8 +214,11 @@ module ActiveSupport
|
|
214
214
|
end
|
215
215
|
|
216
216
|
def coerce(other) #:nodoc:
|
217
|
-
|
217
|
+
case other
|
218
|
+
when Scalar
|
218
219
|
[other, self]
|
220
|
+
when Duration
|
221
|
+
[Scalar.new(other.value), self]
|
219
222
|
else
|
220
223
|
[Scalar.new(other), self]
|
221
224
|
end
|
@@ -373,7 +376,6 @@ module ActiveSupport
|
|
373
376
|
return "0 seconds" if parts.empty?
|
374
377
|
|
375
378
|
parts.
|
376
|
-
reduce(::Hash.new(0)) { |h, (l, r)| h[l] += r; h }.
|
377
379
|
sort_by { |unit, _ | PARTS.index(unit) }.
|
378
380
|
map { |unit, val| "#{val} #{val == 1 ? unit.to_s.chop : unit.to_s}" }.
|
379
381
|
to_sentence(locale: ::I18n.default_locale)
|
@@ -1,7 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "strscan"
|
4
|
-
require "active_support/core_ext/regexp"
|
5
4
|
|
6
5
|
module ActiveSupport
|
7
6
|
class Duration
|
@@ -14,8 +13,8 @@ module ActiveSupport
|
|
14
13
|
class ParsingError < ::ArgumentError; end
|
15
14
|
|
16
15
|
PERIOD_OR_COMMA = /\.|,/
|
17
|
-
PERIOD = "."
|
18
|
-
COMMA = ","
|
16
|
+
PERIOD = "."
|
17
|
+
COMMA = ","
|
19
18
|
|
20
19
|
SIGN_MARKER = /\A\-|\+|/
|
21
20
|
DATE_MARKER = /P/
|
@@ -1,7 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "active_support/core_ext/object/blank"
|
4
|
-
require "active_support/core_ext/hash/transform_values"
|
5
4
|
|
6
5
|
module ActiveSupport
|
7
6
|
class Duration
|
@@ -15,14 +14,14 @@ module ActiveSupport
|
|
15
14
|
# Builds and returns output string.
|
16
15
|
def serialize
|
17
16
|
parts, sign = normalize
|
18
|
-
return "PT0S"
|
17
|
+
return "PT0S" if parts.empty?
|
19
18
|
|
20
|
-
output = "P"
|
19
|
+
output = +"P"
|
21
20
|
output << "#{parts[:years]}Y" if parts.key?(:years)
|
22
21
|
output << "#{parts[:months]}M" if parts.key?(:months)
|
23
22
|
output << "#{parts[:weeks]}W" if parts.key?(:weeks)
|
24
23
|
output << "#{parts[:days]}D" if parts.key?(:days)
|
25
|
-
time = ""
|
24
|
+
time = +""
|
26
25
|
time << "#{parts[:hours]}H" if parts.key?(:hours)
|
27
26
|
time << "#{parts[:minutes]}M" if parts.key?(:minutes)
|
28
27
|
if parts.key?(:seconds)
|
@@ -52,16 +52,17 @@ module ActiveSupport
|
|
52
52
|
@pid = Process.pid
|
53
53
|
@boot_mutex = Mutex.new
|
54
54
|
|
55
|
-
|
55
|
+
dtw = directories_to_watch
|
56
|
+
@dtw, @missing = dtw.partition(&:exist?)
|
57
|
+
|
58
|
+
if @dtw.any?
|
56
59
|
# Loading listen triggers warnings. These are originated by a legit
|
57
60
|
# usage of attr_* macros for private attributes, but adds a lot of noise
|
58
61
|
# to our test suite. Thus, we lazy load it and disable warnings locally.
|
59
62
|
silence_warnings do
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
raise LoadError, "Could not load the 'listen' gem. Add `gem 'listen'` to the development group of your Gemfile", e.backtrace
|
64
|
-
end
|
63
|
+
require "listen"
|
64
|
+
rescue LoadError => e
|
65
|
+
raise LoadError, "Could not load the 'listen' gem. Add `gem 'listen'` to the development group of your Gemfile", e.backtrace
|
65
66
|
end
|
66
67
|
end
|
67
68
|
boot!
|
@@ -75,6 +76,19 @@ module ActiveSupport
|
|
75
76
|
@updated.make_true
|
76
77
|
end
|
77
78
|
end
|
79
|
+
|
80
|
+
if @missing.any?(&:exist?)
|
81
|
+
@boot_mutex.synchronize do
|
82
|
+
appeared, @missing = @missing.partition(&:exist?)
|
83
|
+
shutdown!
|
84
|
+
|
85
|
+
@dtw += appeared
|
86
|
+
boot!
|
87
|
+
|
88
|
+
@updated.make_true
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
78
92
|
@updated.true?
|
79
93
|
end
|
80
94
|
|
@@ -96,6 +110,10 @@ module ActiveSupport
|
|
96
110
|
Listen.to(*@dtw, &method(:changed)).start
|
97
111
|
end
|
98
112
|
|
113
|
+
def shutdown!
|
114
|
+
Listen.stop
|
115
|
+
end
|
116
|
+
|
99
117
|
def changed(modified, added, removed)
|
100
118
|
unless updated?
|
101
119
|
@updated.make_true if (modified + added + removed).any? { |f| watching?(f) }
|
@@ -123,7 +141,7 @@ module ActiveSupport
|
|
123
141
|
end
|
124
142
|
|
125
143
|
def directories_to_watch
|
126
|
-
dtw =
|
144
|
+
dtw = @files.map(&:dirname) + @dirs.keys
|
127
145
|
dtw.compact!
|
128
146
|
dtw.uniq!
|
129
147
|
|
@@ -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
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
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
|
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
|
data/lib/active_support/i18n.rb
CHANGED
@@ -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
|
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!("/"
|
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("::"
|
95
|
-
word.gsub!(inflections.acronyms_underscore_regex) { "#{$1 && '_'
|
96
|
-
word.gsub!(/([A-Z\d]+)([A-Z][a-z])/, '\1_\2'
|
97
|
-
word.gsub!(/([a-z\d])([A-Z])/, '\1_\2'
|
98
|
-
word.tr!("-"
|
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_+/, ""
|
133
|
+
result.sub!(/\A_+/, "")
|
135
134
|
unless keep_id_suffix
|
136
|
-
result.sub!(/_id\z/, ""
|
135
|
+
result.sub!(/_id\z/, "")
|
137
136
|
end
|
138
|
-
result.tr!("_"
|
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(/.*\./, ""
|
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("_"
|
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("::"
|
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
|
-
|
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
|
-
"
|
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("::"
|
369
|
+
parts = camel_cased_word.split("::")
|
382
370
|
|
383
371
|
return Regexp.escape(camel_cased_word) if parts.blank?
|
384
372
|
|