activesupport 4.0.13 → 5.2.5
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 +5 -5
- data/CHANGELOG.md +412 -444
- data/MIT-LICENSE +2 -2
- data/README.rdoc +8 -4
- data/lib/active_support/all.rb +5 -3
- data/lib/active_support/array_inquirer.rb +48 -0
- data/lib/active_support/backtrace_cleaner.rb +14 -12
- data/lib/active_support/benchmarkable.rb +6 -14
- data/lib/active_support/builder.rb +3 -1
- data/lib/active_support/cache/file_store.rb +67 -51
- data/lib/active_support/cache/mem_cache_store.rb +95 -97
- data/lib/active_support/cache/memory_store.rb +28 -30
- data/lib/active_support/cache/null_store.rb +7 -8
- data/lib/active_support/cache/redis_cache_store.rb +466 -0
- data/lib/active_support/cache/strategy/local_cache.rb +70 -56
- data/lib/active_support/cache/strategy/local_cache_middleware.rb +45 -0
- data/lib/active_support/cache.rb +331 -206
- data/lib/active_support/callbacks.rb +697 -426
- data/lib/active_support/concern.rb +32 -10
- data/lib/active_support/concurrency/load_interlock_aware_monitor.rb +17 -0
- data/lib/active_support/concurrency/share_lock.rb +227 -0
- data/lib/active_support/configurable.rb +8 -5
- data/lib/active_support/core_ext/array/access.rb +39 -1
- data/lib/active_support/core_ext/array/conversions.rb +24 -35
- data/lib/active_support/core_ext/array/extract_options.rb +2 -0
- data/lib/active_support/core_ext/array/grouping.rb +23 -13
- data/lib/active_support/core_ext/array/inquiry.rb +19 -0
- data/lib/active_support/core_ext/array/prepend_and_append.rb +7 -5
- data/lib/active_support/core_ext/array/wrap.rb +7 -4
- data/lib/active_support/core_ext/array.rb +9 -7
- data/lib/active_support/core_ext/benchmark.rb +3 -1
- data/lib/active_support/core_ext/big_decimal/conversions.rb +9 -26
- data/lib/active_support/core_ext/big_decimal.rb +3 -1
- data/lib/active_support/core_ext/class/attribute.rb +41 -23
- data/lib/active_support/core_ext/class/attribute_accessors.rb +5 -169
- data/lib/active_support/core_ext/class/subclasses.rb +20 -8
- data/lib/active_support/core_ext/class.rb +4 -4
- data/lib/active_support/core_ext/date/acts_like.rb +3 -1
- data/lib/active_support/core_ext/date/blank.rb +14 -0
- data/lib/active_support/core_ext/date/calculations.rb +21 -9
- data/lib/active_support/core_ext/date/conversions.rb +32 -22
- data/lib/active_support/core_ext/date/zones.rb +5 -34
- data/lib/active_support/core_ext/date.rb +6 -4
- data/lib/active_support/core_ext/date_and_time/calculations.rb +199 -57
- data/lib/active_support/core_ext/date_and_time/compatibility.rb +16 -0
- data/lib/active_support/core_ext/date_and_time/zones.rb +41 -0
- data/lib/active_support/core_ext/date_time/acts_like.rb +4 -2
- data/lib/active_support/core_ext/date_time/blank.rb +14 -0
- data/lib/active_support/core_ext/date_time/calculations.rb +78 -37
- data/lib/active_support/core_ext/date_time/compatibility.rb +18 -0
- data/lib/active_support/core_ext/date_time/conversions.rb +19 -13
- data/lib/active_support/core_ext/date_time.rb +7 -4
- data/lib/active_support/core_ext/digest/uuid.rb +53 -0
- data/lib/active_support/core_ext/digest.rb +3 -0
- data/lib/active_support/core_ext/enumerable.rb +113 -29
- data/lib/active_support/core_ext/file/atomic.rb +38 -31
- data/lib/active_support/core_ext/file.rb +3 -1
- data/lib/active_support/core_ext/hash/compact.rb +29 -0
- data/lib/active_support/core_ext/hash/conversions.rb +71 -49
- data/lib/active_support/core_ext/hash/deep_merge.rb +9 -13
- data/lib/active_support/core_ext/hash/except.rb +12 -3
- data/lib/active_support/core_ext/hash/indifferent_access.rb +5 -3
- data/lib/active_support/core_ext/hash/keys.rb +50 -38
- data/lib/active_support/core_ext/hash/reverse_merge.rb +5 -2
- data/lib/active_support/core_ext/hash/slice.rb +12 -6
- data/lib/active_support/core_ext/hash/transform_values.rb +32 -0
- data/lib/active_support/core_ext/hash.rb +11 -8
- data/lib/active_support/core_ext/integer/inflections.rb +3 -1
- data/lib/active_support/core_ext/integer/multiple.rb +2 -0
- data/lib/active_support/core_ext/integer/time.rb +11 -33
- data/lib/active_support/core_ext/integer.rb +5 -3
- data/lib/active_support/core_ext/kernel/agnostics.rb +2 -0
- data/lib/active_support/core_ext/kernel/concern.rb +14 -0
- data/lib/active_support/core_ext/kernel/reporting.rb +5 -74
- data/lib/active_support/core_ext/kernel/singleton_class.rb +2 -0
- data/lib/active_support/core_ext/kernel.rb +6 -4
- data/lib/active_support/core_ext/load_error.rb +5 -21
- data/lib/active_support/core_ext/marshal.rb +13 -10
- data/lib/active_support/core_ext/module/aliasing.rb +6 -44
- data/lib/active_support/core_ext/module/anonymous.rb +12 -1
- data/lib/active_support/core_ext/module/attr_internal.rb +8 -8
- data/lib/active_support/core_ext/module/attribute_accessors.rb +170 -21
- data/lib/active_support/core_ext/module/attribute_accessors_per_thread.rb +150 -0
- data/lib/active_support/core_ext/module/concerning.rb +134 -0
- data/lib/active_support/core_ext/module/delegation.rb +135 -45
- data/lib/active_support/core_ext/module/deprecation.rb +3 -3
- data/lib/active_support/core_ext/module/introspection.rb +9 -25
- data/lib/active_support/core_ext/module/reachable.rb +5 -2
- data/lib/active_support/core_ext/module/redefine_method.rb +49 -0
- data/lib/active_support/core_ext/module/remove_method.rb +8 -3
- data/lib/active_support/core_ext/module.rb +14 -10
- data/lib/active_support/core_ext/name_error.rb +22 -2
- data/lib/active_support/core_ext/numeric/bytes.rb +22 -0
- data/lib/active_support/core_ext/numeric/conversions.rb +79 -74
- data/lib/active_support/core_ext/numeric/inquiry.rb +28 -0
- data/lib/active_support/core_ext/numeric/time.rb +37 -50
- data/lib/active_support/core_ext/numeric.rb +6 -3
- data/lib/active_support/core_ext/object/acts_like.rb +12 -1
- data/lib/active_support/core_ext/object/blank.rb +70 -19
- data/lib/active_support/core_ext/object/conversions.rb +6 -4
- data/lib/active_support/core_ext/object/deep_dup.rb +19 -10
- data/lib/active_support/core_ext/object/duplicable.rb +100 -34
- data/lib/active_support/core_ext/object/inclusion.rb +18 -15
- data/lib/active_support/core_ext/object/instance_variables.rb +3 -1
- data/lib/active_support/core_ext/object/json.rb +227 -0
- data/lib/active_support/core_ext/object/to_param.rb +3 -1
- data/lib/active_support/core_ext/object/to_query.rb +21 -8
- data/lib/active_support/core_ext/object/try.rb +94 -24
- data/lib/active_support/core_ext/object/with_options.rb +45 -5
- data/lib/active_support/core_ext/object.rb +14 -12
- data/lib/active_support/core_ext/range/compare_range.rb +61 -0
- data/lib/active_support/core_ext/range/conversions.rb +27 -7
- data/lib/active_support/core_ext/range/each.rb +19 -17
- data/lib/active_support/core_ext/range/include_range.rb +2 -22
- data/lib/active_support/core_ext/range/include_time_with_zone.rb +23 -0
- data/lib/active_support/core_ext/range/overlaps.rb +2 -0
- data/lib/active_support/core_ext/range.rb +7 -4
- data/lib/active_support/core_ext/regexp.rb +6 -0
- data/lib/active_support/core_ext/securerandom.rb +25 -0
- data/lib/active_support/core_ext/string/access.rb +41 -39
- data/lib/active_support/core_ext/string/behavior.rb +3 -1
- data/lib/active_support/core_ext/string/conversions.rb +17 -13
- data/lib/active_support/core_ext/string/exclude.rb +5 -3
- data/lib/active_support/core_ext/string/filters.rb +55 -6
- data/lib/active_support/core_ext/string/indent.rb +6 -4
- data/lib/active_support/core_ext/string/inflections.rb +66 -24
- data/lib/active_support/core_ext/string/inquiry.rb +3 -1
- data/lib/active_support/core_ext/string/multibyte.rb +15 -7
- data/lib/active_support/core_ext/string/output_safety.rb +114 -54
- data/lib/active_support/core_ext/string/starts_ends_with.rb +2 -0
- data/lib/active_support/core_ext/string/strip.rb +4 -5
- data/lib/active_support/core_ext/string/zones.rb +4 -1
- data/lib/active_support/core_ext/string.rb +15 -13
- data/lib/active_support/core_ext/time/acts_like.rb +3 -1
- data/lib/active_support/core_ext/time/calculations.rb +123 -110
- data/lib/active_support/core_ext/time/compatibility.rb +16 -0
- data/lib/active_support/core_ext/time/conversions.rb +23 -14
- data/lib/active_support/core_ext/time/zones.rb +42 -26
- data/lib/active_support/core_ext/time.rb +7 -5
- data/lib/active_support/core_ext/uri.rb +6 -8
- data/lib/active_support/core_ext.rb +3 -2
- data/lib/active_support/current_attributes.rb +195 -0
- data/lib/active_support/dependencies/autoload.rb +3 -1
- data/lib/active_support/dependencies/interlock.rb +57 -0
- data/lib/active_support/dependencies.rb +196 -166
- data/lib/active_support/deprecation/behaviors.rb +48 -15
- data/lib/active_support/deprecation/constant_accessor.rb +52 -0
- data/lib/active_support/deprecation/instance_delegator.rb +17 -2
- data/lib/active_support/deprecation/method_wrappers.rb +66 -20
- data/lib/active_support/deprecation/proxy_wrappers.rb +56 -28
- data/lib/active_support/deprecation/reporting.rb +32 -12
- data/lib/active_support/deprecation.rb +14 -11
- data/lib/active_support/descendants_tracker.rb +2 -0
- data/lib/active_support/digest.rb +20 -0
- data/lib/active_support/duration/iso8601_parser.rb +125 -0
- data/lib/active_support/duration/iso8601_serializer.rb +55 -0
- data/lib/active_support/duration.rb +354 -34
- data/lib/active_support/encrypted_configuration.rb +49 -0
- data/lib/active_support/encrypted_file.rb +99 -0
- data/lib/active_support/evented_file_update_checker.rb +205 -0
- data/lib/active_support/execution_wrapper.rb +128 -0
- data/lib/active_support/executor.rb +8 -0
- data/lib/active_support/file_update_checker.rb +63 -37
- data/lib/active_support/gem_version.rb +17 -0
- data/lib/active_support/gzip.rb +7 -5
- data/lib/active_support/hash_with_indifferent_access.rb +158 -35
- data/lib/active_support/i18n.rb +8 -6
- data/lib/active_support/i18n_railtie.rb +38 -20
- data/lib/active_support/inflections.rb +19 -12
- data/lib/active_support/inflector/inflections.rb +79 -30
- data/lib/active_support/inflector/methods.rb +197 -129
- data/lib/active_support/inflector/transliterate.rb +48 -27
- data/lib/active_support/inflector.rb +7 -5
- data/lib/active_support/json/decoding.rb +21 -25
- data/lib/active_support/json/encoding.rb +84 -292
- data/lib/active_support/json.rb +4 -2
- data/lib/active_support/key_generator.rb +26 -28
- data/lib/active_support/lazy_load_hooks.rb +51 -21
- data/lib/active_support/locale/en.yml +2 -0
- data/lib/active_support/log_subscriber/test_helper.rb +14 -12
- data/lib/active_support/log_subscriber.rb +13 -10
- data/lib/active_support/logger.rb +54 -3
- data/lib/active_support/logger_silence.rb +12 -7
- data/lib/active_support/logger_thread_safe_level.rb +34 -0
- data/lib/active_support/message_encryptor.rb +173 -50
- data/lib/active_support/message_verifier.rb +159 -22
- data/lib/active_support/messages/metadata.rb +71 -0
- data/lib/active_support/messages/rotation_configuration.rb +22 -0
- data/lib/active_support/messages/rotator.rb +56 -0
- data/lib/active_support/multibyte/chars.rb +38 -26
- data/lib/active_support/multibyte/unicode.rb +138 -146
- data/lib/active_support/multibyte.rb +4 -2
- data/lib/active_support/notifications/fanout.rb +23 -16
- data/lib/active_support/notifications/instrumenter.rb +29 -8
- data/lib/active_support/notifications.rb +22 -13
- data/lib/active_support/number_helper/number_converter.rb +184 -0
- data/lib/active_support/number_helper/number_to_currency_converter.rb +46 -0
- data/lib/active_support/number_helper/number_to_delimited_converter.rb +29 -0
- data/lib/active_support/number_helper/number_to_human_converter.rb +68 -0
- data/lib/active_support/number_helper/number_to_human_size_converter.rb +59 -0
- data/lib/active_support/number_helper/number_to_percentage_converter.rb +14 -0
- data/lib/active_support/number_helper/number_to_phone_converter.rb +58 -0
- data/lib/active_support/number_helper/number_to_rounded_converter.rb +54 -0
- data/lib/active_support/number_helper/rounding_helper.rb +66 -0
- data/lib/active_support/number_helper.rb +125 -391
- data/lib/active_support/option_merger.rb +3 -1
- data/lib/active_support/ordered_hash.rb +6 -4
- data/lib/active_support/ordered_options.rb +31 -5
- data/lib/active_support/per_thread_registry.rb +19 -11
- data/lib/active_support/proxy_object.rb +2 -0
- data/lib/active_support/rails.rb +16 -8
- data/lib/active_support/railtie.rb +43 -9
- data/lib/active_support/reloader.rb +131 -0
- data/lib/active_support/rescuable.rb +108 -53
- data/lib/active_support/security_utils.rb +31 -0
- data/lib/active_support/string_inquirer.rb +11 -3
- data/lib/active_support/subscriber.rb +54 -17
- data/lib/active_support/tagged_logging.rb +14 -11
- data/lib/active_support/test_case.rb +42 -37
- data/lib/active_support/testing/assertions.rb +126 -39
- data/lib/active_support/testing/autorun.rb +5 -3
- data/lib/active_support/testing/constant_lookup.rb +3 -6
- data/lib/active_support/testing/declarative.rb +10 -22
- data/lib/active_support/testing/deprecation.rb +14 -10
- data/lib/active_support/testing/file_fixtures.rb +36 -0
- data/lib/active_support/testing/isolation.rb +55 -86
- data/lib/active_support/testing/method_call_assertions.rb +43 -0
- data/lib/active_support/testing/setup_and_teardown.rb +30 -10
- data/lib/active_support/testing/stream.rb +44 -0
- data/lib/active_support/testing/tagged_logging.rb +5 -3
- data/lib/active_support/testing/time_helpers.rb +200 -0
- data/lib/active_support/time.rb +13 -13
- data/lib/active_support/time_with_zone.rb +223 -73
- data/lib/active_support/values/time_zone.rb +261 -126
- data/lib/active_support/values/unicode_tables.dat +0 -0
- data/lib/active_support/version.rb +6 -7
- data/lib/active_support/xml_mini/jdom.rb +116 -113
- data/lib/active_support/xml_mini/libxml.rb +17 -16
- data/lib/active_support/xml_mini/libxmlsax.rb +16 -18
- data/lib/active_support/xml_mini/nokogiri.rb +15 -15
- data/lib/active_support/xml_mini/nokogirisax.rb +15 -16
- data/lib/active_support/xml_mini/rexml.rb +17 -16
- data/lib/active_support/xml_mini.rb +69 -51
- data/lib/active_support.rb +29 -3
- metadata +84 -54
- data/lib/active_support/basic_object.rb +0 -11
- data/lib/active_support/buffered_logger.rb +0 -21
- data/lib/active_support/concurrency/latch.rb +0 -27
- data/lib/active_support/core_ext/array/uniq_by.rb +0 -19
- data/lib/active_support/core_ext/class/delegating_attributes.rb +0 -40
- data/lib/active_support/core_ext/date_time/zones.rb +0 -24
- data/lib/active_support/core_ext/hash/diff.rb +0 -14
- data/lib/active_support/core_ext/kernel/debugger.rb +0 -10
- data/lib/active_support/core_ext/logger.rb +0 -67
- data/lib/active_support/core_ext/module/qualified_const.rb +0 -52
- data/lib/active_support/core_ext/object/to_json.rb +0 -27
- data/lib/active_support/core_ext/proc.rb +0 -17
- data/lib/active_support/core_ext/string/encoding.rb +0 -8
- data/lib/active_support/core_ext/struct.rb +0 -6
- data/lib/active_support/core_ext/thread.rb +0 -79
- data/lib/active_support/core_ext/time/marshal.rb +0 -30
- data/lib/active_support/file_watcher.rb +0 -36
- data/lib/active_support/json/variable.rb +0 -18
- data/lib/active_support/testing/pending.rb +0 -14
@@ -1,11 +1,13 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "yaml"
|
2
4
|
|
3
5
|
YAML.add_builtin_type("omap") do |type, val|
|
4
|
-
ActiveSupport::OrderedHash[val.map{ |v| v.to_a.first }]
|
6
|
+
ActiveSupport::OrderedHash[val.map { |v| v.to_a.first }]
|
5
7
|
end
|
6
8
|
|
7
9
|
module ActiveSupport
|
8
|
-
# <tt>ActiveSupport::OrderedHash</tt> implements a hash that preserves
|
10
|
+
# DEPRECATED: <tt>ActiveSupport::OrderedHash</tt> implements a hash that preserves
|
9
11
|
# insertion order.
|
10
12
|
#
|
11
13
|
# oh = ActiveSupport::OrderedHash.new
|
@@ -25,7 +27,7 @@ module ActiveSupport
|
|
25
27
|
end
|
26
28
|
|
27
29
|
def encode_with(coder)
|
28
|
-
coder.represent_seq
|
30
|
+
coder.represent_seq "!omap", map { |k, v| { k => v } }
|
29
31
|
end
|
30
32
|
|
31
33
|
def select(*args, &block)
|
@@ -1,3 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_support/core_ext/object/blank"
|
4
|
+
|
1
5
|
module ActiveSupport
|
2
6
|
# Usually key value pairs are handled something like this:
|
3
7
|
#
|
@@ -6,6 +10,7 @@ module ActiveSupport
|
|
6
10
|
# h[:girl] = 'Mary'
|
7
11
|
# h[:boy] # => 'John'
|
8
12
|
# h[:girl] # => 'Mary'
|
13
|
+
# h[:dog] # => nil
|
9
14
|
#
|
10
15
|
# Using +OrderedOptions+, the above code could be reduced to:
|
11
16
|
#
|
@@ -14,6 +19,13 @@ module ActiveSupport
|
|
14
19
|
# h.girl = 'Mary'
|
15
20
|
# h.boy # => 'John'
|
16
21
|
# h.girl # => 'Mary'
|
22
|
+
# h.dog # => nil
|
23
|
+
#
|
24
|
+
# To raise an exception when the value is blank, append a
|
25
|
+
# bang to the key name, like:
|
26
|
+
#
|
27
|
+
# h.dog! # => raises KeyError: :dog is blank
|
28
|
+
#
|
17
29
|
class OrderedOptions < Hash
|
18
30
|
alias_method :_get, :[] # preserve the original #[] method
|
19
31
|
protected :_get # make it protected
|
@@ -27,11 +39,17 @@ module ActiveSupport
|
|
27
39
|
end
|
28
40
|
|
29
41
|
def method_missing(name, *args)
|
30
|
-
name_string = name.to_s
|
31
|
-
if name_string.chomp!(
|
42
|
+
name_string = name.to_s.dup
|
43
|
+
if name_string.chomp!("=")
|
32
44
|
self[name_string] = args.first
|
33
45
|
else
|
34
|
-
|
46
|
+
bangs = name_string.chomp!("!")
|
47
|
+
|
48
|
+
if bangs
|
49
|
+
self[name_string].presence || raise(KeyError.new(":#{name_string} is blank"))
|
50
|
+
else
|
51
|
+
self[name_string]
|
52
|
+
end
|
35
53
|
end
|
36
54
|
end
|
37
55
|
|
@@ -40,13 +58,21 @@ module ActiveSupport
|
|
40
58
|
end
|
41
59
|
end
|
42
60
|
|
61
|
+
# +InheritableOptions+ provides a constructor to build an +OrderedOptions+
|
62
|
+
# hash inherited from another hash.
|
63
|
+
#
|
64
|
+
# Use this if you already have some hash and you want to create a new one based on it.
|
65
|
+
#
|
66
|
+
# h = ActiveSupport::InheritableOptions.new({ girl: 'Mary', boy: 'John' })
|
67
|
+
# h.girl # => 'Mary'
|
68
|
+
# h.boy # => 'John'
|
43
69
|
class InheritableOptions < OrderedOptions
|
44
70
|
def initialize(parent = nil)
|
45
71
|
if parent.kind_of?(OrderedOptions)
|
46
72
|
# use the faster _get when dealing with OrderedOptions
|
47
|
-
super() { |h,k| parent._get(k) }
|
73
|
+
super() { |h, k| parent._get(k) }
|
48
74
|
elsif parent
|
49
|
-
super() { |h,k| parent[k] }
|
75
|
+
super() { |h, k| parent[k] }
|
50
76
|
else
|
51
77
|
super()
|
52
78
|
end
|
@@ -1,4 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_support/core_ext/module/delegation"
|
4
|
+
|
1
5
|
module ActiveSupport
|
6
|
+
# NOTE: This approach has been deprecated for end-user code in favor of {thread_mattr_accessor}[rdoc-ref:Module#thread_mattr_accessor] and friends.
|
7
|
+
# Please use that approach instead.
|
8
|
+
#
|
2
9
|
# This module is used to encapsulate access to thread local variables.
|
3
10
|
#
|
4
11
|
# Instead of polluting the thread locals namespace:
|
@@ -32,21 +39,22 @@ module ActiveSupport
|
|
32
39
|
#
|
33
40
|
# If the class has an initializer, it must accept no arguments.
|
34
41
|
module PerThreadRegistry
|
35
|
-
|
42
|
+
def self.extended(object)
|
43
|
+
object.instance_variable_set "@per_thread_registry_key", object.name.freeze
|
44
|
+
end
|
36
45
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
per_thread_registry_instance.public_send(name, *a, &b)
|
41
|
-
end
|
42
|
-
|
43
|
-
send(name, *args, &block)
|
44
|
-
end
|
46
|
+
def instance
|
47
|
+
Thread.current[@per_thread_registry_key] ||= new
|
48
|
+
end
|
45
49
|
|
46
50
|
private
|
51
|
+
def method_missing(name, *args, &block)
|
52
|
+
# Caches the method definition as a singleton method of the receiver.
|
53
|
+
#
|
54
|
+
# By letting #delegate handle it, we avoid an enclosure that'll capture args.
|
55
|
+
singleton_class.delegate name, to: :instance
|
47
56
|
|
48
|
-
|
49
|
-
Thread.current[name] ||= new
|
57
|
+
send(name, *args, &block)
|
50
58
|
end
|
51
59
|
end
|
52
60
|
end
|
data/lib/active_support/rails.rb
CHANGED
@@ -1,27 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# This is private interface.
|
2
4
|
#
|
3
5
|
# Rails components cherry pick from Active Support as needed, but there are a
|
4
|
-
# few features that are used for sure some way or another and it is not worth
|
5
|
-
#
|
6
|
+
# few features that are used for sure in some way or another and it is not worth
|
7
|
+
# putting individual requires absolutely everywhere. Think blank? for example.
|
6
8
|
#
|
7
9
|
# This file is loaded by every Rails component except Active Support itself,
|
8
10
|
# but it does not belong to the Rails public interface. It is internal to
|
9
11
|
# Rails and can change anytime.
|
10
12
|
|
11
13
|
# Defines Object#blank? and Object#present?.
|
12
|
-
require
|
14
|
+
require "active_support/core_ext/object/blank"
|
13
15
|
|
14
16
|
# Rails own autoload, eager_load, etc.
|
15
|
-
require
|
17
|
+
require "active_support/dependencies/autoload"
|
16
18
|
|
17
19
|
# Support for ClassMethods and the included macro.
|
18
|
-
require
|
20
|
+
require "active_support/concern"
|
19
21
|
|
20
22
|
# Defines Class#class_attribute.
|
21
|
-
require
|
23
|
+
require "active_support/core_ext/class/attribute"
|
22
24
|
|
23
25
|
# Defines Module#delegate.
|
24
|
-
require
|
26
|
+
require "active_support/core_ext/module/delegation"
|
25
27
|
|
26
28
|
# Defines ActiveSupport::Deprecation.
|
27
|
-
require
|
29
|
+
require "active_support/deprecation"
|
30
|
+
|
31
|
+
# Defines Regexp#match?.
|
32
|
+
#
|
33
|
+
# This should be removed when Rails needs Ruby 2.4 or later, and the require
|
34
|
+
# added where other Regexp extensions are being used (easy to grep).
|
35
|
+
require "active_support/core_ext/regexp"
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "active_support"
|
2
4
|
require "active_support/i18n_railtie"
|
3
5
|
|
@@ -7,6 +9,21 @@ module ActiveSupport
|
|
7
9
|
|
8
10
|
config.eager_load_namespaces << ActiveSupport
|
9
11
|
|
12
|
+
initializer "active_support.set_authenticated_message_encryption" do |app|
|
13
|
+
config.after_initialize do
|
14
|
+
unless app.config.active_support.use_authenticated_message_encryption.nil?
|
15
|
+
ActiveSupport::MessageEncryptor.use_authenticated_message_encryption =
|
16
|
+
app.config.active_support.use_authenticated_message_encryption
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
initializer "active_support.reset_all_current_attributes_instances" do |app|
|
22
|
+
app.reloader.before_class_unload { ActiveSupport::CurrentAttributes.clear_all }
|
23
|
+
app.executor.to_run { ActiveSupport::CurrentAttributes.reset_all }
|
24
|
+
app.executor.to_complete { ActiveSupport::CurrentAttributes.reset_all }
|
25
|
+
end
|
26
|
+
|
10
27
|
initializer "active_support.deprecation_behavior" do |app|
|
11
28
|
if deprecation = app.config.active_support.deprecation
|
12
29
|
ActiveSupport::Deprecation.behavior = deprecation
|
@@ -16,31 +33,48 @@ module ActiveSupport
|
|
16
33
|
# Sets the default value for Time.zone
|
17
34
|
# If assigned value cannot be matched to a TimeZone, an exception will be raised.
|
18
35
|
initializer "active_support.initialize_time_zone" do |app|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
raise 'Value assigned to config.time_zone not recognized. ' \
|
24
|
-
'Run "rake -D time" for a list of tasks for finding appropriate time zone names.'
|
36
|
+
begin
|
37
|
+
TZInfo::DataSource.get
|
38
|
+
rescue TZInfo::DataSourceNotFound => e
|
39
|
+
raise e.exception "tzinfo-data is not present. Please add gem 'tzinfo-data' to your Gemfile and run bundle install"
|
25
40
|
end
|
26
|
-
|
27
|
-
Time.zone_default =
|
41
|
+
require "active_support/core_ext/time/zones"
|
42
|
+
Time.zone_default = Time.find_zone!(app.config.time_zone)
|
28
43
|
end
|
29
44
|
|
30
45
|
# Sets the default week start
|
31
46
|
# If assigned value is not a valid day symbol (e.g. :sunday, :monday, ...), an exception will be raised.
|
32
47
|
initializer "active_support.initialize_beginning_of_week" do |app|
|
33
|
-
require
|
48
|
+
require "active_support/core_ext/date/calculations"
|
34
49
|
beginning_of_week_default = Date.find_beginning_of_week!(app.config.beginning_of_week)
|
35
50
|
|
36
51
|
Date.beginning_of_week_default = beginning_of_week_default
|
37
52
|
end
|
38
53
|
|
54
|
+
initializer "active_support.require_master_key" do |app|
|
55
|
+
if app.config.respond_to?(:require_master_key) && app.config.require_master_key
|
56
|
+
begin
|
57
|
+
app.credentials.key
|
58
|
+
rescue ActiveSupport::EncryptedFile::MissingKeyError => error
|
59
|
+
$stderr.puts error.message
|
60
|
+
exit 1
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
39
65
|
initializer "active_support.set_configs" do |app|
|
40
66
|
app.config.active_support.each do |k, v|
|
41
67
|
k = "#{k}="
|
42
68
|
ActiveSupport.send(k, v) if ActiveSupport.respond_to? k
|
43
69
|
end
|
44
70
|
end
|
71
|
+
|
72
|
+
initializer "active_support.set_hash_digest_class" do |app|
|
73
|
+
config.after_initialize do
|
74
|
+
if app.config.active_support.use_sha1_digests
|
75
|
+
ActiveSupport::Digest.hash_digest_class = ::Digest::SHA1
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
45
79
|
end
|
46
80
|
end
|
@@ -0,0 +1,131 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_support/execution_wrapper"
|
4
|
+
|
5
|
+
module ActiveSupport
|
6
|
+
#--
|
7
|
+
# This class defines several callbacks:
|
8
|
+
#
|
9
|
+
# to_prepare -- Run once at application startup, and also from
|
10
|
+
# +to_run+.
|
11
|
+
#
|
12
|
+
# to_run -- Run before a work run that is reloading. If
|
13
|
+
# +reload_classes_only_on_change+ is true (the default), the class
|
14
|
+
# unload will have already occurred.
|
15
|
+
#
|
16
|
+
# to_complete -- Run after a work run that has reloaded. If
|
17
|
+
# +reload_classes_only_on_change+ is false, the class unload will
|
18
|
+
# have occurred after the work run, but before this callback.
|
19
|
+
#
|
20
|
+
# before_class_unload -- Run immediately before the classes are
|
21
|
+
# unloaded.
|
22
|
+
#
|
23
|
+
# after_class_unload -- Run immediately after the classes are
|
24
|
+
# unloaded.
|
25
|
+
#
|
26
|
+
class Reloader < ExecutionWrapper
|
27
|
+
define_callbacks :prepare
|
28
|
+
|
29
|
+
define_callbacks :class_unload
|
30
|
+
|
31
|
+
# Registers a callback that will run once at application startup and every time the code is reloaded.
|
32
|
+
def self.to_prepare(*args, &block)
|
33
|
+
set_callback(:prepare, *args, &block)
|
34
|
+
end
|
35
|
+
|
36
|
+
# Registers a callback that will run immediately before the classes are unloaded.
|
37
|
+
def self.before_class_unload(*args, &block)
|
38
|
+
set_callback(:class_unload, *args, &block)
|
39
|
+
end
|
40
|
+
|
41
|
+
# Registers a callback that will run immediately after the classes are unloaded.
|
42
|
+
def self.after_class_unload(*args, &block)
|
43
|
+
set_callback(:class_unload, :after, *args, &block)
|
44
|
+
end
|
45
|
+
|
46
|
+
to_run(:after) { self.class.prepare! }
|
47
|
+
|
48
|
+
# Initiate a manual reload
|
49
|
+
def self.reload!
|
50
|
+
executor.wrap do
|
51
|
+
new.tap do |instance|
|
52
|
+
begin
|
53
|
+
instance.run!
|
54
|
+
ensure
|
55
|
+
instance.complete!
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
prepare!
|
60
|
+
end
|
61
|
+
|
62
|
+
def self.run! # :nodoc:
|
63
|
+
if check!
|
64
|
+
super
|
65
|
+
else
|
66
|
+
Null
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
# Run the supplied block as a work unit, reloading code as needed
|
71
|
+
def self.wrap
|
72
|
+
executor.wrap do
|
73
|
+
super
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
class_attribute :executor, default: Executor
|
78
|
+
class_attribute :check, default: lambda { false }
|
79
|
+
|
80
|
+
def self.check! # :nodoc:
|
81
|
+
@should_reload ||= check.call
|
82
|
+
end
|
83
|
+
|
84
|
+
def self.reloaded! # :nodoc:
|
85
|
+
@should_reload = false
|
86
|
+
end
|
87
|
+
|
88
|
+
def self.prepare! # :nodoc:
|
89
|
+
new.run_callbacks(:prepare)
|
90
|
+
end
|
91
|
+
|
92
|
+
def initialize
|
93
|
+
super
|
94
|
+
@locked = false
|
95
|
+
end
|
96
|
+
|
97
|
+
# Acquire the ActiveSupport::Dependencies::Interlock unload lock,
|
98
|
+
# ensuring it will be released automatically
|
99
|
+
def require_unload_lock!
|
100
|
+
unless @locked
|
101
|
+
ActiveSupport::Dependencies.interlock.start_unloading
|
102
|
+
@locked = true
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
# Release the unload lock if it has been previously obtained
|
107
|
+
def release_unload_lock!
|
108
|
+
if @locked
|
109
|
+
@locked = false
|
110
|
+
ActiveSupport::Dependencies.interlock.done_unloading
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
def run! # :nodoc:
|
115
|
+
super
|
116
|
+
release_unload_lock!
|
117
|
+
end
|
118
|
+
|
119
|
+
def class_unload!(&block) # :nodoc:
|
120
|
+
require_unload_lock!
|
121
|
+
run_callbacks(:class_unload, &block)
|
122
|
+
end
|
123
|
+
|
124
|
+
def complete! # :nodoc:
|
125
|
+
super
|
126
|
+
self.class.reloaded!
|
127
|
+
ensure
|
128
|
+
release_unload_lock!
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
@@ -1,7 +1,8 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require
|
4
|
-
require
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_support/concern"
|
4
|
+
require "active_support/core_ext/class/attribute"
|
5
|
+
require "active_support/core_ext/string/inflections"
|
5
6
|
|
6
7
|
module ActiveSupport
|
7
8
|
# Rescuable module adds support for easier exception handling.
|
@@ -9,8 +10,7 @@ module ActiveSupport
|
|
9
10
|
extend Concern
|
10
11
|
|
11
12
|
included do
|
12
|
-
class_attribute :rescue_handlers
|
13
|
-
self.rescue_handlers = []
|
13
|
+
class_attribute :rescue_handlers, default: []
|
14
14
|
end
|
15
15
|
|
16
16
|
module ClassMethods
|
@@ -37,7 +37,7 @@ module ActiveSupport
|
|
37
37
|
# render xml: exception, status: 500
|
38
38
|
# end
|
39
39
|
#
|
40
|
-
#
|
40
|
+
# private
|
41
41
|
# def deny_access
|
42
42
|
# ...
|
43
43
|
# end
|
@@ -48,72 +48,127 @@ module ActiveSupport
|
|
48
48
|
# end
|
49
49
|
#
|
50
50
|
# Exceptions raised inside exception handlers are not propagated up.
|
51
|
-
def rescue_from(*klasses, &block)
|
52
|
-
|
53
|
-
|
54
|
-
unless options.has_key?(:with)
|
51
|
+
def rescue_from(*klasses, with: nil, &block)
|
52
|
+
unless with
|
55
53
|
if block_given?
|
56
|
-
|
54
|
+
with = block
|
57
55
|
else
|
58
|
-
raise ArgumentError, "Need a handler.
|
56
|
+
raise ArgumentError, "Need a handler. Pass the with: keyword argument or provide a block."
|
59
57
|
end
|
60
58
|
end
|
61
59
|
|
62
60
|
klasses.each do |klass|
|
63
|
-
key = if klass.is_a?(
|
61
|
+
key = if klass.is_a?(Module) && klass.respond_to?(:===)
|
64
62
|
klass.name
|
65
63
|
elsif klass.is_a?(String)
|
66
64
|
klass
|
67
65
|
else
|
68
|
-
raise ArgumentError, "#{klass}
|
66
|
+
raise ArgumentError, "#{klass.inspect} must be an Exception class or a String referencing an Exception class"
|
69
67
|
end
|
70
68
|
|
71
|
-
#
|
72
|
-
self.rescue_handlers += [[key,
|
69
|
+
# Put the new handler at the end because the list is read in reverse.
|
70
|
+
self.rescue_handlers += [[key, with]]
|
73
71
|
end
|
74
72
|
end
|
75
|
-
end
|
76
73
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
74
|
+
# Matches an exception to a handler based on the exception class.
|
75
|
+
#
|
76
|
+
# If no handler matches the exception, check for a handler matching the
|
77
|
+
# (optional) exception.cause. If no handler matches the exception or its
|
78
|
+
# cause, this returns +nil+, so you can deal with unhandled exceptions.
|
79
|
+
# Be sure to re-raise unhandled exceptions if this is what you expect.
|
80
|
+
#
|
81
|
+
# begin
|
82
|
+
# …
|
83
|
+
# rescue => exception
|
84
|
+
# rescue_with_handler(exception) || raise
|
85
|
+
# end
|
86
|
+
#
|
87
|
+
# Returns the exception if it was handled and +nil+ if it was not.
|
88
|
+
def rescue_with_handler(exception, object: self, visited_exceptions: [])
|
89
|
+
visited_exceptions << exception
|
84
90
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
# could trigger some other handler and the array could include
|
96
|
-
# precisely a string whose corresponding constant has not yet been
|
97
|
-
# seen. This is why we are tolerant to unknown constants.
|
98
|
-
#
|
99
|
-
# Note that this tolerance only matters if the exception was given as
|
100
|
-
# a string, otherwise a NameError will be raised by the interpreter
|
101
|
-
# itself when rescue_from CONSTANT is executed.
|
102
|
-
klass = self.class.const_get(klass_name) rescue nil
|
103
|
-
klass ||= klass_name.constantize rescue nil
|
104
|
-
exception.is_a?(klass) if klass
|
91
|
+
if handler = handler_for_rescue(exception, object: object)
|
92
|
+
handler.call exception
|
93
|
+
exception
|
94
|
+
elsif exception
|
95
|
+
if visited_exceptions.include?(exception.cause)
|
96
|
+
nil
|
97
|
+
else
|
98
|
+
rescue_with_handler(exception.cause, object: object, visited_exceptions: visited_exceptions)
|
99
|
+
end
|
100
|
+
end
|
105
101
|
end
|
106
102
|
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
103
|
+
def handler_for_rescue(exception, object: self) #:nodoc:
|
104
|
+
case rescuer = find_rescue_handler(exception)
|
105
|
+
when Symbol
|
106
|
+
method = object.method(rescuer)
|
107
|
+
if method.arity == 0
|
108
|
+
-> e { method.call }
|
109
|
+
else
|
110
|
+
method
|
111
|
+
end
|
112
|
+
when Proc
|
113
|
+
if rescuer.arity == 0
|
114
|
+
-> e { object.instance_exec(&rescuer) }
|
115
|
+
else
|
116
|
+
-> e { object.instance_exec(e, &rescuer) }
|
117
|
+
end
|
115
118
|
end
|
116
119
|
end
|
120
|
+
|
121
|
+
private
|
122
|
+
def find_rescue_handler(exception)
|
123
|
+
if exception
|
124
|
+
# Handlers are in order of declaration but the most recently declared
|
125
|
+
# is the highest priority match, so we search for matching handlers
|
126
|
+
# in reverse.
|
127
|
+
_, handler = rescue_handlers.reverse_each.detect do |class_or_name, _|
|
128
|
+
if klass = constantize_rescue_handler_class(class_or_name)
|
129
|
+
klass === exception
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
handler
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
def constantize_rescue_handler_class(class_or_name)
|
138
|
+
case class_or_name
|
139
|
+
when String, Symbol
|
140
|
+
begin
|
141
|
+
# Try a lexical lookup first since we support
|
142
|
+
#
|
143
|
+
# class Super
|
144
|
+
# rescue_from 'Error', with: …
|
145
|
+
# end
|
146
|
+
#
|
147
|
+
# class Sub
|
148
|
+
# class Error < StandardError; end
|
149
|
+
# end
|
150
|
+
#
|
151
|
+
# so an Error raised in Sub will hit the 'Error' handler.
|
152
|
+
const_get class_or_name
|
153
|
+
rescue NameError
|
154
|
+
class_or_name.safe_constantize
|
155
|
+
end
|
156
|
+
else
|
157
|
+
class_or_name
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
# Delegates to the class method, but uses the instance as the subject for
|
163
|
+
# rescue_from handlers (method calls, instance_exec blocks).
|
164
|
+
def rescue_with_handler(exception)
|
165
|
+
self.class.rescue_with_handler exception, object: self
|
166
|
+
end
|
167
|
+
|
168
|
+
# Internal handler lookup. Delegates to class method. Some libraries call
|
169
|
+
# this directly, so keeping it around for compatibility.
|
170
|
+
def handler_for_rescue(exception) #:nodoc:
|
171
|
+
self.class.handler_for_rescue exception, object: self
|
117
172
|
end
|
118
173
|
end
|
119
174
|
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "digest/sha2"
|
4
|
+
|
5
|
+
module ActiveSupport
|
6
|
+
module SecurityUtils
|
7
|
+
# Constant time string comparison, for fixed length strings.
|
8
|
+
#
|
9
|
+
# The values compared should be of fixed length, such as strings
|
10
|
+
# that have already been processed by HMAC. Raises in case of length mismatch.
|
11
|
+
def fixed_length_secure_compare(a, b)
|
12
|
+
raise ArgumentError, "string length mismatch." unless a.bytesize == b.bytesize
|
13
|
+
|
14
|
+
l = a.unpack "C#{a.bytesize}"
|
15
|
+
|
16
|
+
res = 0
|
17
|
+
b.each_byte { |byte| res |= byte ^ l.shift }
|
18
|
+
res == 0
|
19
|
+
end
|
20
|
+
module_function :fixed_length_secure_compare
|
21
|
+
|
22
|
+
# Constant time string comparison, for variable length strings.
|
23
|
+
#
|
24
|
+
# The values are first processed by SHA256, so that we don't leak length info
|
25
|
+
# via timing attacks.
|
26
|
+
def secure_compare(a, b)
|
27
|
+
fixed_length_secure_compare(::Digest::SHA256.hexdigest(a), ::Digest::SHA256.hexdigest(b)) && a == b
|
28
|
+
end
|
29
|
+
module_function :secure_compare
|
30
|
+
end
|
31
|
+
end
|
@@ -1,22 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ActiveSupport
|
2
4
|
# Wrapping a string in this class gives you a prettier way to test
|
3
5
|
# for equality. The value returned by <tt>Rails.env</tt> is wrapped
|
4
|
-
# in a StringInquirer object so instead of calling this:
|
6
|
+
# in a StringInquirer object, so instead of calling this:
|
5
7
|
#
|
6
8
|
# Rails.env == 'production'
|
7
9
|
#
|
8
10
|
# you can call this:
|
9
11
|
#
|
10
12
|
# Rails.env.production?
|
13
|
+
#
|
14
|
+
# == Instantiating a new StringInquirer
|
15
|
+
#
|
16
|
+
# vehicle = ActiveSupport::StringInquirer.new('car')
|
17
|
+
# vehicle.car? # => true
|
18
|
+
# vehicle.bike? # => false
|
11
19
|
class StringInquirer < String
|
12
20
|
private
|
13
21
|
|
14
22
|
def respond_to_missing?(method_name, include_private = false)
|
15
|
-
method_name[-1] ==
|
23
|
+
(method_name[-1] == "?") || super
|
16
24
|
end
|
17
25
|
|
18
26
|
def method_missing(method_name, *arguments)
|
19
|
-
if method_name[-1] ==
|
27
|
+
if method_name[-1] == "?"
|
20
28
|
self == method_name[0..-2]
|
21
29
|
else
|
22
30
|
super
|