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
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "fileutils"
|
2
2
|
|
3
3
|
class File
|
4
4
|
# Write to a file atomically. Useful for situations where you don't
|
@@ -17,7 +17,7 @@ class File
|
|
17
17
|
# file.write('hello')
|
18
18
|
# end
|
19
19
|
def self.atomic_write(file_name, temp_dir = dirname(file_name))
|
20
|
-
require
|
20
|
+
require "tempfile" unless defined?(Tempfile)
|
21
21
|
|
22
22
|
Tempfile.open(".#{basename(file_name)}", temp_dir) do |temp_file|
|
23
23
|
temp_file.binmode
|
@@ -53,11 +53,11 @@ class File
|
|
53
53
|
# Private utility method.
|
54
54
|
def self.probe_stat_in(dir) #:nodoc:
|
55
55
|
basename = [
|
56
|
-
|
56
|
+
".permissions_check",
|
57
57
|
Thread.current.object_id,
|
58
58
|
Process.pid,
|
59
59
|
rand(1000000)
|
60
|
-
].join(
|
60
|
+
].join(".")
|
61
61
|
|
62
62
|
file_name = join(dir, basename)
|
63
63
|
FileUtils.touch(file_name)
|
@@ -1,9 +1,9 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
9
|
-
require
|
1
|
+
require "active_support/core_ext/hash/compact"
|
2
|
+
require "active_support/core_ext/hash/conversions"
|
3
|
+
require "active_support/core_ext/hash/deep_merge"
|
4
|
+
require "active_support/core_ext/hash/except"
|
5
|
+
require "active_support/core_ext/hash/indifferent_access"
|
6
|
+
require "active_support/core_ext/hash/keys"
|
7
|
+
require "active_support/core_ext/hash/reverse_merge"
|
8
|
+
require "active_support/core_ext/hash/slice"
|
9
|
+
require "active_support/core_ext/hash/transform_values"
|
@@ -2,23 +2,26 @@ class Hash
|
|
2
2
|
unless Hash.instance_methods(false).include?(:compact)
|
3
3
|
# Returns a hash with non +nil+ values.
|
4
4
|
#
|
5
|
-
# hash = { a: true, b: false, c: nil}
|
6
|
-
# hash.compact
|
7
|
-
# hash
|
8
|
-
# { c: nil }.compact
|
5
|
+
# hash = { a: true, b: false, c: nil }
|
6
|
+
# hash.compact # => { a: true, b: false }
|
7
|
+
# hash # => { a: true, b: false, c: nil }
|
8
|
+
# { c: nil }.compact # => {}
|
9
|
+
# { c: true }.compact # => { c: true }
|
9
10
|
def compact
|
10
|
-
|
11
|
+
select { |_, value| !value.nil? }
|
11
12
|
end
|
12
13
|
end
|
13
14
|
|
14
15
|
unless Hash.instance_methods(false).include?(:compact!)
|
15
16
|
# Replaces current hash with non +nil+ values.
|
17
|
+
# Returns +nil+ if no changes were made, otherwise returns the hash.
|
16
18
|
#
|
17
|
-
# hash = { a: true, b: false, c: nil}
|
18
|
-
# hash.compact!
|
19
|
-
# hash
|
19
|
+
# hash = { a: true, b: false, c: nil }
|
20
|
+
# hash.compact! # => { a: true, b: false }
|
21
|
+
# hash # => { a: true, b: false }
|
22
|
+
# { c: true }.compact! # => nil
|
20
23
|
def compact!
|
21
|
-
|
24
|
+
reject! { |_, value| value.nil? }
|
22
25
|
end
|
23
26
|
end
|
24
27
|
end
|
@@ -1,11 +1,11 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
1
|
+
require "active_support/xml_mini"
|
2
|
+
require "active_support/time"
|
3
|
+
require "active_support/core_ext/object/blank"
|
4
|
+
require "active_support/core_ext/object/to_param"
|
5
|
+
require "active_support/core_ext/object/to_query"
|
6
|
+
require "active_support/core_ext/array/wrap"
|
7
|
+
require "active_support/core_ext/hash/reverse_merge"
|
8
|
+
require "active_support/core_ext/string/inflections"
|
9
9
|
|
10
10
|
class Hash
|
11
11
|
# Returns a string containing an XML representation of its receiver:
|
@@ -71,11 +71,11 @@ class Hash
|
|
71
71
|
# configure your own builder with the <tt>:builder</tt> option. The method also accepts
|
72
72
|
# options like <tt>:dasherize</tt> and friends, they are forwarded to the builder.
|
73
73
|
def to_xml(options = {})
|
74
|
-
require
|
74
|
+
require "active_support/builder" unless defined?(Builder)
|
75
75
|
|
76
76
|
options = options.dup
|
77
77
|
options[:indent] ||= 2
|
78
|
-
options[:root] ||=
|
78
|
+
options[:root] ||= "hash"
|
79
79
|
options[:builder] ||= Builder::XmlMarkup.new(indent: options[:indent])
|
80
80
|
|
81
81
|
builder = options[:builder]
|
@@ -159,36 +159,36 @@ module ActiveSupport
|
|
159
159
|
private
|
160
160
|
def normalize_keys(params)
|
161
161
|
case params
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
162
|
+
when Hash
|
163
|
+
Hash[params.map { |k, v| [k.to_s.tr("-", "_"), normalize_keys(v)] } ]
|
164
|
+
when Array
|
165
|
+
params.map { |v| normalize_keys(v) }
|
166
166
|
else
|
167
|
-
|
167
|
+
params
|
168
168
|
end
|
169
169
|
end
|
170
170
|
|
171
171
|
def deep_to_h(value)
|
172
172
|
case value
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
173
|
+
when Hash
|
174
|
+
process_hash(value)
|
175
|
+
when Array
|
176
|
+
process_array(value)
|
177
|
+
when String
|
178
|
+
value
|
179
179
|
else
|
180
|
-
|
180
|
+
raise "can't typecast #{value.class.name} - #{value.inspect}"
|
181
181
|
end
|
182
182
|
end
|
183
183
|
|
184
184
|
def process_hash(value)
|
185
|
-
if value.include?(
|
186
|
-
raise DisallowedType, value[
|
185
|
+
if value.include?("type") && !value["type"].is_a?(Hash) && @disallowed_types.include?(value["type"])
|
186
|
+
raise DisallowedType, value["type"]
|
187
187
|
end
|
188
188
|
|
189
189
|
if become_array?(value)
|
190
|
-
_, entries = Array.wrap(value.detect { |k,v| not v.is_a?(String) })
|
191
|
-
if entries.nil? || value[
|
190
|
+
_, entries = Array.wrap(value.detect { |k, v| not v.is_a?(String) })
|
191
|
+
if entries.nil? || value["__content__"].try(:empty?)
|
192
192
|
[]
|
193
193
|
else
|
194
194
|
case entries
|
@@ -204,28 +204,28 @@ module ActiveSupport
|
|
204
204
|
process_content(value)
|
205
205
|
|
206
206
|
elsif become_empty_string?(value)
|
207
|
-
|
207
|
+
""
|
208
208
|
elsif become_hash?(value)
|
209
|
-
xml_value = Hash[value.map { |k,v| [k, deep_to_h(v)] }]
|
209
|
+
xml_value = Hash[value.map { |k, v| [k, deep_to_h(v)] }]
|
210
210
|
|
211
211
|
# Turn { files: { file: #<StringIO> } } into { files: #<StringIO> } so it is compatible with
|
212
212
|
# how multipart uploaded files from HTML appear
|
213
|
-
xml_value[
|
213
|
+
xml_value["file"].is_a?(StringIO) ? xml_value["file"] : xml_value
|
214
214
|
end
|
215
215
|
end
|
216
216
|
|
217
217
|
def become_content?(value)
|
218
|
-
value[
|
218
|
+
value["type"] == "file" || (value["__content__"] && (value.keys.size == 1 || value["__content__"].present?))
|
219
219
|
end
|
220
220
|
|
221
221
|
def become_array?(value)
|
222
|
-
value[
|
222
|
+
value["type"] == "array"
|
223
223
|
end
|
224
224
|
|
225
225
|
def become_empty_string?(value)
|
226
226
|
# { "string" => true }
|
227
227
|
# No tests fail when the second term is removed.
|
228
|
-
value[
|
228
|
+
value["type"] == "string" && value["nil"] != "true"
|
229
229
|
end
|
230
230
|
|
231
231
|
def become_hash?(value)
|
@@ -234,19 +234,19 @@ module ActiveSupport
|
|
234
234
|
|
235
235
|
def nothing?(value)
|
236
236
|
# blank or nil parsed values are represented by nil
|
237
|
-
value.blank? || value[
|
237
|
+
value.blank? || value["nil"] == "true"
|
238
238
|
end
|
239
239
|
|
240
240
|
def garbage?(value)
|
241
241
|
# If the type is the only element which makes it then
|
242
242
|
# this still makes the value nil, except if type is
|
243
243
|
# an XML node(where type['value'] is a Hash)
|
244
|
-
value[
|
244
|
+
value["type"] && !value["type"].is_a?(::Hash) && value.size == 1
|
245
245
|
end
|
246
246
|
|
247
247
|
def process_content(value)
|
248
|
-
content = value[
|
249
|
-
if parser = ActiveSupport::XmlMini::PARSING[value[
|
248
|
+
content = value["__content__"]
|
249
|
+
if parser = ActiveSupport::XmlMini::PARSING[value["type"]]
|
250
250
|
parser.arity == 1 ? parser.call(content) : parser.call(content, value)
|
251
251
|
else
|
252
252
|
content
|
@@ -257,6 +257,5 @@ module ActiveSupport
|
|
257
257
|
value.map! { |i| deep_to_h(i) }
|
258
258
|
value.length > 1 ? value : value.first
|
259
259
|
end
|
260
|
-
|
261
260
|
end
|
262
261
|
end
|
@@ -52,14 +52,14 @@ class Hash
|
|
52
52
|
# hash.symbolize_keys
|
53
53
|
# # => {:name=>"Rob", :age=>"28"}
|
54
54
|
def symbolize_keys
|
55
|
-
transform_keys{ |key| key.to_sym rescue key }
|
55
|
+
transform_keys { |key| key.to_sym rescue key }
|
56
56
|
end
|
57
57
|
alias_method :to_options, :symbolize_keys
|
58
58
|
|
59
59
|
# Destructively converts all keys to symbols, as long as they respond
|
60
60
|
# to +to_sym+. Same as +symbolize_keys+, but modifies +self+.
|
61
61
|
def symbolize_keys!
|
62
|
-
transform_keys!{ |key| key.to_sym rescue key }
|
62
|
+
transform_keys! { |key| key.to_sym rescue key }
|
63
63
|
end
|
64
64
|
alias_method :to_options!, :symbolize_keys!
|
65
65
|
|
@@ -128,14 +128,14 @@ class Hash
|
|
128
128
|
# hash.deep_symbolize_keys
|
129
129
|
# # => {:person=>{:name=>"Rob", :age=>"28"}}
|
130
130
|
def deep_symbolize_keys
|
131
|
-
deep_transform_keys{ |key| key.to_sym rescue key }
|
131
|
+
deep_transform_keys { |key| key.to_sym rescue key }
|
132
132
|
end
|
133
133
|
|
134
134
|
# Destructively converts all keys to symbols, as long as they respond
|
135
135
|
# to +to_sym+. This includes the keys from the root hash and from all
|
136
136
|
# nested hashes and arrays.
|
137
137
|
def deep_symbolize_keys!
|
138
|
-
deep_transform_keys!{ |key| key.to_sym rescue key }
|
138
|
+
deep_transform_keys! { |key| key.to_sym rescue key }
|
139
139
|
end
|
140
140
|
|
141
141
|
private
|
@@ -147,7 +147,7 @@ class Hash
|
|
147
147
|
result[yield(key)] = _deep_transform_keys_in_object(value, &block)
|
148
148
|
end
|
149
149
|
when Array
|
150
|
-
object.map {|e| _deep_transform_keys_in_object(e, &block) }
|
150
|
+
object.map { |e| _deep_transform_keys_in_object(e, &block) }
|
151
151
|
else
|
152
152
|
object
|
153
153
|
end
|
@@ -162,7 +162,7 @@ class Hash
|
|
162
162
|
end
|
163
163
|
object
|
164
164
|
when Array
|
165
|
-
object.map! {|e| _deep_transform_keys_in_object!(e, &block)}
|
165
|
+
object.map! { |e| _deep_transform_keys_in_object!(e, &block) }
|
166
166
|
else
|
167
167
|
object
|
168
168
|
end
|
@@ -16,7 +16,7 @@ class Hash
|
|
16
16
|
# Destructive +reverse_merge+.
|
17
17
|
def reverse_merge!(other_hash)
|
18
18
|
# right wins if there is no left
|
19
|
-
merge!(
|
19
|
+
merge!(other_hash) { |key, left, right| left }
|
20
20
|
end
|
21
21
|
alias_method :reverse_update, :reverse_merge!
|
22
22
|
end
|
@@ -1,11 +1,11 @@
|
|
1
1
|
class Hash
|
2
|
-
# Slices a hash to include only the given keys. Returns a hash containing
|
2
|
+
# Slices a hash to include only the given keys. Returns a hash containing
|
3
3
|
# the given keys.
|
4
|
-
#
|
4
|
+
#
|
5
5
|
# { a: 1, b: 2, c: 3, d: 4 }.slice(:a, :b)
|
6
6
|
# # => {:a=>1, :b=>2}
|
7
|
-
#
|
8
|
-
# This is useful for limiting an options hash to valid keys before
|
7
|
+
#
|
8
|
+
# This is useful for limiting an options hash to valid keys before
|
9
9
|
# passing to a method:
|
10
10
|
#
|
11
11
|
# def search(criteria = {})
|
@@ -1,3 +1,3 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require "active_support/core_ext/integer/multiple"
|
2
|
+
require "active_support/core_ext/integer/inflections"
|
3
|
+
require "active_support/core_ext/integer/time"
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
1
|
+
require "active_support/core_ext/kernel/agnostics"
|
2
|
+
require "active_support/core_ext/kernel/concern"
|
3
|
+
require "active_support/core_ext/kernel/reporting"
|
4
|
+
require "active_support/core_ext/kernel/singleton_class"
|
@@ -1,6 +1,3 @@
|
|
1
|
-
require "active_support/deprecation"
|
2
|
-
require "active_support/deprecation/proxy_wrappers"
|
3
|
-
|
4
1
|
class LoadError
|
5
2
|
REGEXPS = [
|
6
3
|
/^no such file to load -- (.+)$/i,
|
@@ -9,23 +6,9 @@ class LoadError
|
|
9
6
|
/^cannot load such file -- (.+)$/i,
|
10
7
|
]
|
11
8
|
|
12
|
-
unless method_defined?(:path)
|
13
|
-
# Returns the path which was unable to be loaded.
|
14
|
-
def path
|
15
|
-
@path ||= begin
|
16
|
-
REGEXPS.find do |regex|
|
17
|
-
message =~ regex
|
18
|
-
end
|
19
|
-
$1
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
9
|
# Returns true if the given path name (except perhaps for the ".rb"
|
25
10
|
# extension) is the missing file which caused the exception to be raised.
|
26
11
|
def is_missing?(location)
|
27
|
-
location.sub(/\.rb$/,
|
12
|
+
location.sub(/\.rb$/, "".freeze) == path.sub(/\.rb$/, "".freeze)
|
28
13
|
end
|
29
14
|
end
|
30
|
-
|
31
|
-
MissingSourceFile = ActiveSupport::Deprecation::DeprecatedConstantProxy.new('MissingSourceFile', 'LoadError')
|
@@ -1,12 +1,11 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
9
|
-
require
|
10
|
-
require
|
11
|
-
require
|
12
|
-
require 'active_support/core_ext/module/qualified_const'
|
1
|
+
require "active_support/core_ext/module/aliasing"
|
2
|
+
require "active_support/core_ext/module/introspection"
|
3
|
+
require "active_support/core_ext/module/anonymous"
|
4
|
+
require "active_support/core_ext/module/reachable"
|
5
|
+
require "active_support/core_ext/module/attribute_accessors"
|
6
|
+
require "active_support/core_ext/module/attribute_accessors_per_thread"
|
7
|
+
require "active_support/core_ext/module/attr_internal"
|
8
|
+
require "active_support/core_ext/module/concerning"
|
9
|
+
require "active_support/core_ext/module/delegation"
|
10
|
+
require "active_support/core_ext/module/deprecation"
|
11
|
+
require "active_support/core_ext/module/remove_method"
|
@@ -1,52 +1,4 @@
|
|
1
1
|
class Module
|
2
|
-
# NOTE: This method is deprecated. Please use <tt>Module#prepend</tt> that
|
3
|
-
# comes with Ruby 2.0 or newer instead.
|
4
|
-
#
|
5
|
-
# Encapsulates the common pattern of:
|
6
|
-
#
|
7
|
-
# alias_method :foo_without_feature, :foo
|
8
|
-
# alias_method :foo, :foo_with_feature
|
9
|
-
#
|
10
|
-
# With this, you simply do:
|
11
|
-
#
|
12
|
-
# alias_method_chain :foo, :feature
|
13
|
-
#
|
14
|
-
# And both aliases are set up for you.
|
15
|
-
#
|
16
|
-
# Query and bang methods (foo?, foo!) keep the same punctuation:
|
17
|
-
#
|
18
|
-
# alias_method_chain :foo?, :feature
|
19
|
-
#
|
20
|
-
# is equivalent to
|
21
|
-
#
|
22
|
-
# alias_method :foo_without_feature?, :foo?
|
23
|
-
# alias_method :foo?, :foo_with_feature?
|
24
|
-
#
|
25
|
-
# so you can safely chain foo, foo?, foo! and/or foo= with the same feature.
|
26
|
-
def alias_method_chain(target, feature)
|
27
|
-
ActiveSupport::Deprecation.warn("alias_method_chain is deprecated. Please, use Module#prepend instead. From module, you can access the original method using super.")
|
28
|
-
|
29
|
-
# Strip out punctuation on predicates, bang or writer methods since
|
30
|
-
# e.g. target?_without_feature is not a valid method name.
|
31
|
-
aliased_target, punctuation = target.to_s.sub(/([?!=])$/, ''), $1
|
32
|
-
yield(aliased_target, punctuation) if block_given?
|
33
|
-
|
34
|
-
with_method = "#{aliased_target}_with_#{feature}#{punctuation}"
|
35
|
-
without_method = "#{aliased_target}_without_#{feature}#{punctuation}"
|
36
|
-
|
37
|
-
alias_method without_method, target
|
38
|
-
alias_method target, with_method
|
39
|
-
|
40
|
-
case
|
41
|
-
when public_method_defined?(without_method)
|
42
|
-
public target
|
43
|
-
when protected_method_defined?(without_method)
|
44
|
-
protected target
|
45
|
-
when private_method_defined?(without_method)
|
46
|
-
private target
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
2
|
# Allows you to make aliases for attributes, which includes
|
51
3
|
# getter, setter, and a predicate.
|
52
4
|
#
|
@@ -65,6 +17,9 @@ class Module
|
|
65
17
|
# e.subject = "Megastars"
|
66
18
|
# e.title # => "Megastars"
|
67
19
|
def alias_attribute(new_name, old_name)
|
20
|
+
# The following reader methods use an explicit `self` receiver in order to
|
21
|
+
# support aliases that start with an uppercase letter. Otherwise, they would
|
22
|
+
# be resolved as constants instead.
|
68
23
|
module_eval <<-STR, __FILE__, __LINE__ + 1
|
69
24
|
def #{new_name}; self.#{old_name}; end # def subject; self.title; end
|
70
25
|
def #{new_name}?; self.#{old_name}?; end # def subject?; self.title?; end
|