omg-activesupport 8.0.0.alpha1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +86 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +40 -0
- data/lib/active_support/actionable_error.rb +50 -0
- data/lib/active_support/all.rb +5 -0
- data/lib/active_support/array_inquirer.rb +50 -0
- data/lib/active_support/backtrace_cleaner.rb +163 -0
- data/lib/active_support/benchmark.rb +21 -0
- data/lib/active_support/benchmarkable.rb +53 -0
- data/lib/active_support/broadcast_logger.rb +251 -0
- data/lib/active_support/builder.rb +8 -0
- data/lib/active_support/cache/coder.rb +153 -0
- data/lib/active_support/cache/entry.rb +134 -0
- data/lib/active_support/cache/file_store.rb +244 -0
- data/lib/active_support/cache/mem_cache_store.rb +290 -0
- data/lib/active_support/cache/memory_store.rb +262 -0
- data/lib/active_support/cache/null_store.rb +62 -0
- data/lib/active_support/cache/redis_cache_store.rb +492 -0
- data/lib/active_support/cache/serializer_with_fallback.rb +152 -0
- data/lib/active_support/cache/strategy/local_cache.rb +201 -0
- data/lib/active_support/cache/strategy/local_cache_middleware.rb +45 -0
- data/lib/active_support/cache.rb +1104 -0
- data/lib/active_support/callbacks.rb +944 -0
- data/lib/active_support/class_attribute.rb +26 -0
- data/lib/active_support/code_generator.rb +79 -0
- data/lib/active_support/concern.rb +217 -0
- data/lib/active_support/concurrency/load_interlock_aware_monitor.rb +72 -0
- data/lib/active_support/concurrency/null_lock.rb +13 -0
- data/lib/active_support/concurrency/share_lock.rb +225 -0
- data/lib/active_support/configurable.rb +159 -0
- data/lib/active_support/configuration_file.rb +60 -0
- data/lib/active_support/core_ext/array/access.rb +100 -0
- data/lib/active_support/core_ext/array/conversions.rb +213 -0
- data/lib/active_support/core_ext/array/extract.rb +21 -0
- data/lib/active_support/core_ext/array/extract_options.rb +31 -0
- data/lib/active_support/core_ext/array/grouping.rb +109 -0
- data/lib/active_support/core_ext/array/inquiry.rb +19 -0
- data/lib/active_support/core_ext/array/wrap.rb +48 -0
- data/lib/active_support/core_ext/array.rb +9 -0
- data/lib/active_support/core_ext/benchmark.rb +13 -0
- data/lib/active_support/core_ext/big_decimal/conversions.rb +14 -0
- data/lib/active_support/core_ext/big_decimal.rb +3 -0
- data/lib/active_support/core_ext/class/attribute.rb +122 -0
- data/lib/active_support/core_ext/class/attribute_accessors.rb +6 -0
- data/lib/active_support/core_ext/class/subclasses.rb +24 -0
- data/lib/active_support/core_ext/class.rb +4 -0
- data/lib/active_support/core_ext/date/acts_like.rb +10 -0
- data/lib/active_support/core_ext/date/blank.rb +18 -0
- data/lib/active_support/core_ext/date/calculations.rb +161 -0
- data/lib/active_support/core_ext/date/conversions.rb +98 -0
- data/lib/active_support/core_ext/date/zones.rb +8 -0
- data/lib/active_support/core_ext/date.rb +7 -0
- data/lib/active_support/core_ext/date_and_time/calculations.rb +374 -0
- data/lib/active_support/core_ext/date_and_time/compatibility.rb +58 -0
- data/lib/active_support/core_ext/date_and_time/zones.rb +40 -0
- data/lib/active_support/core_ext/date_time/acts_like.rb +16 -0
- data/lib/active_support/core_ext/date_time/blank.rb +18 -0
- data/lib/active_support/core_ext/date_time/calculations.rb +215 -0
- data/lib/active_support/core_ext/date_time/compatibility.rb +18 -0
- data/lib/active_support/core_ext/date_time/conversions.rb +106 -0
- data/lib/active_support/core_ext/date_time.rb +7 -0
- data/lib/active_support/core_ext/digest/uuid.rb +76 -0
- data/lib/active_support/core_ext/digest.rb +3 -0
- data/lib/active_support/core_ext/enumerable.rb +267 -0
- data/lib/active_support/core_ext/erb/util.rb +201 -0
- data/lib/active_support/core_ext/file/atomic.rb +72 -0
- data/lib/active_support/core_ext/file.rb +3 -0
- data/lib/active_support/core_ext/hash/conversions.rb +262 -0
- data/lib/active_support/core_ext/hash/deep_merge.rb +42 -0
- data/lib/active_support/core_ext/hash/deep_transform_values.rb +46 -0
- data/lib/active_support/core_ext/hash/except.rb +12 -0
- data/lib/active_support/core_ext/hash/indifferent_access.rb +24 -0
- data/lib/active_support/core_ext/hash/keys.rb +143 -0
- data/lib/active_support/core_ext/hash/reverse_merge.rb +25 -0
- data/lib/active_support/core_ext/hash/slice.rb +27 -0
- data/lib/active_support/core_ext/hash.rb +10 -0
- data/lib/active_support/core_ext/integer/inflections.rb +31 -0
- data/lib/active_support/core_ext/integer/multiple.rb +12 -0
- data/lib/active_support/core_ext/integer/time.rb +22 -0
- data/lib/active_support/core_ext/integer.rb +5 -0
- data/lib/active_support/core_ext/kernel/concern.rb +14 -0
- data/lib/active_support/core_ext/kernel/reporting.rb +45 -0
- data/lib/active_support/core_ext/kernel/singleton_class.rb +8 -0
- data/lib/active_support/core_ext/kernel.rb +5 -0
- data/lib/active_support/core_ext/load_error.rb +9 -0
- data/lib/active_support/core_ext/module/aliasing.rb +31 -0
- data/lib/active_support/core_ext/module/anonymous.rb +30 -0
- data/lib/active_support/core_ext/module/attr_internal.rb +49 -0
- data/lib/active_support/core_ext/module/attribute_accessors.rb +214 -0
- data/lib/active_support/core_ext/module/attribute_accessors_per_thread.rb +175 -0
- data/lib/active_support/core_ext/module/concerning.rb +140 -0
- data/lib/active_support/core_ext/module/delegation.rb +225 -0
- data/lib/active_support/core_ext/module/deprecation.rb +25 -0
- data/lib/active_support/core_ext/module/introspection.rb +62 -0
- data/lib/active_support/core_ext/module/redefine_method.rb +40 -0
- data/lib/active_support/core_ext/module/remove_method.rb +17 -0
- data/lib/active_support/core_ext/module.rb +13 -0
- data/lib/active_support/core_ext/name_error.rb +59 -0
- data/lib/active_support/core_ext/numeric/bytes.rb +75 -0
- data/lib/active_support/core_ext/numeric/conversions.rb +145 -0
- data/lib/active_support/core_ext/numeric/time.rb +66 -0
- data/lib/active_support/core_ext/numeric.rb +5 -0
- data/lib/active_support/core_ext/object/acts_like.rb +45 -0
- data/lib/active_support/core_ext/object/blank.rb +199 -0
- data/lib/active_support/core_ext/object/conversions.rb +6 -0
- data/lib/active_support/core_ext/object/deep_dup.rb +71 -0
- data/lib/active_support/core_ext/object/duplicable.rb +69 -0
- data/lib/active_support/core_ext/object/inclusion.rb +37 -0
- data/lib/active_support/core_ext/object/instance_variables.rb +32 -0
- data/lib/active_support/core_ext/object/json.rb +260 -0
- data/lib/active_support/core_ext/object/to_param.rb +3 -0
- data/lib/active_support/core_ext/object/to_query.rb +87 -0
- data/lib/active_support/core_ext/object/try.rb +158 -0
- data/lib/active_support/core_ext/object/with.rb +46 -0
- data/lib/active_support/core_ext/object/with_options.rb +101 -0
- data/lib/active_support/core_ext/object.rb +17 -0
- data/lib/active_support/core_ext/pathname/blank.rb +20 -0
- data/lib/active_support/core_ext/pathname/existence.rb +23 -0
- data/lib/active_support/core_ext/pathname.rb +4 -0
- data/lib/active_support/core_ext/range/compare_range.rb +57 -0
- data/lib/active_support/core_ext/range/conversions.rb +62 -0
- data/lib/active_support/core_ext/range/each.rb +24 -0
- data/lib/active_support/core_ext/range/overlap.rb +40 -0
- data/lib/active_support/core_ext/range.rb +6 -0
- data/lib/active_support/core_ext/regexp.rb +14 -0
- data/lib/active_support/core_ext/securerandom.rb +41 -0
- data/lib/active_support/core_ext/string/access.rb +95 -0
- data/lib/active_support/core_ext/string/behavior.rb +8 -0
- data/lib/active_support/core_ext/string/conversions.rb +60 -0
- data/lib/active_support/core_ext/string/exclude.rb +13 -0
- data/lib/active_support/core_ext/string/filters.rb +151 -0
- data/lib/active_support/core_ext/string/indent.rb +45 -0
- data/lib/active_support/core_ext/string/inflections.rb +300 -0
- data/lib/active_support/core_ext/string/inquiry.rb +16 -0
- data/lib/active_support/core_ext/string/multibyte.rb +58 -0
- data/lib/active_support/core_ext/string/output_safety.rb +228 -0
- data/lib/active_support/core_ext/string/starts_ends_with.rb +6 -0
- data/lib/active_support/core_ext/string/strip.rb +27 -0
- data/lib/active_support/core_ext/string/zones.rb +16 -0
- data/lib/active_support/core_ext/string.rb +15 -0
- data/lib/active_support/core_ext/symbol/starts_ends_with.rb +6 -0
- data/lib/active_support/core_ext/symbol.rb +3 -0
- data/lib/active_support/core_ext/thread/backtrace/location.rb +12 -0
- data/lib/active_support/core_ext/time/acts_like.rb +10 -0
- data/lib/active_support/core_ext/time/calculations.rb +386 -0
- data/lib/active_support/core_ext/time/compatibility.rb +32 -0
- data/lib/active_support/core_ext/time/conversions.rb +75 -0
- data/lib/active_support/core_ext/time/zones.rb +97 -0
- data/lib/active_support/core_ext/time.rb +7 -0
- data/lib/active_support/core_ext.rb +5 -0
- data/lib/active_support/current_attributes/test_helper.rb +13 -0
- data/lib/active_support/current_attributes.rb +233 -0
- data/lib/active_support/deep_mergeable.rb +53 -0
- data/lib/active_support/delegation.rb +202 -0
- data/lib/active_support/dependencies/autoload.rb +72 -0
- data/lib/active_support/dependencies/interlock.rb +49 -0
- data/lib/active_support/dependencies/require_dependency.rb +28 -0
- data/lib/active_support/dependencies.rb +98 -0
- data/lib/active_support/deprecation/behaviors.rb +148 -0
- data/lib/active_support/deprecation/constant_accessor.rb +74 -0
- data/lib/active_support/deprecation/deprecators.rb +104 -0
- data/lib/active_support/deprecation/disallowed.rb +54 -0
- data/lib/active_support/deprecation/method_wrappers.rb +68 -0
- data/lib/active_support/deprecation/proxy_wrappers.rb +189 -0
- data/lib/active_support/deprecation/reporting.rb +179 -0
- data/lib/active_support/deprecation.rb +81 -0
- data/lib/active_support/deprecator.rb +7 -0
- data/lib/active_support/descendants_tracker.rb +112 -0
- data/lib/active_support/digest.rb +22 -0
- data/lib/active_support/duration/iso8601_parser.rb +123 -0
- data/lib/active_support/duration/iso8601_serializer.rb +64 -0
- data/lib/active_support/duration.rb +520 -0
- data/lib/active_support/encrypted_configuration.rb +126 -0
- data/lib/active_support/encrypted_file.rb +133 -0
- data/lib/active_support/environment_inquirer.rb +40 -0
- data/lib/active_support/error_reporter/test_helper.rb +15 -0
- data/lib/active_support/error_reporter.rb +265 -0
- data/lib/active_support/evented_file_update_checker.rb +182 -0
- data/lib/active_support/execution_context/test_helper.rb +13 -0
- data/lib/active_support/execution_context.rb +53 -0
- data/lib/active_support/execution_wrapper.rb +150 -0
- data/lib/active_support/executor/test_helper.rb +7 -0
- data/lib/active_support/executor.rb +8 -0
- data/lib/active_support/file_update_checker.rb +164 -0
- data/lib/active_support/fork_tracker.rb +43 -0
- data/lib/active_support/gem_version.rb +17 -0
- data/lib/active_support/gzip.rb +40 -0
- data/lib/active_support/hash_with_indifferent_access.rb +445 -0
- data/lib/active_support/html_safe_translation.rb +56 -0
- data/lib/active_support/i18n.rb +17 -0
- data/lib/active_support/i18n_railtie.rb +138 -0
- data/lib/active_support/inflections.rb +72 -0
- data/lib/active_support/inflector/inflections.rb +273 -0
- data/lib/active_support/inflector/methods.rb +387 -0
- data/lib/active_support/inflector/transliterate.rb +149 -0
- data/lib/active_support/inflector.rb +9 -0
- data/lib/active_support/isolated_execution_state.rb +75 -0
- data/lib/active_support/json/decoding.rb +76 -0
- data/lib/active_support/json/encoding.rb +120 -0
- data/lib/active_support/json.rb +4 -0
- data/lib/active_support/key_generator.rb +66 -0
- data/lib/active_support/lazy_load_hooks.rb +107 -0
- data/lib/active_support/locale/en.rb +33 -0
- data/lib/active_support/locale/en.yml +141 -0
- data/lib/active_support/log_subscriber/test_helper.rb +106 -0
- data/lib/active_support/log_subscriber.rb +192 -0
- data/lib/active_support/logger.rb +55 -0
- data/lib/active_support/logger_silence.rb +21 -0
- data/lib/active_support/logger_thread_safe_level.rb +47 -0
- data/lib/active_support/message_encryptor.rb +374 -0
- data/lib/active_support/message_encryptors.rb +141 -0
- data/lib/active_support/message_pack/cache_serializer.rb +23 -0
- data/lib/active_support/message_pack/extensions.rb +305 -0
- data/lib/active_support/message_pack/serializer.rb +63 -0
- data/lib/active_support/message_pack.rb +50 -0
- data/lib/active_support/message_verifier.rb +368 -0
- data/lib/active_support/message_verifiers.rb +135 -0
- data/lib/active_support/messages/codec.rb +65 -0
- data/lib/active_support/messages/metadata.rb +146 -0
- data/lib/active_support/messages/rotation_configuration.rb +23 -0
- data/lib/active_support/messages/rotation_coordinator.rb +93 -0
- data/lib/active_support/messages/rotator.rb +59 -0
- data/lib/active_support/messages/serializer_with_fallback.rb +158 -0
- data/lib/active_support/multibyte/chars.rb +178 -0
- data/lib/active_support/multibyte/unicode.rb +42 -0
- data/lib/active_support/multibyte.rb +23 -0
- data/lib/active_support/notifications/fanout.rb +446 -0
- data/lib/active_support/notifications/instrumenter.rb +240 -0
- data/lib/active_support/notifications.rb +281 -0
- data/lib/active_support/number_helper/number_converter.rb +190 -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 +30 -0
- data/lib/active_support/number_helper/number_to_human_converter.rb +69 -0
- data/lib/active_support/number_helper/number_to_human_size_converter.rb +60 -0
- data/lib/active_support/number_helper/number_to_percentage_converter.rb +16 -0
- data/lib/active_support/number_helper/number_to_phone_converter.rb +60 -0
- data/lib/active_support/number_helper/number_to_rounded_converter.rb +59 -0
- data/lib/active_support/number_helper/rounding_helper.rb +46 -0
- data/lib/active_support/number_helper.rb +479 -0
- data/lib/active_support/option_merger.rb +38 -0
- data/lib/active_support/ordered_hash.rb +50 -0
- data/lib/active_support/ordered_options.rb +147 -0
- data/lib/active_support/parameter_filter.rb +157 -0
- data/lib/active_support/proxy_object.rb +20 -0
- data/lib/active_support/rails.rb +26 -0
- data/lib/active_support/railtie.rb +161 -0
- data/lib/active_support/reloader.rb +138 -0
- data/lib/active_support/rescuable.rb +176 -0
- data/lib/active_support/secure_compare_rotator.rb +58 -0
- data/lib/active_support/security_utils.rb +38 -0
- data/lib/active_support/string_inquirer.rb +35 -0
- data/lib/active_support/subscriber.rb +146 -0
- data/lib/active_support/syntax_error_proxy.rb +60 -0
- data/lib/active_support/tagged_logging.rb +152 -0
- data/lib/active_support/test_case.rb +304 -0
- data/lib/active_support/testing/assertions.rb +332 -0
- data/lib/active_support/testing/autorun.rb +5 -0
- data/lib/active_support/testing/constant_lookup.rb +51 -0
- data/lib/active_support/testing/constant_stubbing.rb +54 -0
- data/lib/active_support/testing/declarative.rb +28 -0
- data/lib/active_support/testing/deprecation.rb +82 -0
- data/lib/active_support/testing/error_reporter_assertions.rb +107 -0
- data/lib/active_support/testing/file_fixtures.rb +38 -0
- data/lib/active_support/testing/isolation.rb +121 -0
- data/lib/active_support/testing/method_call_assertions.rb +69 -0
- data/lib/active_support/testing/parallelization/server.rb +85 -0
- data/lib/active_support/testing/parallelization/worker.rb +103 -0
- data/lib/active_support/testing/parallelization.rb +55 -0
- data/lib/active_support/testing/parallelize_executor.rb +81 -0
- data/lib/active_support/testing/setup_and_teardown.rb +57 -0
- data/lib/active_support/testing/stream.rb +41 -0
- data/lib/active_support/testing/strict_warnings.rb +43 -0
- data/lib/active_support/testing/tagged_logging.rb +27 -0
- data/lib/active_support/testing/tests_without_assertions.rb +19 -0
- data/lib/active_support/testing/time_helpers.rb +269 -0
- data/lib/active_support/time.rb +20 -0
- data/lib/active_support/time_with_zone.rb +609 -0
- data/lib/active_support/values/time_zone.rb +614 -0
- data/lib/active_support/version.rb +10 -0
- data/lib/active_support/xml_mini/jdom.rb +175 -0
- data/lib/active_support/xml_mini/libxml.rb +80 -0
- data/lib/active_support/xml_mini/libxmlsax.rb +83 -0
- data/lib/active_support/xml_mini/nokogiri.rb +83 -0
- data/lib/active_support/xml_mini/nokogirisax.rb +86 -0
- data/lib/active_support/xml_mini/rexml.rb +137 -0
- data/lib/active_support/xml_mini.rb +211 -0
- data/lib/active_support.rb +144 -0
- metadata +526 -0
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "yaml"
|
4
|
+
|
5
|
+
YAML.add_builtin_type("omap") do |type, val|
|
6
|
+
ActiveSupport::OrderedHash[val.map { |v| v.to_a.first }]
|
7
|
+
end
|
8
|
+
|
9
|
+
module ActiveSupport
|
10
|
+
# DEPRECATED: +ActiveSupport::OrderedHash+ implements a hash that preserves
|
11
|
+
# insertion order.
|
12
|
+
#
|
13
|
+
# oh = ActiveSupport::OrderedHash.new
|
14
|
+
# oh[:a] = 1
|
15
|
+
# oh[:b] = 2
|
16
|
+
# oh.keys # => [:a, :b], this order is guaranteed
|
17
|
+
#
|
18
|
+
# Also, maps the +omap+ feature for YAML files
|
19
|
+
# (See https://yaml.org/type/omap.html) to support ordered items
|
20
|
+
# when loading from YAML.
|
21
|
+
#
|
22
|
+
# +ActiveSupport::OrderedHash+ is namespaced to prevent conflicts
|
23
|
+
# with other implementations.
|
24
|
+
class OrderedHash < ::Hash # :nodoc:
|
25
|
+
def to_yaml_type
|
26
|
+
"!tag:yaml.org,2002:omap"
|
27
|
+
end
|
28
|
+
|
29
|
+
def encode_with(coder)
|
30
|
+
coder.represent_seq "!omap", map { |k, v| { k => v } }
|
31
|
+
end
|
32
|
+
|
33
|
+
def select(*args, &block)
|
34
|
+
dup.tap { |hash| hash.select!(*args, &block) }
|
35
|
+
end
|
36
|
+
|
37
|
+
def reject(*args, &block)
|
38
|
+
dup.tap { |hash| hash.reject!(*args, &block) }
|
39
|
+
end
|
40
|
+
|
41
|
+
def nested_under_indifferent_access
|
42
|
+
self
|
43
|
+
end
|
44
|
+
|
45
|
+
# Returns true to make sure that this hash is extractable via <tt>Array#extract_options!</tt>
|
46
|
+
def extractable_options?
|
47
|
+
true
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,147 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_support/core_ext/object/blank"
|
4
|
+
|
5
|
+
module ActiveSupport
|
6
|
+
# = Ordered Options
|
7
|
+
#
|
8
|
+
# +OrderedOptions+ inherits from +Hash+ and provides dynamic accessor methods.
|
9
|
+
#
|
10
|
+
# With a +Hash+, key-value pairs are typically managed like this:
|
11
|
+
#
|
12
|
+
# h = {}
|
13
|
+
# h[:boy] = 'John'
|
14
|
+
# h[:girl] = 'Mary'
|
15
|
+
# h[:boy] # => 'John'
|
16
|
+
# h[:girl] # => 'Mary'
|
17
|
+
# h[:dog] # => nil
|
18
|
+
#
|
19
|
+
# Using +OrderedOptions+, the above code can be written as:
|
20
|
+
#
|
21
|
+
# h = ActiveSupport::OrderedOptions.new
|
22
|
+
# h.boy = 'John'
|
23
|
+
# h.girl = 'Mary'
|
24
|
+
# h.boy # => 'John'
|
25
|
+
# h.girl # => 'Mary'
|
26
|
+
# h.dog # => nil
|
27
|
+
#
|
28
|
+
# To raise an exception when the value is blank, append a
|
29
|
+
# bang to the key name, like:
|
30
|
+
#
|
31
|
+
# h.dog! # => raises KeyError: :dog is blank
|
32
|
+
#
|
33
|
+
class OrderedOptions < Hash
|
34
|
+
alias_method :_get, :[] # preserve the original #[] method
|
35
|
+
protected :_get # make it protected
|
36
|
+
|
37
|
+
def []=(key, value)
|
38
|
+
super(key.to_sym, value)
|
39
|
+
end
|
40
|
+
|
41
|
+
def [](key)
|
42
|
+
super(key.to_sym)
|
43
|
+
end
|
44
|
+
|
45
|
+
def dig(key, *identifiers)
|
46
|
+
super(key.to_sym, *identifiers)
|
47
|
+
end
|
48
|
+
|
49
|
+
def method_missing(method, *args)
|
50
|
+
if method.end_with?("=")
|
51
|
+
self[method.name.chomp("=")] = args.first
|
52
|
+
elsif method.end_with?("!")
|
53
|
+
name_string = method.name.chomp("!")
|
54
|
+
self[name_string].presence || raise(KeyError.new(":#{name_string} is blank"))
|
55
|
+
else
|
56
|
+
self[method.name]
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def respond_to_missing?(name, include_private)
|
61
|
+
true
|
62
|
+
end
|
63
|
+
|
64
|
+
def extractable_options?
|
65
|
+
true
|
66
|
+
end
|
67
|
+
|
68
|
+
def inspect
|
69
|
+
"#<#{self.class.name} #{super}>"
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
# = Inheritable Options
|
74
|
+
#
|
75
|
+
# +InheritableOptions+ provides a constructor to build an OrderedOptions
|
76
|
+
# hash inherited from another hash.
|
77
|
+
#
|
78
|
+
# Use this if you already have some hash and you want to create a new one based on it.
|
79
|
+
#
|
80
|
+
# h = ActiveSupport::InheritableOptions.new({ girl: 'Mary', boy: 'John' })
|
81
|
+
# h.girl # => 'Mary'
|
82
|
+
# h.boy # => 'John'
|
83
|
+
#
|
84
|
+
# If the existing hash has string keys, call Hash#symbolize_keys on it.
|
85
|
+
#
|
86
|
+
# h = ActiveSupport::InheritableOptions.new({ 'girl' => 'Mary', 'boy' => 'John' }.symbolize_keys)
|
87
|
+
# h.girl # => 'Mary'
|
88
|
+
# h.boy # => 'John'
|
89
|
+
class InheritableOptions < OrderedOptions
|
90
|
+
def initialize(parent = nil)
|
91
|
+
@parent = parent
|
92
|
+
if @parent.kind_of?(OrderedOptions)
|
93
|
+
# use the faster _get when dealing with OrderedOptions
|
94
|
+
super() { |h, k| @parent._get(k) }
|
95
|
+
elsif @parent
|
96
|
+
super() { |h, k| @parent[k] }
|
97
|
+
else
|
98
|
+
super()
|
99
|
+
@parent = {}
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
def to_h
|
104
|
+
@parent.merge(self)
|
105
|
+
end
|
106
|
+
|
107
|
+
def ==(other)
|
108
|
+
to_h == other.to_h
|
109
|
+
end
|
110
|
+
|
111
|
+
def inspect
|
112
|
+
"#<#{self.class.name} #{to_h.inspect}>"
|
113
|
+
end
|
114
|
+
|
115
|
+
def to_s
|
116
|
+
to_h.to_s
|
117
|
+
end
|
118
|
+
|
119
|
+
def pretty_print(pp)
|
120
|
+
pp.pp_hash(to_h)
|
121
|
+
end
|
122
|
+
|
123
|
+
alias_method :own_key?, :key?
|
124
|
+
private :own_key?
|
125
|
+
|
126
|
+
def key?(key)
|
127
|
+
super || @parent.key?(key)
|
128
|
+
end
|
129
|
+
|
130
|
+
def overridden?(key)
|
131
|
+
!!(@parent && @parent.key?(key) && own_key?(key.to_sym))
|
132
|
+
end
|
133
|
+
|
134
|
+
def inheritable_copy
|
135
|
+
self.class.new(self)
|
136
|
+
end
|
137
|
+
|
138
|
+
def to_a
|
139
|
+
entries
|
140
|
+
end
|
141
|
+
|
142
|
+
def each(&block)
|
143
|
+
to_h.each(&block)
|
144
|
+
self
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
@@ -0,0 +1,157 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_support/core_ext/object/duplicable"
|
4
|
+
require "active_support/core_ext/array/extract"
|
5
|
+
|
6
|
+
module ActiveSupport
|
7
|
+
# = Active Support Parameter Filter
|
8
|
+
#
|
9
|
+
# +ParameterFilter+ replaces values in a <tt>Hash</tt>-like object if their
|
10
|
+
# keys match one of the specified filters.
|
11
|
+
#
|
12
|
+
# Matching based on nested keys is possible by using dot notation, e.g.
|
13
|
+
# <tt>"credit_card.number"</tt>.
|
14
|
+
#
|
15
|
+
# If a proc is given as a filter, each key and value of the <tt>Hash</tt>-like
|
16
|
+
# and of any nested <tt>Hash</tt>es will be passed to it. The value or key can
|
17
|
+
# then be mutated as desired using methods such as <tt>String#replace</tt>.
|
18
|
+
#
|
19
|
+
# # Replaces values with "[FILTERED]" for keys that match /password/i.
|
20
|
+
# ActiveSupport::ParameterFilter.new([:password])
|
21
|
+
#
|
22
|
+
# # Replaces values with "[FILTERED]" for keys that match /foo|bar/i.
|
23
|
+
# ActiveSupport::ParameterFilter.new([:foo, "bar"])
|
24
|
+
#
|
25
|
+
# # Replaces values for the exact key "pin" and for keys that begin with
|
26
|
+
# # "pin_". Does not match keys that otherwise include "pin" as a
|
27
|
+
# # substring, such as "shipping_id".
|
28
|
+
# ActiveSupport::ParameterFilter.new([/\Apin\z/, /\Apin_/])
|
29
|
+
#
|
30
|
+
# # Replaces the value for :code in `{ credit_card: { code: "xxxx" } }`.
|
31
|
+
# # Does not change `{ file: { code: "xxxx" } }`.
|
32
|
+
# ActiveSupport::ParameterFilter.new(["credit_card.code"])
|
33
|
+
#
|
34
|
+
# # Reverses values for keys that match /secret/i.
|
35
|
+
# ActiveSupport::ParameterFilter.new([-> (k, v) do
|
36
|
+
# v.reverse! if /secret/i.match?(k)
|
37
|
+
# end])
|
38
|
+
#
|
39
|
+
class ParameterFilter
|
40
|
+
FILTERED = "[FILTERED]" # :nodoc:
|
41
|
+
|
42
|
+
# Precompiles an array of filters that otherwise would be passed directly to
|
43
|
+
# #initialize. Depending on the quantity and types of filters,
|
44
|
+
# precompilation can improve filtering performance, especially in the case
|
45
|
+
# where the ParameterFilter instance itself cannot be retained (but the
|
46
|
+
# precompiled filters can be retained).
|
47
|
+
#
|
48
|
+
# filters = [/foo/, :bar, "nested.baz", /nested\.qux/]
|
49
|
+
#
|
50
|
+
# precompiled = ActiveSupport::ParameterFilter.precompile_filters(filters)
|
51
|
+
# # => [/(?-mix:foo)|(?i:bar)/, /(?i:nested\.baz)|(?-mix:nested\.qux)/]
|
52
|
+
#
|
53
|
+
# ActiveSupport::ParameterFilter.new(precompiled)
|
54
|
+
#
|
55
|
+
def self.precompile_filters(filters)
|
56
|
+
filters, patterns = filters.partition { |filter| filter.is_a?(Proc) }
|
57
|
+
|
58
|
+
patterns.map! do |pattern|
|
59
|
+
pattern.is_a?(Regexp) ? pattern : "(?i:#{Regexp.escape pattern.to_s})"
|
60
|
+
end
|
61
|
+
|
62
|
+
deep_patterns = patterns.extract! { |pattern| pattern.to_s.include?("\\.") }
|
63
|
+
|
64
|
+
filters << Regexp.new(patterns.join("|")) if patterns.any?
|
65
|
+
filters << Regexp.new(deep_patterns.join("|")) if deep_patterns.any?
|
66
|
+
|
67
|
+
filters
|
68
|
+
end
|
69
|
+
|
70
|
+
# Create instance with given filters. Supported type of filters are +String+, +Regexp+, and +Proc+.
|
71
|
+
# Other types of filters are treated as +String+ using +to_s+.
|
72
|
+
# For +Proc+ filters, key, value, and optional original hash is passed to block arguments.
|
73
|
+
#
|
74
|
+
# ==== Options
|
75
|
+
#
|
76
|
+
# * <tt>:mask</tt> - A replaced object when filtered. Defaults to <tt>"[FILTERED]"</tt>.
|
77
|
+
def initialize(filters = [], mask: FILTERED)
|
78
|
+
@mask = mask
|
79
|
+
compile_filters!(filters)
|
80
|
+
end
|
81
|
+
|
82
|
+
# Mask value of +params+ if key matches one of filters.
|
83
|
+
def filter(params)
|
84
|
+
@no_filters ? params.dup : call(params)
|
85
|
+
end
|
86
|
+
|
87
|
+
# Returns filtered value for given key. For +Proc+ filters, third block argument is not populated.
|
88
|
+
def filter_param(key, value)
|
89
|
+
@no_filters ? value : value_for_key(key, value)
|
90
|
+
end
|
91
|
+
|
92
|
+
private
|
93
|
+
def compile_filters!(filters)
|
94
|
+
@no_filters = filters.empty?
|
95
|
+
return if @no_filters
|
96
|
+
|
97
|
+
@regexps, strings = [], []
|
98
|
+
@deep_regexps, deep_strings = nil, nil
|
99
|
+
@blocks = nil
|
100
|
+
|
101
|
+
filters.each do |item|
|
102
|
+
case item
|
103
|
+
when Proc
|
104
|
+
(@blocks ||= []) << item
|
105
|
+
when Regexp
|
106
|
+
if item.to_s.include?("\\.")
|
107
|
+
(@deep_regexps ||= []) << item
|
108
|
+
else
|
109
|
+
@regexps << item
|
110
|
+
end
|
111
|
+
else
|
112
|
+
s = Regexp.escape(item.to_s)
|
113
|
+
if s.include?("\\.")
|
114
|
+
(deep_strings ||= []) << s
|
115
|
+
else
|
116
|
+
strings << s
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
@regexps << Regexp.new(strings.join("|"), true) unless strings.empty?
|
122
|
+
(@deep_regexps ||= []) << Regexp.new(deep_strings.join("|"), true) if deep_strings
|
123
|
+
end
|
124
|
+
|
125
|
+
def call(params, full_parent_key = nil, original_params = params)
|
126
|
+
filtered_params = params.class.new
|
127
|
+
|
128
|
+
params.each do |key, value|
|
129
|
+
filtered_params[key] = value_for_key(key, value, full_parent_key, original_params)
|
130
|
+
end
|
131
|
+
|
132
|
+
filtered_params
|
133
|
+
end
|
134
|
+
|
135
|
+
def value_for_key(key, value, full_parent_key = nil, original_params = nil)
|
136
|
+
if @deep_regexps
|
137
|
+
full_key = full_parent_key ? "#{full_parent_key}.#{key}" : key.to_s
|
138
|
+
end
|
139
|
+
|
140
|
+
if @regexps.any? { |r| r.match?(key.to_s) }
|
141
|
+
value = @mask
|
142
|
+
elsif @deep_regexps&.any? { |r| r.match?(full_key) }
|
143
|
+
value = @mask
|
144
|
+
elsif value.is_a?(Hash)
|
145
|
+
value = call(value, full_key, original_params)
|
146
|
+
elsif value.is_a?(Array)
|
147
|
+
value = value.map { |v| value_for_key(key, v, full_parent_key, original_params) }
|
148
|
+
elsif @blocks
|
149
|
+
key = key.dup if key.duplicable?
|
150
|
+
value = value.dup if value.duplicable?
|
151
|
+
@blocks.each { |b| b.arity == 2 ? b.call(key, value) : b.call(key, value, original_params) }
|
152
|
+
end
|
153
|
+
|
154
|
+
value
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ActiveSupport
|
4
|
+
class ProxyObject < ::BasicObject # :nodoc:
|
5
|
+
undef_method :==
|
6
|
+
undef_method :equal?
|
7
|
+
|
8
|
+
# Let ActiveSupport::ProxyObject at least raise exceptions.
|
9
|
+
def raise(*args)
|
10
|
+
::Object.send(:raise, *args)
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.inherited(_subclass)
|
14
|
+
::ActiveSupport.deprecator.warn(<<~MSG)
|
15
|
+
ActiveSupport::ProxyObject is deprecated and will be removed in Rails 8.0.
|
16
|
+
Use Ruby's built-in BasicObject instead.
|
17
|
+
MSG
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# This is a private interface.
|
4
|
+
#
|
5
|
+
# Rails components cherry pick from Active Support as needed, but there are a
|
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.
|
8
|
+
#
|
9
|
+
# This file is loaded by every Rails component except Active Support itself,
|
10
|
+
# but it does not belong to the Rails public interface. It is internal to
|
11
|
+
# Rails and can change anytime.
|
12
|
+
|
13
|
+
# Defines Object#blank? and Object#present?.
|
14
|
+
require "active_support/core_ext/object/blank"
|
15
|
+
|
16
|
+
# Support for ClassMethods and the included macro.
|
17
|
+
require "active_support/concern"
|
18
|
+
|
19
|
+
# Defines Class#class_attribute.
|
20
|
+
require "active_support/core_ext/class/attribute"
|
21
|
+
|
22
|
+
# Defines Module#delegate.
|
23
|
+
require "active_support/core_ext/module/delegation"
|
24
|
+
|
25
|
+
# Defines ActiveSupport::Deprecation.
|
26
|
+
require "active_support/deprecation"
|
@@ -0,0 +1,161 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_support"
|
4
|
+
require "active_support/i18n_railtie"
|
5
|
+
|
6
|
+
module ActiveSupport
|
7
|
+
class Railtie < Rails::Railtie # :nodoc:
|
8
|
+
config.active_support = ActiveSupport::OrderedOptions.new
|
9
|
+
|
10
|
+
config.eager_load_namespaces << ActiveSupport
|
11
|
+
|
12
|
+
initializer "active_support.deprecator", before: :load_environment_config do |app|
|
13
|
+
app.deprecators[:active_support] = ActiveSupport.deprecator
|
14
|
+
end
|
15
|
+
|
16
|
+
initializer "active_support.isolation_level" do |app|
|
17
|
+
config.after_initialize do
|
18
|
+
if level = app.config.active_support.delete(:isolation_level)
|
19
|
+
ActiveSupport::IsolatedExecutionState.isolation_level = level
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
initializer "active_support.raise_on_invalid_cache_expiration_time" do |app|
|
25
|
+
config.after_initialize do
|
26
|
+
if app.config.active_support.raise_on_invalid_cache_expiration_time
|
27
|
+
ActiveSupport::Cache::Store.raise_on_invalid_cache_expiration_time = true
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
initializer "active_support.set_authenticated_message_encryption" do |app|
|
33
|
+
config.after_initialize do
|
34
|
+
unless app.config.active_support.use_authenticated_message_encryption.nil?
|
35
|
+
ActiveSupport::MessageEncryptor.use_authenticated_message_encryption =
|
36
|
+
app.config.active_support.use_authenticated_message_encryption
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
initializer "active_support.reset_execution_context" do |app|
|
42
|
+
app.reloader.before_class_unload { ActiveSupport::ExecutionContext.clear }
|
43
|
+
app.executor.to_run { ActiveSupport::ExecutionContext.clear }
|
44
|
+
app.executor.to_complete { ActiveSupport::ExecutionContext.clear }
|
45
|
+
end
|
46
|
+
|
47
|
+
initializer "active_support.reset_all_current_attributes_instances" do |app|
|
48
|
+
app.reloader.before_class_unload { ActiveSupport::CurrentAttributes.clear_all }
|
49
|
+
app.executor.to_run { ActiveSupport::CurrentAttributes.reset_all }
|
50
|
+
app.executor.to_complete { ActiveSupport::CurrentAttributes.reset_all }
|
51
|
+
|
52
|
+
ActiveSupport.on_load(:active_support_test_case) do
|
53
|
+
if app.config.active_support.executor_around_test_case
|
54
|
+
require "active_support/executor/test_helper"
|
55
|
+
include ActiveSupport::Executor::TestHelper
|
56
|
+
else
|
57
|
+
require "active_support/current_attributes/test_helper"
|
58
|
+
include ActiveSupport::CurrentAttributes::TestHelper
|
59
|
+
|
60
|
+
require "active_support/execution_context/test_helper"
|
61
|
+
include ActiveSupport::ExecutionContext::TestHelper
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
initializer "active_support.deprecation_behavior" do |app|
|
67
|
+
if app.config.active_support.report_deprecations == false
|
68
|
+
app.deprecators.silenced = true
|
69
|
+
app.deprecators.behavior = :silence
|
70
|
+
app.deprecators.disallowed_behavior = :silence
|
71
|
+
else
|
72
|
+
if deprecation = app.config.active_support.deprecation
|
73
|
+
app.deprecators.behavior = deprecation
|
74
|
+
end
|
75
|
+
|
76
|
+
if disallowed_deprecation = app.config.active_support.disallowed_deprecation
|
77
|
+
app.deprecators.disallowed_behavior = disallowed_deprecation
|
78
|
+
end
|
79
|
+
|
80
|
+
if disallowed_warnings = app.config.active_support.disallowed_deprecation_warnings
|
81
|
+
app.deprecators.disallowed_warnings = disallowed_warnings
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
# Sets the default value for Time.zone
|
87
|
+
# If assigned value cannot be matched to a TimeZone, an exception will be raised.
|
88
|
+
initializer "active_support.initialize_time_zone" do |app|
|
89
|
+
begin
|
90
|
+
TZInfo::DataSource.get
|
91
|
+
rescue TZInfo::DataSourceNotFound => e
|
92
|
+
raise e.exception('tzinfo-data is not present. Please add gem "tzinfo-data" to your Gemfile and run bundle install')
|
93
|
+
end
|
94
|
+
require "active_support/core_ext/time/zones"
|
95
|
+
Time.zone_default = Time.find_zone!(app.config.time_zone)
|
96
|
+
config.eager_load_namespaces << TZInfo
|
97
|
+
end
|
98
|
+
|
99
|
+
initializer "active_support.to_time_preserves_timezone" do |app|
|
100
|
+
ActiveSupport.to_time_preserves_timezone = app.config.active_support.to_time_preserves_timezone
|
101
|
+
end
|
102
|
+
|
103
|
+
# Sets the default week start
|
104
|
+
# If assigned value is not a valid day symbol (e.g. :sunday, :monday, ...), an exception will be raised.
|
105
|
+
initializer "active_support.initialize_beginning_of_week" do |app|
|
106
|
+
require "active_support/core_ext/date/calculations"
|
107
|
+
beginning_of_week_default = Date.find_beginning_of_week!(app.config.beginning_of_week)
|
108
|
+
|
109
|
+
Date.beginning_of_week_default = beginning_of_week_default
|
110
|
+
end
|
111
|
+
|
112
|
+
initializer "active_support.require_master_key" do |app|
|
113
|
+
if app.config.respond_to?(:require_master_key) && app.config.require_master_key
|
114
|
+
begin
|
115
|
+
app.credentials.key
|
116
|
+
rescue ActiveSupport::EncryptedFile::MissingKeyError => error
|
117
|
+
$stderr.puts error.message
|
118
|
+
exit 1
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
initializer "active_support.set_configs" do |app|
|
124
|
+
app.config.active_support.each do |k, v|
|
125
|
+
k = "#{k}="
|
126
|
+
ActiveSupport.public_send(k, v) if ActiveSupport.respond_to? k
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
initializer "active_support.set_hash_digest_class" do |app|
|
131
|
+
config.after_initialize do
|
132
|
+
if klass = app.config.active_support.hash_digest_class
|
133
|
+
ActiveSupport::Digest.hash_digest_class = klass
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
initializer "active_support.set_key_generator_hash_digest_class" do |app|
|
139
|
+
config.after_initialize do
|
140
|
+
if klass = app.config.active_support.key_generator_hash_digest_class
|
141
|
+
ActiveSupport::KeyGenerator.hash_digest_class = klass
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
initializer "active_support.set_default_message_serializer" do |app|
|
147
|
+
config.after_initialize do
|
148
|
+
if message_serializer = app.config.active_support.message_serializer
|
149
|
+
ActiveSupport::Messages::Codec.default_serializer = message_serializer
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
initializer "active_support.set_use_message_serializer_for_metadata" do |app|
|
155
|
+
config.after_initialize do
|
156
|
+
ActiveSupport::Messages::Metadata.use_message_serializer_for_metadata =
|
157
|
+
app.config.active_support.use_message_serializer_for_metadata
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
@@ -0,0 +1,138 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_support/execution_wrapper"
|
4
|
+
require "active_support/executor"
|
5
|
+
|
6
|
+
module ActiveSupport
|
7
|
+
# = Active Support \Reloader
|
8
|
+
#
|
9
|
+
# This class defines several callbacks:
|
10
|
+
#
|
11
|
+
# to_prepare -- Run once at application startup, and also from
|
12
|
+
# +to_run+.
|
13
|
+
#
|
14
|
+
# to_run -- Run before a work run that is reloading. If
|
15
|
+
# +reload_classes_only_on_change+ is true (the default), the class
|
16
|
+
# unload will have already occurred.
|
17
|
+
#
|
18
|
+
# to_complete -- Run after a work run that has reloaded. If
|
19
|
+
# +reload_classes_only_on_change+ is false, the class unload will
|
20
|
+
# have occurred after the work run, but before this callback.
|
21
|
+
#
|
22
|
+
# before_class_unload -- Run immediately before the classes are
|
23
|
+
# unloaded.
|
24
|
+
#
|
25
|
+
# after_class_unload -- Run immediately after the classes are
|
26
|
+
# unloaded.
|
27
|
+
#
|
28
|
+
class Reloader < ExecutionWrapper
|
29
|
+
define_callbacks :prepare
|
30
|
+
|
31
|
+
define_callbacks :class_unload
|
32
|
+
|
33
|
+
# Registers a callback that will run once at application startup and every time the code is reloaded.
|
34
|
+
def self.to_prepare(*args, &block)
|
35
|
+
set_callback(:prepare, *args, &block)
|
36
|
+
end
|
37
|
+
|
38
|
+
# Registers a callback that will run immediately before the classes are unloaded.
|
39
|
+
def self.before_class_unload(*args, &block)
|
40
|
+
set_callback(:class_unload, *args, &block)
|
41
|
+
end
|
42
|
+
|
43
|
+
# Registers a callback that will run immediately after the classes are unloaded.
|
44
|
+
def self.after_class_unload(*args, &block)
|
45
|
+
set_callback(:class_unload, :after, *args, &block)
|
46
|
+
end
|
47
|
+
|
48
|
+
to_run(:after) { self.class.prepare! }
|
49
|
+
|
50
|
+
# Initiate a manual reload
|
51
|
+
def self.reload!
|
52
|
+
executor.wrap do
|
53
|
+
new.tap do |instance|
|
54
|
+
instance.run!
|
55
|
+
ensure
|
56
|
+
instance.complete!
|
57
|
+
end
|
58
|
+
end
|
59
|
+
prepare!
|
60
|
+
end
|
61
|
+
|
62
|
+
def self.run!(reset: false) # :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(**kwargs)
|
72
|
+
return yield if active?
|
73
|
+
|
74
|
+
executor.wrap(**kwargs) do
|
75
|
+
instance = run!
|
76
|
+
begin
|
77
|
+
yield
|
78
|
+
ensure
|
79
|
+
instance.complete!
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
class_attribute :executor, default: Executor
|
85
|
+
class_attribute :check, default: lambda { false }
|
86
|
+
|
87
|
+
def self.check! # :nodoc:
|
88
|
+
@should_reload ||= check.call
|
89
|
+
end
|
90
|
+
|
91
|
+
def self.reloaded! # :nodoc:
|
92
|
+
@should_reload = false
|
93
|
+
end
|
94
|
+
|
95
|
+
def self.prepare! # :nodoc:
|
96
|
+
new.run_callbacks(:prepare)
|
97
|
+
end
|
98
|
+
|
99
|
+
def initialize
|
100
|
+
super
|
101
|
+
@locked = false
|
102
|
+
end
|
103
|
+
|
104
|
+
# Acquire the ActiveSupport::Dependencies::Interlock unload lock,
|
105
|
+
# ensuring it will be released automatically
|
106
|
+
def require_unload_lock!
|
107
|
+
unless @locked
|
108
|
+
ActiveSupport::Dependencies.interlock.start_unloading
|
109
|
+
@locked = true
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
# Release the unload lock if it has been previously obtained
|
114
|
+
def release_unload_lock!
|
115
|
+
if @locked
|
116
|
+
@locked = false
|
117
|
+
ActiveSupport::Dependencies.interlock.done_unloading
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
def run! # :nodoc:
|
122
|
+
super
|
123
|
+
release_unload_lock!
|
124
|
+
end
|
125
|
+
|
126
|
+
def class_unload!(&block) # :nodoc:
|
127
|
+
require_unload_lock!
|
128
|
+
run_callbacks(:class_unload, &block)
|
129
|
+
end
|
130
|
+
|
131
|
+
def complete! # :nodoc:
|
132
|
+
super
|
133
|
+
self.class.reloaded!
|
134
|
+
ensure
|
135
|
+
release_unload_lock!
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|