activesupport 5.0.7.2 → 5.1.7
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 +464 -694
- data/MIT-LICENSE +1 -1
- data/README.rdoc +1 -1
- data/lib/active_support.rb +8 -4
- data/lib/active_support/all.rb +3 -3
- data/lib/active_support/array_inquirer.rb +7 -5
- data/lib/active_support/backtrace_cleaner.rb +4 -4
- data/lib/active_support/benchmarkable.rb +3 -3
- data/lib/active_support/builder.rb +1 -1
- data/lib/active_support/cache.rb +41 -48
- data/lib/active_support/cache/file_store.rb +11 -20
- data/lib/active_support/cache/mem_cache_store.rb +30 -40
- data/lib/active_support/cache/memory_store.rb +13 -13
- data/lib/active_support/cache/null_store.rb +4 -4
- data/lib/active_support/cache/strategy/local_cache.rb +13 -22
- data/lib/active_support/cache/strategy/local_cache_middleware.rb +4 -5
- data/lib/active_support/callbacks.rb +649 -584
- data/lib/active_support/concurrency/load_interlock_aware_monitor.rb +17 -0
- data/lib/active_support/concurrency/share_lock.rb +20 -21
- data/lib/active_support/configurable.rb +5 -5
- data/lib/active_support/core_ext.rb +1 -2
- data/lib/active_support/core_ext/array.rb +7 -7
- data/lib/active_support/core_ext/array/access.rb +1 -1
- data/lib/active_support/core_ext/array/conversions.rb +15 -15
- data/lib/active_support/core_ext/array/grouping.rb +1 -1
- data/lib/active_support/core_ext/array/inquiry.rb +1 -1
- data/lib/active_support/core_ext/array/prepend_and_append.rb +1 -1
- data/lib/active_support/core_ext/benchmark.rb +1 -1
- data/lib/active_support/core_ext/big_decimal.rb +1 -1
- data/lib/active_support/core_ext/big_decimal/conversions.rb +4 -6
- data/lib/active_support/core_ext/class.rb +2 -2
- data/lib/active_support/core_ext/class/attribute.rb +5 -5
- data/lib/active_support/core_ext/class/attribute_accessors.rb +1 -1
- data/lib/active_support/core_ext/class/subclasses.rb +18 -4
- data/lib/active_support/core_ext/date.rb +5 -5
- data/lib/active_support/core_ext/date/acts_like.rb +1 -1
- data/lib/active_support/core_ext/date/blank.rb +1 -1
- data/lib/active_support/core_ext/date/calculations.rb +8 -8
- data/lib/active_support/core_ext/date/conversions.rb +12 -12
- data/lib/active_support/core_ext/date/zones.rb +2 -2
- data/lib/active_support/core_ext/date_and_time/calculations.rb +27 -22
- data/lib/active_support/core_ext/date_and_time/compatibility.rb +1 -1
- data/lib/active_support/core_ext/date_and_time/zones.rb +7 -8
- data/lib/active_support/core_ext/date_time.rb +5 -5
- data/lib/active_support/core_ext/date_time/acts_like.rb +2 -2
- data/lib/active_support/core_ext/date_time/blank.rb +1 -1
- data/lib/active_support/core_ext/date_time/calculations.rb +20 -10
- data/lib/active_support/core_ext/date_time/compatibility.rb +2 -2
- data/lib/active_support/core_ext/date_time/conversions.rb +12 -12
- data/lib/active_support/core_ext/digest/uuid.rb +4 -4
- data/lib/active_support/core_ext/enumerable.rb +23 -12
- data/lib/active_support/core_ext/file.rb +1 -1
- data/lib/active_support/core_ext/file/atomic.rb +4 -4
- data/lib/active_support/core_ext/hash.rb +9 -9
- data/lib/active_support/core_ext/hash/compact.rb +12 -9
- data/lib/active_support/core_ext/hash/conversions.rb +36 -37
- data/lib/active_support/core_ext/hash/indifferent_access.rb +1 -2
- data/lib/active_support/core_ext/hash/keys.rb +6 -6
- data/lib/active_support/core_ext/hash/reverse_merge.rb +1 -1
- data/lib/active_support/core_ext/hash/slice.rb +4 -4
- data/lib/active_support/core_ext/hash/transform_values.rb +1 -0
- data/lib/active_support/core_ext/integer.rb +3 -3
- data/lib/active_support/core_ext/integer/inflections.rb +1 -1
- data/lib/active_support/core_ext/integer/time.rb +2 -2
- data/lib/active_support/core_ext/kernel.rb +4 -4
- data/lib/active_support/core_ext/kernel/concern.rb +1 -1
- data/lib/active_support/core_ext/kernel/reporting.rb +1 -1
- data/lib/active_support/core_ext/load_error.rb +1 -18
- data/lib/active_support/core_ext/module.rb +11 -12
- data/lib/active_support/core_ext/module/aliasing.rb +3 -48
- data/lib/active_support/core_ext/module/attr_internal.rb +4 -4
- data/lib/active_support/core_ext/module/attribute_accessors.rb +11 -5
- data/lib/active_support/core_ext/module/attribute_accessors_per_thread.rb +20 -13
- data/lib/active_support/core_ext/module/concerning.rb +1 -1
- data/lib/active_support/core_ext/module/delegation.rb +85 -16
- data/lib/active_support/core_ext/module/introspection.rb +3 -11
- data/lib/active_support/core_ext/module/reachable.rb +2 -2
- data/lib/active_support/core_ext/numeric.rb +4 -4
- data/lib/active_support/core_ext/numeric/conversions.rb +3 -9
- data/lib/active_support/core_ext/numeric/inquiry.rb +21 -21
- data/lib/active_support/core_ext/numeric/time.rb +5 -5
- data/lib/active_support/core_ext/object.rb +12 -12
- data/lib/active_support/core_ext/object/blank.rb +3 -1
- data/lib/active_support/core_ext/object/conversions.rb +4 -4
- data/lib/active_support/core_ext/object/deep_dup.rb +1 -1
- data/lib/active_support/core_ext/object/duplicable.rb +34 -4
- data/lib/active_support/core_ext/object/inclusion.rb +1 -1
- data/lib/active_support/core_ext/object/json.rb +26 -12
- data/lib/active_support/core_ext/object/to_param.rb +1 -1
- data/lib/active_support/core_ext/object/to_query.rb +8 -5
- data/lib/active_support/core_ext/object/try.rb +1 -1
- data/lib/active_support/core_ext/object/with_options.rb +12 -1
- data/lib/active_support/core_ext/range.rb +4 -4
- data/lib/active_support/core_ext/range/conversions.rb +1 -1
- data/lib/active_support/core_ext/regexp.rb +4 -0
- data/lib/active_support/core_ext/securerandom.rb +3 -3
- data/lib/active_support/core_ext/string.rb +13 -13
- data/lib/active_support/core_ext/string/access.rb +6 -6
- data/lib/active_support/core_ext/string/conversions.rb +2 -2
- data/lib/active_support/core_ext/string/filters.rb +3 -3
- data/lib/active_support/core_ext/string/indent.rb +4 -4
- data/lib/active_support/core_ext/string/inflections.rb +10 -14
- data/lib/active_support/core_ext/string/inquiry.rb +1 -1
- data/lib/active_support/core_ext/string/multibyte.rb +1 -1
- data/lib/active_support/core_ext/string/output_safety.rb +19 -20
- data/lib/active_support/core_ext/string/strip.rb +1 -1
- data/lib/active_support/core_ext/string/zones.rb +2 -2
- data/lib/active_support/core_ext/time.rb +5 -5
- data/lib/active_support/core_ext/time/acts_like.rb +1 -1
- data/lib/active_support/core_ext/time/calculations.rb +46 -29
- data/lib/active_support/core_ext/time/conversions.rb +15 -12
- data/lib/active_support/core_ext/time/zones.rb +3 -3
- data/lib/active_support/core_ext/uri.rb +2 -2
- data/lib/active_support/dependencies.rb +45 -46
- data/lib/active_support/dependencies/interlock.rb +1 -1
- data/lib/active_support/deprecation.rb +9 -8
- data/lib/active_support/deprecation/behaviors.rb +3 -3
- data/lib/active_support/deprecation/constant_accessor.rb +50 -0
- data/lib/active_support/deprecation/instance_delegator.rb +2 -2
- data/lib/active_support/deprecation/method_wrappers.rb +10 -3
- data/lib/active_support/deprecation/proxy_wrappers.rb +6 -4
- data/lib/active_support/deprecation/reporting.rb +7 -7
- data/lib/active_support/duration.rb +221 -28
- data/lib/active_support/duration/iso8601_parser.rb +66 -65
- data/lib/active_support/duration/iso8601_serializer.rb +11 -9
- data/lib/active_support/evented_file_update_checker.rb +59 -55
- data/lib/active_support/execution_wrapper.rb +3 -3
- data/lib/active_support/executor.rb +1 -1
- data/lib/active_support/file_update_checker.rb +54 -50
- data/lib/active_support/gem_version.rb +2 -2
- data/lib/active_support/gzip.rb +4 -4
- data/lib/active_support/hash_with_indifferent_access.rb +40 -28
- data/lib/active_support/i18n.rb +5 -5
- data/lib/active_support/i18n_railtie.rb +14 -9
- data/lib/active_support/inflections.rb +11 -11
- data/lib/active_support/inflector.rb +5 -5
- data/lib/active_support/inflector/inflections.rb +11 -9
- data/lib/active_support/inflector/methods.rb +52 -51
- data/lib/active_support/inflector/transliterate.rb +8 -11
- data/lib/active_support/json.rb +2 -2
- data/lib/active_support/json/decoding.rb +3 -3
- data/lib/active_support/json/encoding.rb +8 -7
- data/lib/active_support/key_generator.rb +17 -17
- data/lib/active_support/lazy_load_hooks.rb +2 -2
- data/lib/active_support/log_subscriber.rb +9 -7
- data/lib/active_support/log_subscriber/test_helper.rb +9 -9
- data/lib/active_support/logger.rb +3 -3
- data/lib/active_support/logger_silence.rb +3 -3
- data/lib/active_support/logger_thread_safe_level.rb +1 -1
- data/lib/active_support/message_encryptor.rb +77 -35
- data/lib/active_support/message_verifier.rb +7 -7
- data/lib/active_support/multibyte.rb +2 -2
- data/lib/active_support/multibyte/chars.rb +23 -21
- data/lib/active_support/multibyte/unicode.rb +68 -89
- data/lib/active_support/notifications.rb +7 -5
- data/lib/active_support/notifications/fanout.rb +3 -3
- data/lib/active_support/notifications/instrumenter.rb +5 -5
- data/lib/active_support/number_helper.rb +5 -4
- data/lib/active_support/number_helper/number_converter.rb +11 -11
- data/lib/active_support/number_helper/number_to_currency_converter.rb +3 -3
- data/lib/active_support/number_helper/number_to_delimited_converter.rb +1 -2
- data/lib/active_support/number_helper/number_to_human_converter.rb +8 -10
- data/lib/active_support/number_helper/number_to_human_size_converter.rb +6 -11
- data/lib/active_support/number_helper/number_to_percentage_converter.rb +1 -1
- data/lib/active_support/number_helper/number_to_phone_converter.rb +1 -3
- data/lib/active_support/number_helper/number_to_rounded_converter.rb +12 -32
- data/lib/active_support/number_helper/rounding_helper.rb +64 -0
- data/lib/active_support/option_merger.rb +1 -1
- data/lib/active_support/ordered_hash.rb +3 -3
- data/lib/active_support/ordered_options.rb +6 -4
- data/lib/active_support/per_thread_registry.rb +5 -5
- data/lib/active_support/rails.rb +12 -6
- data/lib/active_support/railtie.rb +3 -3
- data/lib/active_support/reloader.rb +1 -1
- data/lib/active_support/rescuable.rb +6 -6
- data/lib/active_support/security_utils.rb +1 -1
- data/lib/active_support/string_inquirer.rb +8 -2
- data/lib/active_support/subscriber.rb +9 -5
- data/lib/active_support/tagged_logging.rb +4 -4
- data/lib/active_support/test_case.rb +12 -29
- data/lib/active_support/testing/assertions.rb +100 -2
- data/lib/active_support/testing/autorun.rb +2 -2
- data/lib/active_support/testing/constant_lookup.rb +0 -1
- data/lib/active_support/testing/declarative.rb +1 -1
- data/lib/active_support/testing/deprecation.rb +3 -2
- data/lib/active_support/testing/isolation.rb +15 -22
- data/lib/active_support/testing/method_call_assertions.rb +1 -1
- data/lib/active_support/testing/setup_and_teardown.rb +2 -2
- data/lib/active_support/testing/stream.rb +28 -28
- data/lib/active_support/testing/tagged_logging.rb +1 -1
- data/lib/active_support/testing/time_helpers.rb +45 -11
- data/lib/active_support/time.rb +12 -12
- data/lib/active_support/time_with_zone.rb +16 -14
- data/lib/active_support/values/time_zone.rb +100 -31
- data/lib/active_support/values/unicode_tables.dat +0 -0
- data/lib/active_support/version.rb +1 -1
- data/lib/active_support/xml_mini.rb +34 -36
- data/lib/active_support/xml_mini/jdom.rb +112 -112
- data/lib/active_support/xml_mini/libxml.rb +12 -11
- data/lib/active_support/xml_mini/libxmlsax.rb +13 -14
- data/lib/active_support/xml_mini/nokogiri.rb +10 -10
- data/lib/active_support/xml_mini/nokogirisax.rb +12 -13
- data/lib/active_support/xml_mini/rexml.rb +9 -9
- metadata +8 -9
- data/lib/active_support/concurrency/latch.rb +0 -26
- data/lib/active_support/core_ext/kernel/debugger.rb +0 -3
- data/lib/active_support/core_ext/module/method_transplanting.rb +0 -3
- data/lib/active_support/core_ext/module/qualified_const.rb +0 -70
- data/lib/active_support/core_ext/struct.rb +0 -3
- data/lib/active_support/core_ext/time/marshal.rb +0 -3
data/lib/active_support/gzip.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "zlib"
|
2
|
+
require "stringio"
|
3
3
|
|
4
4
|
module ActiveSupport
|
5
5
|
# A convenient wrapper for the zlib standard library that allows
|
@@ -9,7 +9,7 @@ module ActiveSupport
|
|
9
9
|
# # => "\x1F\x8B\b\x00o\x8D\xCDO\x00\x03K\xCE\xCF-(J-.V\xC8MU\x04\x00R>n\x83\f\x00\x00\x00"
|
10
10
|
#
|
11
11
|
# ActiveSupport::Gzip.decompress(gzip)
|
12
|
-
# # => "compress me!"
|
12
|
+
# # => "compress me!"
|
13
13
|
module Gzip
|
14
14
|
class Stream < StringIO
|
15
15
|
def initialize(*)
|
@@ -25,7 +25,7 @@ module ActiveSupport
|
|
25
25
|
end
|
26
26
|
|
27
27
|
# Compresses a string using gzip.
|
28
|
-
def self.compress(source, level=Zlib::DEFAULT_COMPRESSION, strategy=Zlib::DEFAULT_STRATEGY)
|
28
|
+
def self.compress(source, level = Zlib::DEFAULT_COMPRESSION, strategy = Zlib::DEFAULT_STRATEGY)
|
29
29
|
output = Stream.new
|
30
30
|
gz = Zlib::GzipWriter.new(output, level, strategy)
|
31
31
|
gz.write(source)
|
@@ -1,5 +1,5 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "active_support/core_ext/hash/keys"
|
2
|
+
require "active_support/core_ext/hash/reverse_merge"
|
3
3
|
|
4
4
|
module ActiveSupport
|
5
5
|
# Implements a hash where keys <tt>:foo</tt> and <tt>"foo"</tt> are considered
|
@@ -74,25 +74,6 @@ module ActiveSupport
|
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
77
|
-
def default(*args)
|
78
|
-
arg_key = args.first
|
79
|
-
|
80
|
-
if include?(key = convert_key(arg_key))
|
81
|
-
self[key]
|
82
|
-
else
|
83
|
-
super
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
def self.new_from_hash_copying_default(hash)
|
88
|
-
ActiveSupport::Deprecation.warn(<<-MSG.squish)
|
89
|
-
`ActiveSupport::HashWithIndifferentAccess.new_from_hash_copying_default`
|
90
|
-
has been deprecated, and will be removed in Rails 5.1. The behavior of
|
91
|
-
this method is now identical to the behavior of `.new`.
|
92
|
-
MSG
|
93
|
-
new(hash)
|
94
|
-
end
|
95
|
-
|
96
77
|
def self.[](*args)
|
97
78
|
new.merge!(Hash[*args])
|
98
79
|
end
|
@@ -167,7 +148,6 @@ module ActiveSupport
|
|
167
148
|
alias_method :has_key?, :key?
|
168
149
|
alias_method :member?, :key?
|
169
150
|
|
170
|
-
|
171
151
|
# Same as <tt>Hash#[]</tt> where the key passed as argument can be
|
172
152
|
# either a string or a symbol:
|
173
153
|
#
|
@@ -195,6 +175,36 @@ module ActiveSupport
|
|
195
175
|
super(convert_key(key), *extras)
|
196
176
|
end
|
197
177
|
|
178
|
+
if Hash.new.respond_to?(:dig)
|
179
|
+
# Same as <tt>Hash#dig</tt> where the key passed as argument can be
|
180
|
+
# either a string or a symbol:
|
181
|
+
#
|
182
|
+
# counters = ActiveSupport::HashWithIndifferentAccess.new
|
183
|
+
# counters[:foo] = { bar: 1 }
|
184
|
+
#
|
185
|
+
# counters.dig('foo', 'bar') # => 1
|
186
|
+
# counters.dig(:foo, :bar) # => 1
|
187
|
+
# counters.dig(:zoo) # => nil
|
188
|
+
def dig(*args)
|
189
|
+
args[0] = convert_key(args[0]) if args.size > 0
|
190
|
+
super(*args)
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
# Same as <tt>Hash#default</tt> where the key passed as argument can be
|
195
|
+
# either a string or a symbol:
|
196
|
+
#
|
197
|
+
# hash = ActiveSupport::HashWithIndifferentAccess.new(1)
|
198
|
+
# hash.default # => 1
|
199
|
+
#
|
200
|
+
# hash = ActiveSupport::HashWithIndifferentAccess.new { |hash, key| key }
|
201
|
+
# hash.default # => nil
|
202
|
+
# hash.default('foo') # => 'foo'
|
203
|
+
# hash.default(:foo) # => 'foo'
|
204
|
+
def default(*args)
|
205
|
+
super(*args.map { |arg| convert_key(arg) })
|
206
|
+
end
|
207
|
+
|
198
208
|
# Returns an array of the values at the specified indices:
|
199
209
|
#
|
200
210
|
# hash = ActiveSupport::HashWithIndifferentAccess.new
|
@@ -223,7 +233,7 @@ module ActiveSupport
|
|
223
233
|
# modify the receiver but rather returns a new hash with indifferent
|
224
234
|
# access with the result of the merge.
|
225
235
|
def merge(hash, &block)
|
226
|
-
|
236
|
+
dup.update(hash, &block)
|
227
237
|
end
|
228
238
|
|
229
239
|
# Like +merge+ but the other way around: Merges the receiver into the
|
@@ -238,7 +248,7 @@ module ActiveSupport
|
|
238
248
|
|
239
249
|
# Same semantics as +reverse_merge+ but modifies the receiver in-place.
|
240
250
|
def reverse_merge!(other_hash)
|
241
|
-
replace(reverse_merge(
|
251
|
+
replace(reverse_merge(other_hash))
|
242
252
|
end
|
243
253
|
|
244
254
|
# Replaces the contents of this hash with other_hash.
|
@@ -294,12 +304,12 @@ module ActiveSupport
|
|
294
304
|
_new_hash
|
295
305
|
end
|
296
306
|
|
297
|
-
|
298
|
-
def convert_key(key)
|
307
|
+
private
|
308
|
+
def convert_key(key) # :doc:
|
299
309
|
key.kind_of?(Symbol) ? key.to_s : key
|
300
310
|
end
|
301
311
|
|
302
|
-
def convert_value(value, options = {})
|
312
|
+
def convert_value(value, options = {}) # :doc:
|
303
313
|
if value.is_a? Hash
|
304
314
|
if options[:for] == :to_hash
|
305
315
|
value.to_hash
|
@@ -316,7 +326,7 @@ module ActiveSupport
|
|
316
326
|
end
|
317
327
|
end
|
318
328
|
|
319
|
-
def set_defaults(target)
|
329
|
+
def set_defaults(target) # :doc:
|
320
330
|
if default_proc
|
321
331
|
target.default_proc = default_proc.dup
|
322
332
|
else
|
@@ -326,4 +336,6 @@ module ActiveSupport
|
|
326
336
|
end
|
327
337
|
end
|
328
338
|
|
339
|
+
# :stopdoc:
|
340
|
+
|
329
341
|
HashWithIndifferentAccess = ActiveSupport::HashWithIndifferentAccess
|
data/lib/active_support/i18n.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require "active_support/core_ext/hash/deep_merge"
|
2
|
+
require "active_support/core_ext/hash/except"
|
3
|
+
require "active_support/core_ext/hash/slice"
|
4
4
|
begin
|
5
|
-
require
|
5
|
+
require "i18n"
|
6
6
|
rescue LoadError => e
|
7
7
|
$stderr.puts "The i18n gem is not available. Please add it to your Gemfile and run bundle install"
|
8
8
|
raise e
|
9
9
|
end
|
10
|
-
require
|
10
|
+
require "active_support/lazy_load_hooks"
|
11
11
|
|
12
12
|
ActiveSupport.run_load_hooks(:i18n)
|
13
13
|
I18n.load_path << "#{File.dirname(__FILE__)}/locale/en.yml"
|
@@ -2,6 +2,8 @@ require "active_support"
|
|
2
2
|
require "active_support/file_update_checker"
|
3
3
|
require "active_support/core_ext/array/wrap"
|
4
4
|
|
5
|
+
# :enddoc:
|
6
|
+
|
5
7
|
module I18n
|
6
8
|
class Railtie < Rails::Railtie
|
7
9
|
config.i18n = ActiveSupport::OrderedOptions.new
|
@@ -21,8 +23,6 @@ module I18n
|
|
21
23
|
I18n::Railtie.initialize_i18n(app)
|
22
24
|
end
|
23
25
|
|
24
|
-
protected
|
25
|
-
|
26
26
|
@i18n_inited = false
|
27
27
|
|
28
28
|
# Setup i18n configuration.
|
@@ -83,13 +83,18 @@ module I18n
|
|
83
83
|
def self.init_fallbacks(fallbacks)
|
84
84
|
include_fallbacks_module
|
85
85
|
|
86
|
-
args =
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
Array
|
91
|
-
|
92
|
-
|
86
|
+
args = \
|
87
|
+
case fallbacks
|
88
|
+
when ActiveSupport::OrderedOptions
|
89
|
+
[*(fallbacks[:defaults] || []) << fallbacks[:map]].compact
|
90
|
+
when Hash, Array
|
91
|
+
Array.wrap(fallbacks)
|
92
|
+
else # TrueClass
|
93
|
+
[I18n.default_locale]
|
94
|
+
end
|
95
|
+
|
96
|
+
if args.empty? || args.first.is_a?(Hash)
|
97
|
+
args.unshift I18n.default_locale
|
93
98
|
end
|
94
99
|
|
95
100
|
I18n.fallbacks = I18n::Locale::Fallbacks.new(*args)
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "active_support/inflector/inflections"
|
2
2
|
|
3
3
|
#--
|
4
4
|
# Defines the standard inflection rules. These are the starting point for
|
@@ -8,8 +8,8 @@ require 'active_support/inflector/inflections'
|
|
8
8
|
#++
|
9
9
|
module ActiveSupport
|
10
10
|
Inflector.inflections(:en) do |inflect|
|
11
|
-
inflect.plural(/$/,
|
12
|
-
inflect.plural(/s$/i,
|
11
|
+
inflect.plural(/$/, "s")
|
12
|
+
inflect.plural(/s$/i, "s")
|
13
13
|
inflect.plural(/^(ax|test)is$/i, '\1es')
|
14
14
|
inflect.plural(/(octop|vir)us$/i, '\1i')
|
15
15
|
inflect.plural(/(octop|vir)i$/i, '\1i')
|
@@ -18,7 +18,7 @@ module ActiveSupport
|
|
18
18
|
inflect.plural(/(buffal|tomat)o$/i, '\1oes')
|
19
19
|
inflect.plural(/([ti])um$/i, '\1a')
|
20
20
|
inflect.plural(/([ti])a$/i, '\1a')
|
21
|
-
inflect.plural(/sis$/i,
|
21
|
+
inflect.plural(/sis$/i, "ses")
|
22
22
|
inflect.plural(/(?:([^f])fe|([lr])f)$/i, '\1\2ves')
|
23
23
|
inflect.plural(/(hive)$/i, '\1s')
|
24
24
|
inflect.plural(/([^aeiouy]|qu)y$/i, '\1ies')
|
@@ -30,7 +30,7 @@ module ActiveSupport
|
|
30
30
|
inflect.plural(/^(oxen)$/i, '\1')
|
31
31
|
inflect.plural(/(quiz)$/i, '\1zes')
|
32
32
|
|
33
|
-
inflect.singular(/s$/i,
|
33
|
+
inflect.singular(/s$/i, "")
|
34
34
|
inflect.singular(/(ss)$/i, '\1')
|
35
35
|
inflect.singular(/(n)ews$/i, '\1ews')
|
36
36
|
inflect.singular(/([ti])a$/i, '\1um')
|
@@ -58,12 +58,12 @@ module ActiveSupport
|
|
58
58
|
inflect.singular(/(quiz)zes$/i, '\1')
|
59
59
|
inflect.singular(/(database)s$/i, '\1')
|
60
60
|
|
61
|
-
inflect.irregular(
|
62
|
-
inflect.irregular(
|
63
|
-
inflect.irregular(
|
64
|
-
inflect.irregular(
|
65
|
-
inflect.irregular(
|
66
|
-
inflect.irregular(
|
61
|
+
inflect.irregular("person", "people")
|
62
|
+
inflect.irregular("man", "men")
|
63
|
+
inflect.irregular("child", "children")
|
64
|
+
inflect.irregular("sex", "sexes")
|
65
|
+
inflect.irregular("move", "moves")
|
66
|
+
inflect.irregular("zombie", "zombies")
|
67
67
|
|
68
68
|
inflect.uncountable(%w(equipment information rice money species series fish sheep jeans police))
|
69
69
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# in case active_support/inflector is required without the rest of active_support
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
2
|
+
require "active_support/inflector/inflections"
|
3
|
+
require "active_support/inflector/transliterate"
|
4
|
+
require "active_support/inflector/methods"
|
5
5
|
|
6
|
-
require
|
7
|
-
require
|
6
|
+
require "active_support/inflections"
|
7
|
+
require "active_support/core_ext/string/inflections"
|
@@ -1,6 +1,7 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require "concurrent/map"
|
2
|
+
require "active_support/core_ext/array/prepend_and_append"
|
3
|
+
require "active_support/core_ext/regexp"
|
4
|
+
require "active_support/i18n"
|
4
5
|
|
5
6
|
module ActiveSupport
|
6
7
|
module Inflector
|
@@ -43,13 +44,14 @@ module ActiveSupport
|
|
43
44
|
end
|
44
45
|
|
45
46
|
def add(words)
|
46
|
-
|
47
|
-
|
47
|
+
words = words.flatten.map(&:downcase)
|
48
|
+
concat(words)
|
49
|
+
@regex_array += words.map { |word| to_regex(word) }
|
48
50
|
self
|
49
51
|
end
|
50
52
|
|
51
53
|
def uncountable?(str)
|
52
|
-
@regex_array.any? { |regex| regex
|
54
|
+
@regex_array.any? { |regex| regex.match? str }
|
53
55
|
end
|
54
56
|
|
55
57
|
private
|
@@ -215,10 +217,10 @@ module ActiveSupport
|
|
215
217
|
# clear :plurals
|
216
218
|
def clear(scope = :all)
|
217
219
|
case scope
|
218
|
-
|
219
|
-
|
220
|
+
when :all
|
221
|
+
@plurals, @singulars, @uncountables, @humans = [], [], Uncountables.new, []
|
220
222
|
else
|
221
|
-
|
223
|
+
instance_variable_set "@#{scope}", []
|
222
224
|
end
|
223
225
|
end
|
224
226
|
end
|
@@ -1,4 +1,5 @@
|
|
1
|
-
require
|
1
|
+
require "active_support/inflections"
|
2
|
+
require "active_support/core_ext/regexp"
|
2
3
|
|
3
4
|
module ActiveSupport
|
4
5
|
# The Inflector transforms words from singular to plural, class names to table
|
@@ -71,7 +72,7 @@ module ActiveSupport
|
|
71
72
|
string = string.sub(/^(?:#{inflections.acronym_regex}(?=\b|[A-Z_])|\w)/) { |match| match.downcase }
|
72
73
|
end
|
73
74
|
string.gsub!(/(?:_|(\/))([a-z\d]*)/i) { "#{$1}#{inflections.acronyms[$2] || $2.capitalize}" }
|
74
|
-
string.gsub!(
|
75
|
+
string.gsub!("/".freeze, "::".freeze)
|
75
76
|
string
|
76
77
|
end
|
77
78
|
|
@@ -87,8 +88,8 @@ module ActiveSupport
|
|
87
88
|
#
|
88
89
|
# camelize(underscore('SSLError')) # => "SslError"
|
89
90
|
def underscore(camel_cased_word)
|
90
|
-
return camel_cased_word unless
|
91
|
-
word = camel_cased_word.to_s.gsub(
|
91
|
+
return camel_cased_word unless /[A-Z-]|::/.match?(camel_cased_word)
|
92
|
+
word = camel_cased_word.to_s.gsub("::".freeze, "/".freeze)
|
92
93
|
word.gsub!(/(?:(?<=([A-Za-z\d]))|\b)(#{inflections.acronym_regex})(?=\b|[^a-z])/) { "#{$1 && '_'.freeze }#{$2.downcase}" }
|
93
94
|
word.gsub!(/([A-Z\d]+)([A-Z][a-z])/, '\1_\2'.freeze)
|
94
95
|
word.gsub!(/([a-z\d])([A-Z])/, '\1_\2'.freeze)
|
@@ -125,9 +126,9 @@ module ActiveSupport
|
|
125
126
|
|
126
127
|
inflections.humans.each { |(rule, replacement)| break if result.sub!(rule, replacement) }
|
127
128
|
|
128
|
-
result.sub!(/\A_+/,
|
129
|
-
result.sub!(/_id\z/,
|
130
|
-
result.tr!(
|
129
|
+
result.sub!(/\A_+/, "".freeze)
|
130
|
+
result.sub!(/_id\z/, "".freeze)
|
131
|
+
result.tr!("_".freeze, " ".freeze)
|
131
132
|
|
132
133
|
result.gsub!(/([a-z\d]*)/i) do |match|
|
133
134
|
"#{inflections.acronyms[match] || match.downcase}"
|
@@ -146,7 +147,7 @@ module ActiveSupport
|
|
146
147
|
# upcase_first('w') # => "W"
|
147
148
|
# upcase_first('') # => ""
|
148
149
|
def upcase_first(string)
|
149
|
-
string.length > 0 ? string[0].upcase.concat(string[1..-1]) :
|
150
|
+
string.length > 0 ? string[0].upcase.concat(string[1..-1]) : ""
|
150
151
|
end
|
151
152
|
|
152
153
|
# Capitalizes all the words and replaces some characters in the string to
|
@@ -160,7 +161,7 @@ module ActiveSupport
|
|
160
161
|
# titleize('TheManWithoutAPast') # => "The Man Without A Past"
|
161
162
|
# titleize('raiders_of_the_lost_ark') # => "Raiders Of The Lost Ark"
|
162
163
|
def titleize(word)
|
163
|
-
humanize(underscore(word)).gsub(/\b(
|
164
|
+
humanize(underscore(word)).gsub(/\b(?<!\w['’`])[a-z]/) { |match| match.capitalize }
|
164
165
|
end
|
165
166
|
|
166
167
|
# Creates the name of a table like Rails does for models to table names.
|
@@ -185,28 +186,28 @@ module ActiveSupport
|
|
185
186
|
# classify('calculus') # => "Calculus"
|
186
187
|
def classify(table_name)
|
187
188
|
# strip out any leading schema name
|
188
|
-
camelize(singularize(table_name.to_s.sub(/.*\./,
|
189
|
+
camelize(singularize(table_name.to_s.sub(/.*\./, "".freeze)))
|
189
190
|
end
|
190
191
|
|
191
192
|
# Replaces underscores with dashes in the string.
|
192
193
|
#
|
193
194
|
# dasherize('puni_puni') # => "puni-puni"
|
194
195
|
def dasherize(underscored_word)
|
195
|
-
underscored_word.tr(
|
196
|
+
underscored_word.tr("_".freeze, "-".freeze)
|
196
197
|
end
|
197
198
|
|
198
199
|
# Removes the module part from the expression in the string.
|
199
200
|
#
|
200
|
-
# demodulize('
|
201
|
-
# demodulize('Inflections')
|
202
|
-
# demodulize('::Inflections')
|
203
|
-
# demodulize('')
|
201
|
+
# demodulize('ActiveSupport::Inflector::Inflections') # => "Inflections"
|
202
|
+
# demodulize('Inflections') # => "Inflections"
|
203
|
+
# demodulize('::Inflections') # => "Inflections"
|
204
|
+
# demodulize('') # => ""
|
204
205
|
#
|
205
206
|
# See also #deconstantize.
|
206
207
|
def demodulize(path)
|
207
208
|
path = path.to_s
|
208
|
-
if i = path.rindex(
|
209
|
-
path[(i+2)..-1]
|
209
|
+
if i = path.rindex("::")
|
210
|
+
path[(i + 2)..-1]
|
210
211
|
else
|
211
212
|
path
|
212
213
|
end
|
@@ -222,7 +223,7 @@ module ActiveSupport
|
|
222
223
|
#
|
223
224
|
# See also #demodulize.
|
224
225
|
def deconstantize(path)
|
225
|
-
path.to_s[0, path.rindex(
|
226
|
+
path.to_s[0, path.rindex("::") || 0] # implementation based on the one in facets' Module#spacename
|
226
227
|
end
|
227
228
|
|
228
229
|
# Creates a foreign key name from a class name.
|
@@ -238,8 +239,8 @@ module ActiveSupport
|
|
238
239
|
|
239
240
|
# Tries to find a constant with the name specified in the argument string.
|
240
241
|
#
|
241
|
-
# 'Module'
|
242
|
-
# 'Foo::Bar'
|
242
|
+
# constantize('Module') # => Module
|
243
|
+
# constantize('Foo::Bar') # => Foo::Bar
|
243
244
|
#
|
244
245
|
# The name is assumed to be the one of a top-level constant, no matter
|
245
246
|
# whether it starts with "::" or not. No lexical context is taken into
|
@@ -248,14 +249,14 @@ module ActiveSupport
|
|
248
249
|
# C = 'outside'
|
249
250
|
# module M
|
250
251
|
# C = 'inside'
|
251
|
-
# C
|
252
|
-
# 'C'
|
252
|
+
# C # => 'inside'
|
253
|
+
# constantize('C') # => 'outside', same as ::C
|
253
254
|
# end
|
254
255
|
#
|
255
256
|
# NameError is raised when the name is not in CamelCase or the constant is
|
256
257
|
# unknown.
|
257
258
|
def constantize(camel_cased_word)
|
258
|
-
names = camel_cased_word.split(
|
259
|
+
names = camel_cased_word.split("::".freeze)
|
259
260
|
|
260
261
|
# Trigger a built-in NameError exception including the ill-formed constant in the message.
|
261
262
|
Object.const_get(camel_cased_word) if names.empty?
|
@@ -313,7 +314,7 @@ module ActiveSupport
|
|
313
314
|
raise if e.name && !(camel_cased_word.to_s.split("::").include?(e.name.to_s) ||
|
314
315
|
e.name.to_s == camel_cased_word.to_s)
|
315
316
|
rescue ArgumentError => e
|
316
|
-
raise unless
|
317
|
+
raise unless /not missing constant #{const_regexp(camel_cased_word)}!$/.match?(e.message)
|
317
318
|
end
|
318
319
|
|
319
320
|
# Returns the suffix that should be added to a number to denote the position
|
@@ -332,9 +333,9 @@ module ActiveSupport
|
|
332
333
|
"th"
|
333
334
|
else
|
334
335
|
case abs_number % 10
|
335
|
-
|
336
|
-
|
337
|
-
|
336
|
+
when 1; "st"
|
337
|
+
when 2; "nd"
|
338
|
+
when 3; "rd"
|
338
339
|
else "th"
|
339
340
|
end
|
340
341
|
end
|
@@ -355,36 +356,36 @@ module ActiveSupport
|
|
355
356
|
|
356
357
|
private
|
357
358
|
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
359
|
+
# Mounts a regular expression, returned as a string to ease interpolation,
|
360
|
+
# that will match part by part the given constant.
|
361
|
+
#
|
362
|
+
# const_regexp("Foo::Bar::Baz") # => "Foo(::Bar(::Baz)?)?"
|
363
|
+
# const_regexp("::") # => "::"
|
364
|
+
def const_regexp(camel_cased_word)
|
365
|
+
parts = camel_cased_word.split("::".freeze)
|
365
366
|
|
366
|
-
|
367
|
+
return Regexp.escape(camel_cased_word) if parts.blank?
|
367
368
|
|
368
|
-
|
369
|
+
last = parts.pop
|
369
370
|
|
370
|
-
|
371
|
-
|
371
|
+
parts.reverse.inject(last) do |acc, part|
|
372
|
+
part.empty? ? acc : "#{part}(::#{acc})?"
|
373
|
+
end
|
372
374
|
end
|
373
|
-
end
|
374
375
|
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
376
|
+
# Applies inflection rules for +singularize+ and +pluralize+.
|
377
|
+
#
|
378
|
+
# apply_inflections('post', inflections.plurals) # => "posts"
|
379
|
+
# apply_inflections('posts', inflections.singulars) # => "post"
|
380
|
+
def apply_inflections(word, rules)
|
381
|
+
result = word.to_s.dup
|
381
382
|
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
383
|
+
if word.empty? || inflections.uncountables.uncountable?(result)
|
384
|
+
result
|
385
|
+
else
|
386
|
+
rules.each { |(rule, replacement)| break if result.sub!(rule, replacement) }
|
387
|
+
result
|
388
|
+
end
|
387
389
|
end
|
388
|
-
end
|
389
390
|
end
|
390
391
|
end
|