activesupport 4.2.11.1 → 6.0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of activesupport might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/CHANGELOG.md +399 -411
- data/MIT-LICENSE +2 -2
- data/README.rdoc +7 -7
- data/lib/active_support/actionable_error.rb +48 -0
- data/lib/active_support/all.rb +5 -3
- data/lib/active_support/array_inquirer.rb +48 -0
- data/lib/active_support/backtrace_cleaner.rb +34 -6
- data/lib/active_support/benchmarkable.rb +6 -4
- data/lib/active_support/builder.rb +3 -1
- data/lib/active_support/cache/file_store.rb +58 -53
- data/lib/active_support/cache/mem_cache_store.rb +95 -91
- data/lib/active_support/cache/memory_store.rb +39 -36
- data/lib/active_support/cache/null_store.rb +11 -7
- data/lib/active_support/cache/redis_cache_store.rb +493 -0
- data/lib/active_support/cache/strategy/local_cache.rb +75 -42
- data/lib/active_support/cache/strategy/local_cache_middleware.rb +10 -9
- data/lib/active_support/cache.rb +331 -217
- data/lib/active_support/callbacks.rb +650 -592
- data/lib/active_support/concern.rb +35 -6
- data/lib/active_support/concurrency/load_interlock_aware_monitor.rb +35 -0
- data/lib/active_support/concurrency/share_lock.rb +226 -0
- data/lib/active_support/configurable.rb +13 -14
- data/lib/active_support/core_ext/array/access.rb +41 -1
- data/lib/active_support/core_ext/array/conversions.rb +24 -20
- data/lib/active_support/core_ext/array/extract.rb +21 -0
- data/lib/active_support/core_ext/array/extract_options.rb +2 -0
- data/lib/active_support/core_ext/array/grouping.rb +11 -18
- data/lib/active_support/core_ext/array/inquiry.rb +19 -0
- data/lib/active_support/core_ext/array/prepend_and_append.rb +4 -6
- data/lib/active_support/core_ext/array/wrap.rb +7 -4
- data/lib/active_support/core_ext/array.rb +9 -6
- data/lib/active_support/core_ext/benchmark.rb +3 -1
- data/lib/active_support/core_ext/big_decimal/conversions.rb +10 -12
- data/lib/active_support/core_ext/big_decimal.rb +3 -1
- data/lib/active_support/core_ext/class/attribute.rb +45 -31
- data/lib/active_support/core_ext/class/attribute_accessors.rb +3 -1
- data/lib/active_support/core_ext/class/subclasses.rb +20 -6
- data/lib/active_support/core_ext/class.rb +4 -3
- 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 +17 -14
- data/lib/active_support/core_ext/date/conversions.rb +25 -23
- data/lib/active_support/core_ext/date/zones.rb +4 -2
- data/lib/active_support/core_ext/date.rb +6 -4
- data/lib/active_support/core_ext/date_and_time/calculations.rb +154 -65
- data/lib/active_support/core_ext/date_and_time/compatibility.rb +4 -3
- data/lib/active_support/core_ext/date_and_time/zones.rb +12 -13
- 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 +37 -19
- data/lib/active_support/core_ext/date_time/compatibility.rb +8 -6
- data/lib/active_support/core_ext/date_time/conversions.rb +16 -13
- data/lib/active_support/core_ext/date_time.rb +7 -5
- data/lib/active_support/core_ext/digest/uuid.rb +7 -5
- data/lib/active_support/core_ext/digest.rb +3 -0
- data/lib/active_support/core_ext/enumerable.rb +114 -22
- 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 +4 -23
- data/lib/active_support/core_ext/hash/conversions.rb +62 -41
- data/lib/active_support/core_ext/hash/deep_merge.rb +9 -13
- data/lib/active_support/core_ext/hash/deep_transform_values.rb +46 -0
- data/lib/active_support/core_ext/hash/except.rb +12 -9
- data/lib/active_support/core_ext/hash/indifferent_access.rb +4 -3
- data/lib/active_support/core_ext/hash/keys.rb +19 -42
- data/lib/active_support/core_ext/hash/reverse_merge.rb +5 -2
- data/lib/active_support/core_ext/hash/slice.rb +5 -27
- data/lib/active_support/core_ext/hash/transform_values.rb +4 -22
- data/lib/active_support/core_ext/hash.rb +10 -9
- data/lib/active_support/core_ext/integer/inflections.rb +3 -1
- data/lib/active_support/core_ext/integer/multiple.rb +3 -1
- data/lib/active_support/core_ext/integer/time.rb +11 -18
- data/lib/active_support/core_ext/integer.rb +5 -3
- data/lib/active_support/core_ext/kernel/concern.rb +5 -1
- data/lib/active_support/core_ext/kernel/reporting.rb +4 -84
- data/lib/active_support/core_ext/kernel/singleton_class.rb +2 -0
- data/lib/active_support/core_ext/kernel.rb +5 -5
- data/lib/active_support/core_ext/load_error.rb +3 -22
- data/lib/active_support/core_ext/marshal.rb +8 -8
- 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 -9
- data/lib/active_support/core_ext/module/attribute_accessors.rb +46 -46
- data/lib/active_support/core_ext/module/attribute_accessors_per_thread.rb +144 -0
- data/lib/active_support/core_ext/module/concerning.rb +11 -12
- data/lib/active_support/core_ext/module/delegation.rb +133 -30
- data/lib/active_support/core_ext/module/deprecation.rb +4 -2
- data/lib/active_support/core_ext/module/introspection.rb +44 -19
- data/lib/active_support/core_ext/module/reachable.rb +5 -7
- data/lib/active_support/core_ext/module/redefine_method.rb +40 -0
- data/lib/active_support/core_ext/module/remove_method.rb +8 -3
- data/lib/active_support/core_ext/module.rb +13 -11
- 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 +129 -136
- data/lib/active_support/core_ext/numeric/inquiry.rb +5 -0
- data/lib/active_support/core_ext/numeric/time.rb +35 -23
- data/lib/active_support/core_ext/numeric.rb +5 -3
- data/lib/active_support/core_ext/object/acts_like.rb +12 -1
- data/lib/active_support/core_ext/object/blank.rb +27 -3
- data/lib/active_support/core_ext/object/conversions.rb +6 -4
- data/lib/active_support/core_ext/object/deep_dup.rb +13 -4
- data/lib/active_support/core_ext/object/duplicable.rb +13 -93
- data/lib/active_support/core_ext/object/inclusion.rb +5 -3
- data/lib/active_support/core_ext/object/instance_variables.rb +3 -1
- data/lib/active_support/core_ext/object/json.rb +51 -20
- data/lib/active_support/core_ext/object/to_param.rb +3 -1
- data/lib/active_support/core_ext/object/to_query.rb +10 -5
- data/lib/active_support/core_ext/object/try.rb +81 -23
- data/lib/active_support/core_ext/object/with_options.rb +16 -3
- data/lib/active_support/core_ext/object.rb +14 -13
- data/lib/active_support/core_ext/range/compare_range.rb +76 -0
- data/lib/active_support/core_ext/range/conversions.rb +37 -15
- data/lib/active_support/core_ext/range/each.rb +18 -17
- data/lib/active_support/core_ext/range/include_range.rb +7 -21
- 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 +2 -0
- data/lib/active_support/core_ext/securerandom.rb +45 -0
- data/lib/active_support/core_ext/string/access.rb +16 -6
- data/lib/active_support/core_ext/string/behavior.rb +3 -1
- data/lib/active_support/core_ext/string/conversions.rb +7 -4
- data/lib/active_support/core_ext/string/exclude.rb +2 -0
- data/lib/active_support/core_ext/string/filters.rb +48 -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 +16 -7
- data/lib/active_support/core_ext/string/output_safety.rb +93 -40
- data/lib/active_support/core_ext/string/starts_ends_with.rb +2 -0
- data/lib/active_support/core_ext/string/strip.rb +6 -5
- data/lib/active_support/core_ext/string/zones.rb +4 -2
- 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 +115 -52
- data/lib/active_support/core_ext/time/compatibility.rb +4 -2
- data/lib/active_support/core_ext/time/conversions.rb +20 -13
- data/lib/active_support/core_ext/time/zones.rb +41 -7
- data/lib/active_support/core_ext/time.rb +7 -6
- data/lib/active_support/core_ext/uri.rb +6 -7
- data/lib/active_support/core_ext.rb +3 -1
- data/lib/active_support/current_attributes.rb +203 -0
- data/lib/active_support/dependencies/autoload.rb +2 -0
- data/lib/active_support/dependencies/interlock.rb +57 -0
- data/lib/active_support/dependencies/zeitwerk_integration.rb +117 -0
- data/lib/active_support/dependencies.rb +208 -166
- data/lib/active_support/deprecation/behaviors.rb +44 -11
- 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 +61 -21
- data/lib/active_support/deprecation/proxy_wrappers.rb +81 -30
- data/lib/active_support/deprecation/reporting.rb +32 -12
- data/lib/active_support/deprecation.rb +12 -9
- data/lib/active_support/descendants_tracker.rb +57 -9
- data/lib/active_support/digest.rb +20 -0
- data/lib/active_support/duration/iso8601_parser.rb +123 -0
- data/lib/active_support/duration/iso8601_serializer.rb +53 -0
- data/lib/active_support/duration.rb +315 -40
- data/lib/active_support/encrypted_configuration.rb +45 -0
- data/lib/active_support/encrypted_file.rb +100 -0
- data/lib/active_support/evented_file_update_checker.rb +234 -0
- data/lib/active_support/execution_wrapper.rb +129 -0
- data/lib/active_support/executor.rb +8 -0
- data/lib/active_support/file_update_checker.rb +62 -37
- data/lib/active_support/gem_version.rb +6 -4
- data/lib/active_support/gzip.rb +7 -5
- data/lib/active_support/hash_with_indifferent_access.rb +129 -30
- data/lib/active_support/i18n.rb +9 -6
- data/lib/active_support/i18n_railtie.rb +50 -14
- data/lib/active_support/inflections.rb +13 -11
- data/lib/active_support/inflector/inflections.rb +58 -13
- data/lib/active_support/inflector/methods.rb +159 -145
- data/lib/active_support/inflector/transliterate.rb +84 -34
- data/lib/active_support/inflector.rb +7 -5
- data/lib/active_support/json/decoding.rb +32 -30
- data/lib/active_support/json/encoding.rb +17 -60
- data/lib/active_support/json.rb +4 -2
- data/lib/active_support/key_generator.rb +11 -43
- data/lib/active_support/lazy_load_hooks.rb +53 -20
- data/lib/active_support/locale/en.rb +33 -0
- 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 +44 -19
- data/lib/active_support/logger.rb +9 -23
- data/lib/active_support/logger_silence.rb +32 -14
- data/lib/active_support/logger_thread_safe_level.rb +32 -8
- data/lib/active_support/message_encryptor.rb +166 -53
- data/lib/active_support/message_verifier.rb +149 -16
- data/lib/active_support/messages/metadata.rb +72 -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 +56 -63
- data/lib/active_support/multibyte/unicode.rb +56 -290
- data/lib/active_support/multibyte.rb +4 -2
- data/lib/active_support/notifications/fanout.rb +109 -22
- data/lib/active_support/notifications/instrumenter.rb +107 -16
- data/lib/active_support/notifications.rb +51 -10
- data/lib/active_support/number_helper/number_converter.rb +16 -15
- data/lib/active_support/number_helper/number_to_currency_converter.rb +14 -15
- data/lib/active_support/number_helper/number_to_delimited_converter.rb +11 -4
- data/lib/active_support/number_helper/number_to_human_converter.rb +13 -10
- data/lib/active_support/number_helper/number_to_human_size_converter.rb +11 -9
- data/lib/active_support/number_helper/number_to_percentage_converter.rb +5 -1
- data/lib/active_support/number_helper/number_to_phone_converter.rb +15 -5
- data/lib/active_support/number_helper/number_to_rounded_converter.rb +25 -57
- data/lib/active_support/number_helper/rounding_helper.rb +66 -0
- data/lib/active_support/number_helper.rb +105 -68
- data/lib/active_support/option_merger.rb +24 -4
- data/lib/active_support/ordered_hash.rb +7 -5
- data/lib/active_support/ordered_options.rb +27 -5
- data/lib/active_support/parameter_filter.rb +128 -0
- data/lib/active_support/per_thread_registry.rb +9 -4
- data/lib/active_support/proxy_object.rb +2 -0
- data/lib/active_support/rails.rb +10 -8
- data/lib/active_support/railtie.rb +43 -9
- data/lib/active_support/reloader.rb +130 -0
- data/lib/active_support/rescuable.rb +108 -53
- data/lib/active_support/security_utils.rb +15 -11
- data/lib/active_support/string_inquirer.rb +11 -4
- data/lib/active_support/subscriber.rb +74 -30
- data/lib/active_support/tagged_logging.rb +25 -13
- data/lib/active_support/test_case.rb +107 -44
- data/lib/active_support/testing/assertions.rb +151 -20
- data/lib/active_support/testing/autorun.rb +4 -2
- data/lib/active_support/testing/constant_lookup.rb +2 -1
- data/lib/active_support/testing/declarative.rb +3 -1
- data/lib/active_support/testing/deprecation.rb +13 -10
- data/lib/active_support/testing/file_fixtures.rb +38 -0
- data/lib/active_support/testing/isolation.rb +35 -26
- data/lib/active_support/testing/method_call_assertions.rb +70 -0
- data/lib/active_support/testing/parallelization.rb +134 -0
- data/lib/active_support/testing/setup_and_teardown.rb +13 -8
- data/lib/active_support/testing/stream.rb +43 -0
- data/lib/active_support/testing/tagged_logging.rb +3 -1
- data/lib/active_support/testing/time_helpers.rb +84 -20
- data/lib/active_support/time.rb +14 -12
- data/lib/active_support/time_with_zone.rb +179 -39
- data/lib/active_support/values/time_zone.rb +203 -63
- data/lib/active_support/version.rb +3 -1
- data/lib/active_support/xml_mini/jdom.rb +116 -115
- data/lib/active_support/xml_mini/libxml.rb +16 -13
- data/lib/active_support/xml_mini/libxmlsax.rb +15 -14
- data/lib/active_support/xml_mini/nokogiri.rb +14 -12
- data/lib/active_support/xml_mini/nokogirisax.rb +14 -13
- data/lib/active_support/xml_mini/rexml.rb +11 -9
- data/lib/active_support/xml_mini.rb +38 -46
- data/lib/active_support.rb +13 -11
- metadata +84 -26
- data/lib/active_support/concurrency/latch.rb +0 -27
- data/lib/active_support/core_ext/big_decimal/yaml_conversions.rb +0 -16
- data/lib/active_support/core_ext/class/delegating_attributes.rb +0 -45
- data/lib/active_support/core_ext/date_time/zones.rb +0 -6
- data/lib/active_support/core_ext/kernel/agnostics.rb +0 -11
- data/lib/active_support/core_ext/kernel/debugger.rb +0 -10
- data/lib/active_support/core_ext/module/method_transplanting.rb +0 -13
- data/lib/active_support/core_ext/module/qualified_const.rb +0 -52
- data/lib/active_support/core_ext/object/itself.rb +0 -15
- data/lib/active_support/core_ext/struct.rb +0 -6
- data/lib/active_support/core_ext/thread.rb +0 -86
- data/lib/active_support/core_ext/time/marshal.rb +0 -30
- data/lib/active_support/values/unicode_tables.dat +0 -0
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class Object
|
2
4
|
# Returns true if this object is included in the argument. Argument must be
|
3
5
|
# any object which responds to +#include?+. Usage:
|
@@ -5,7 +7,7 @@ class Object
|
|
5
7
|
# characters = ["Konata", "Kagami", "Tsukasa"]
|
6
8
|
# "Konata".in?(characters) # => true
|
7
9
|
#
|
8
|
-
# This will throw an ArgumentError if the argument doesn't respond
|
10
|
+
# This will throw an +ArgumentError+ if the argument doesn't respond
|
9
11
|
# to +#include?+.
|
10
12
|
def in?(another_object)
|
11
13
|
another_object.include?(self)
|
@@ -18,10 +20,10 @@ class Object
|
|
18
20
|
#
|
19
21
|
# params[:bucket_type].presence_in %w( project calendar )
|
20
22
|
#
|
21
|
-
# This will throw an ArgumentError if the argument doesn't respond to +#include?+.
|
23
|
+
# This will throw an +ArgumentError+ if the argument doesn't respond to +#include?+.
|
22
24
|
#
|
23
25
|
# @return [Object]
|
24
26
|
def presence_in(another_object)
|
25
|
-
|
27
|
+
in?(another_object) ? self : nil
|
26
28
|
end
|
27
29
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class Object
|
2
4
|
# Returns a hash with string keys that maps instance variable names without "@" to their
|
3
5
|
# corresponding values.
|
@@ -23,6 +25,6 @@ class Object
|
|
23
25
|
#
|
24
26
|
# C.new(0, 1).instance_variable_names # => ["@y", "@x"]
|
25
27
|
def instance_variable_names
|
26
|
-
instance_variables.map
|
28
|
+
instance_variables.map(&:to_s)
|
27
29
|
end
|
28
30
|
end
|
@@ -1,16 +1,20 @@
|
|
1
|
-
#
|
2
|
-
require 'json'
|
3
|
-
require 'bigdecimal'
|
4
|
-
require 'active_support/core_ext/big_decimal/conversions' # for #to_s
|
5
|
-
require 'active_support/core_ext/hash/except'
|
6
|
-
require 'active_support/core_ext/hash/slice'
|
7
|
-
require 'active_support/core_ext/object/instance_variables'
|
8
|
-
require 'time'
|
9
|
-
require 'active_support/core_ext/time/conversions'
|
10
|
-
require 'active_support/core_ext/date_time/conversions'
|
11
|
-
require 'active_support/core_ext/date/conversions'
|
12
|
-
require 'active_support/core_ext/module/aliasing'
|
1
|
+
# frozen_string_literal: true
|
13
2
|
|
3
|
+
# Hack to load json gem first so we can overwrite its to_json.
|
4
|
+
require "json"
|
5
|
+
require "bigdecimal"
|
6
|
+
require "uri/generic"
|
7
|
+
require "pathname"
|
8
|
+
require "active_support/core_ext/big_decimal/conversions" # for #to_s
|
9
|
+
require "active_support/core_ext/hash/except"
|
10
|
+
require "active_support/core_ext/hash/slice"
|
11
|
+
require "active_support/core_ext/object/instance_variables"
|
12
|
+
require "time"
|
13
|
+
require "active_support/core_ext/time/conversions"
|
14
|
+
require "active_support/core_ext/date_time/conversions"
|
15
|
+
require "active_support/core_ext/date/conversions"
|
16
|
+
|
17
|
+
#--
|
14
18
|
# The JSON gem adds a few modules to Ruby core classes containing :to_json definition, overwriting
|
15
19
|
# their default behavior. That said, we need to define the basic to_json method in all of them,
|
16
20
|
# otherwise they will always use to_json gem implementation, which is backwards incompatible in
|
@@ -26,22 +30,25 @@ require 'active_support/core_ext/module/aliasing'
|
|
26
30
|
# bypassed completely. This means that as_json won't be invoked and the JSON gem will simply
|
27
31
|
# ignore any options it does not natively understand. This also means that ::JSON.{generate,dump}
|
28
32
|
# should give exactly the same results with or without active support.
|
29
|
-
|
30
|
-
|
31
|
-
|
33
|
+
|
34
|
+
module ActiveSupport
|
35
|
+
module ToJsonWithActiveSupportEncoder # :nodoc:
|
36
|
+
def to_json(options = nil)
|
32
37
|
if options.is_a?(::JSON::State)
|
33
38
|
# Called from JSON.{generate,dump}, forward it to JSON gem's to_json
|
34
|
-
|
39
|
+
super(options)
|
35
40
|
else
|
36
41
|
# to_json is being invoked directly, use ActiveSupport's encoder
|
37
42
|
ActiveSupport::JSON.encode(self, options)
|
38
43
|
end
|
39
44
|
end
|
40
|
-
|
41
|
-
alias_method_chain :to_json, :active_support_encoder
|
42
45
|
end
|
43
46
|
end
|
44
47
|
|
48
|
+
[Object, Array, FalseClass, Float, Hash, Integer, NilClass, String, TrueClass, Enumerable].reverse_each do |klass|
|
49
|
+
klass.prepend(ActiveSupport::ToJsonWithActiveSupportEncoder)
|
50
|
+
end
|
51
|
+
|
45
52
|
class Object
|
46
53
|
def as_json(options = nil) #:nodoc:
|
47
54
|
if respond_to?(:to_hash)
|
@@ -129,6 +136,12 @@ module Enumerable
|
|
129
136
|
end
|
130
137
|
end
|
131
138
|
|
139
|
+
class IO
|
140
|
+
def as_json(options = nil) #:nodoc:
|
141
|
+
to_s
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
132
145
|
class Range
|
133
146
|
def as_json(options = nil) #:nodoc:
|
134
147
|
to_s
|
@@ -185,13 +198,31 @@ class DateTime
|
|
185
198
|
if ActiveSupport::JSON::Encoding.use_standard_json_time_format
|
186
199
|
xmlschema(ActiveSupport::JSON::Encoding.time_precision)
|
187
200
|
else
|
188
|
-
strftime(
|
201
|
+
strftime("%Y/%m/%d %H:%M:%S %z")
|
189
202
|
end
|
190
203
|
end
|
191
204
|
end
|
192
205
|
|
206
|
+
class URI::Generic #:nodoc:
|
207
|
+
def as_json(options = nil)
|
208
|
+
to_s
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
class Pathname #:nodoc:
|
213
|
+
def as_json(options = nil)
|
214
|
+
to_s
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
193
218
|
class Process::Status #:nodoc:
|
194
219
|
def as_json(options = nil)
|
195
|
-
{ :
|
220
|
+
{ exitstatus: exitstatus, pid: pid }
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
224
|
+
class Exception
|
225
|
+
def as_json(options = nil)
|
226
|
+
to_s
|
196
227
|
end
|
197
228
|
end
|
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "cgi"
|
2
4
|
|
3
5
|
class Object
|
4
6
|
# Alias of <tt>to_s</tt>.
|
@@ -38,7 +40,7 @@ class Array
|
|
38
40
|
# Calls <tt>to_param</tt> on all its elements and joins the result with
|
39
41
|
# slashes. This is used by <tt>url_for</tt> in Action Pack.
|
40
42
|
def to_param
|
41
|
-
collect
|
43
|
+
collect(&:to_param).join "/"
|
42
44
|
end
|
43
45
|
|
44
46
|
# Converts an array into a string suitable for use as a URL query string,
|
@@ -51,7 +53,7 @@ class Array
|
|
51
53
|
if empty?
|
52
54
|
nil.to_query(prefix)
|
53
55
|
else
|
54
|
-
collect { |value| value.to_query(prefix) }.join
|
56
|
+
collect { |value| value.to_query(prefix) }.join "&"
|
55
57
|
end
|
56
58
|
end
|
57
59
|
end
|
@@ -73,11 +75,14 @@ class Hash
|
|
73
75
|
#
|
74
76
|
# This method is also aliased as +to_param+.
|
75
77
|
def to_query(namespace = nil)
|
76
|
-
collect do |key, value|
|
78
|
+
query = collect do |key, value|
|
77
79
|
unless (value.is_a?(Hash) || value.is_a?(Array)) && value.empty?
|
78
80
|
value.to_query(namespace ? "#{namespace}[#{key}]" : key)
|
79
81
|
end
|
80
|
-
end.compact
|
82
|
+
end.compact
|
83
|
+
|
84
|
+
query.sort! unless namespace.to_s.include?("[]")
|
85
|
+
query.join("&")
|
81
86
|
end
|
82
87
|
|
83
88
|
alias_method :to_param, :to_query
|
@@ -1,4 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "delegate"
|
4
|
+
|
5
|
+
module ActiveSupport
|
6
|
+
module Tryable #:nodoc:
|
7
|
+
def try(method_name = nil, *args, &b)
|
8
|
+
if method_name.nil? && block_given?
|
9
|
+
if b.arity == 0
|
10
|
+
instance_eval(&b)
|
11
|
+
else
|
12
|
+
yield self
|
13
|
+
end
|
14
|
+
elsif respond_to?(method_name)
|
15
|
+
public_send(method_name, *args, &b)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
ruby2_keywords(:try) if respond_to?(:ruby2_keywords, true)
|
19
|
+
|
20
|
+
def try!(method_name = nil, *args, &b)
|
21
|
+
if method_name.nil? && block_given?
|
22
|
+
if b.arity == 0
|
23
|
+
instance_eval(&b)
|
24
|
+
else
|
25
|
+
yield self
|
26
|
+
end
|
27
|
+
else
|
28
|
+
public_send(method_name, *args, &b)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
ruby2_keywords(:try!) if respond_to?(:ruby2_keywords, true)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
1
35
|
class Object
|
36
|
+
include ActiveSupport::Tryable
|
37
|
+
|
38
|
+
##
|
39
|
+
# :method: try
|
40
|
+
#
|
41
|
+
# :call-seq:
|
42
|
+
# try(*a, &b)
|
43
|
+
#
|
2
44
|
# Invokes the public method whose name goes as first argument just like
|
3
45
|
# +public_send+ does, except that if the receiver does not respond to it the
|
4
46
|
# call returns +nil+ rather than raising an exception.
|
@@ -21,11 +63,11 @@ class Object
|
|
21
63
|
#
|
22
64
|
# +try+ will also return +nil+ if the receiver does not respond to the method:
|
23
65
|
#
|
24
|
-
# @person.try(:non_existing_method)
|
66
|
+
# @person.try(:non_existing_method) # => nil
|
25
67
|
#
|
26
68
|
# instead of
|
27
69
|
#
|
28
|
-
# @person.non_existing_method if @person.respond_to?(:non_existing_method)
|
70
|
+
# @person.non_existing_method if @person.respond_to?(:non_existing_method) # => nil
|
29
71
|
#
|
30
72
|
# +try+ returns +nil+ when called on +nil+ regardless of whether it responds
|
31
73
|
# to the method:
|
@@ -56,27 +98,40 @@ class Object
|
|
56
98
|
#
|
57
99
|
# Please also note that +try+ is defined on +Object+. Therefore, it won't work
|
58
100
|
# with instances of classes that do not have +Object+ among their ancestors,
|
59
|
-
# like direct subclasses of +BasicObject+.
|
60
|
-
# +SimpleDelegator+ will delegate +try+ to the target instead of calling it on
|
61
|
-
# the delegator itself.
|
62
|
-
def try(*a, &b)
|
63
|
-
try!(*a, &b) if a.empty? || respond_to?(a.first)
|
64
|
-
end
|
101
|
+
# like direct subclasses of +BasicObject+.
|
65
102
|
|
66
|
-
|
67
|
-
#
|
103
|
+
##
|
104
|
+
# :method: try!
|
105
|
+
#
|
106
|
+
# :call-seq:
|
107
|
+
# try!(*a, &b)
|
108
|
+
#
|
109
|
+
# Same as #try, but raises a +NoMethodError+ exception if the receiver is
|
110
|
+
# not +nil+ and does not implement the tried method.
|
111
|
+
#
|
112
|
+
# "a".try!(:upcase) # => "A"
|
113
|
+
# nil.try!(:upcase) # => nil
|
114
|
+
# 123.try!(:upcase) # => NoMethodError: undefined method `upcase' for 123:Integer
|
115
|
+
end
|
68
116
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
117
|
+
class Delegator
|
118
|
+
include ActiveSupport::Tryable
|
119
|
+
|
120
|
+
##
|
121
|
+
# :method: try
|
122
|
+
#
|
123
|
+
# :call-seq:
|
124
|
+
# try(a*, &b)
|
125
|
+
#
|
126
|
+
# See Object#try
|
127
|
+
|
128
|
+
##
|
129
|
+
# :method: try!
|
130
|
+
#
|
131
|
+
# :call-seq:
|
132
|
+
# try!(a*, &b)
|
133
|
+
#
|
134
|
+
# See Object#try!
|
80
135
|
end
|
81
136
|
|
82
137
|
class NilClass
|
@@ -90,11 +145,14 @@ class NilClass
|
|
90
145
|
#
|
91
146
|
# With +try+
|
92
147
|
# @person.try(:children).try(:first).try(:name)
|
93
|
-
def try(*args)
|
148
|
+
def try(method_name = nil, *args)
|
94
149
|
nil
|
95
150
|
end
|
96
151
|
|
97
|
-
|
152
|
+
# Calling +try!+ on +nil+ always returns +nil+.
|
153
|
+
#
|
154
|
+
# nil.try!(:name) # => nil
|
155
|
+
def try!(method_name = nil, *args)
|
98
156
|
nil
|
99
157
|
end
|
100
158
|
end
|
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_support/option_merger"
|
2
4
|
|
3
5
|
class Object
|
4
6
|
# An elegant way to factor duplication out of options passed to a series of
|
@@ -7,7 +9,7 @@ class Object
|
|
7
9
|
# provided. Each method called on the block variable must take an options
|
8
10
|
# hash as its final argument.
|
9
11
|
#
|
10
|
-
# Without <tt>with_options
|
12
|
+
# Without <tt>with_options</tt>, this code contains duplication:
|
11
13
|
#
|
12
14
|
# class Account < ActiveRecord::Base
|
13
15
|
# has_many :customers, dependent: :destroy
|
@@ -60,7 +62,18 @@ class Object
|
|
60
62
|
#
|
61
63
|
# validates :content, length: { minimum: 50 }, if: -> { content.present? }
|
62
64
|
#
|
63
|
-
# Hence the inherited default for
|
65
|
+
# Hence the inherited default for +if+ key is ignored.
|
66
|
+
#
|
67
|
+
# NOTE: You cannot call class methods implicitly inside of with_options.
|
68
|
+
# You can access these methods using the class name instead:
|
69
|
+
#
|
70
|
+
# class Phone < ActiveRecord::Base
|
71
|
+
# enum phone_number_type: { home: 0, office: 1, mobile: 2 }
|
72
|
+
#
|
73
|
+
# with_options presence: true do
|
74
|
+
# validates :phone_number_type, inclusion: { in: Phone.phone_number_types.keys }
|
75
|
+
# end
|
76
|
+
# end
|
64
77
|
#
|
65
78
|
def with_options(options, &block)
|
66
79
|
option_merger = ActiveSupport::OptionMerger.new(self, options)
|
@@ -1,15 +1,16 @@
|
|
1
|
-
|
2
|
-
require 'active_support/core_ext/object/blank'
|
3
|
-
require 'active_support/core_ext/object/duplicable'
|
4
|
-
require 'active_support/core_ext/object/deep_dup'
|
5
|
-
require 'active_support/core_ext/object/itself'
|
6
|
-
require 'active_support/core_ext/object/try'
|
7
|
-
require 'active_support/core_ext/object/inclusion'
|
1
|
+
# frozen_string_literal: true
|
8
2
|
|
9
|
-
require
|
10
|
-
require
|
3
|
+
require "active_support/core_ext/object/acts_like"
|
4
|
+
require "active_support/core_ext/object/blank"
|
5
|
+
require "active_support/core_ext/object/duplicable"
|
6
|
+
require "active_support/core_ext/object/deep_dup"
|
7
|
+
require "active_support/core_ext/object/try"
|
8
|
+
require "active_support/core_ext/object/inclusion"
|
11
9
|
|
12
|
-
require
|
13
|
-
require
|
14
|
-
|
15
|
-
require
|
10
|
+
require "active_support/core_ext/object/conversions"
|
11
|
+
require "active_support/core_ext/object/instance_variables"
|
12
|
+
|
13
|
+
require "active_support/core_ext/object/json"
|
14
|
+
require "active_support/core_ext/object/to_param"
|
15
|
+
require "active_support/core_ext/object/to_query"
|
16
|
+
require "active_support/core_ext/object/with_options"
|
@@ -0,0 +1,76 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ActiveSupport
|
4
|
+
module CompareWithRange
|
5
|
+
# Extends the default Range#=== to support range comparisons.
|
6
|
+
# (1..5) === (1..5) # => true
|
7
|
+
# (1..5) === (2..3) # => true
|
8
|
+
# (1..5) === (1...6) # => true
|
9
|
+
# (1..5) === (2..6) # => false
|
10
|
+
#
|
11
|
+
# The native Range#=== behavior is untouched.
|
12
|
+
# ('a'..'f') === ('c') # => true
|
13
|
+
# (5..9) === (11) # => false
|
14
|
+
#
|
15
|
+
# The given range must be fully bounded, with both start and end.
|
16
|
+
def ===(value)
|
17
|
+
if value.is_a?(::Range)
|
18
|
+
# 1...10 includes 1..9 but it does not include 1..10.
|
19
|
+
# 1..10 includes 1...11 but it does not include 1...12.
|
20
|
+
operator = exclude_end? && !value.exclude_end? ? :< : :<=
|
21
|
+
value_max = !exclude_end? && value.exclude_end? ? value.max : value.last
|
22
|
+
super(value.first) && (self.end.nil? || value_max.send(operator, last))
|
23
|
+
else
|
24
|
+
super
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# Extends the default Range#include? to support range comparisons.
|
29
|
+
# (1..5).include?(1..5) # => true
|
30
|
+
# (1..5).include?(2..3) # => true
|
31
|
+
# (1..5).include?(1...6) # => true
|
32
|
+
# (1..5).include?(2..6) # => false
|
33
|
+
#
|
34
|
+
# The native Range#include? behavior is untouched.
|
35
|
+
# ('a'..'f').include?('c') # => true
|
36
|
+
# (5..9).include?(11) # => false
|
37
|
+
#
|
38
|
+
# The given range must be fully bounded, with both start and end.
|
39
|
+
def include?(value)
|
40
|
+
if value.is_a?(::Range)
|
41
|
+
# 1...10 includes 1..9 but it does not include 1..10.
|
42
|
+
# 1..10 includes 1...11 but it does not include 1...12.
|
43
|
+
operator = exclude_end? && !value.exclude_end? ? :< : :<=
|
44
|
+
value_max = !exclude_end? && value.exclude_end? ? value.max : value.last
|
45
|
+
super(value.first) && (self.end.nil? || value_max.send(operator, last))
|
46
|
+
else
|
47
|
+
super
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
# Extends the default Range#cover? to support range comparisons.
|
52
|
+
# (1..5).cover?(1..5) # => true
|
53
|
+
# (1..5).cover?(2..3) # => true
|
54
|
+
# (1..5).cover?(1...6) # => true
|
55
|
+
# (1..5).cover?(2..6) # => false
|
56
|
+
#
|
57
|
+
# The native Range#cover? behavior is untouched.
|
58
|
+
# ('a'..'f').cover?('c') # => true
|
59
|
+
# (5..9).cover?(11) # => false
|
60
|
+
#
|
61
|
+
# The given range must be fully bounded, with both start and end.
|
62
|
+
def cover?(value)
|
63
|
+
if value.is_a?(::Range)
|
64
|
+
# 1...10 covers 1..9 but it does not cover 1..10.
|
65
|
+
# 1..10 covers 1...11 but it does not cover 1...12.
|
66
|
+
operator = exclude_end? && !value.exclude_end? ? :< : :<=
|
67
|
+
value_max = !exclude_end? && value.exclude_end? ? value.max : value.last
|
68
|
+
super(value.first) && (self.end.nil? || value_max.send(operator, last))
|
69
|
+
else
|
70
|
+
super
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
Range.prepend(ActiveSupport::CompareWithRange)
|
@@ -1,19 +1,41 @@
|
|
1
|
-
|
2
|
-
RANGE_FORMATS = {
|
3
|
-
:db => Proc.new { |start, stop| "BETWEEN '#{start.to_s(:db)}' AND '#{stop.to_s(:db)}'" }
|
4
|
-
}
|
1
|
+
# frozen_string_literal: true
|
5
2
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
3
|
+
module ActiveSupport
|
4
|
+
module RangeWithFormat
|
5
|
+
RANGE_FORMATS = {
|
6
|
+
db: -> (start, stop) do
|
7
|
+
case start
|
8
|
+
when String then "BETWEEN '#{start}' AND '#{stop}'"
|
9
|
+
else
|
10
|
+
"BETWEEN '#{start.to_s(:db)}' AND '#{stop.to_s(:db)}'"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
}
|
14
|
+
|
15
|
+
# Convert range to a formatted string. See RANGE_FORMATS for predefined formats.
|
16
|
+
#
|
17
|
+
# range = (1..100) # => 1..100
|
18
|
+
#
|
19
|
+
# range.to_s # => "1..100"
|
20
|
+
# range.to_s(:db) # => "BETWEEN '1' AND '100'"
|
21
|
+
#
|
22
|
+
# == Adding your own range formats to to_s
|
23
|
+
# You can add your own formats to the Range::RANGE_FORMATS hash.
|
24
|
+
# Use the format name as the hash key and a Proc instance.
|
25
|
+
#
|
26
|
+
# # config/initializers/range_formats.rb
|
27
|
+
# Range::RANGE_FORMATS[:short] = ->(start, stop) { "Between #{start.to_s(:db)} and #{stop.to_s(:db)}" }
|
28
|
+
def to_s(format = :default)
|
29
|
+
if formatter = RANGE_FORMATS[format]
|
30
|
+
formatter.call(first, last)
|
31
|
+
else
|
32
|
+
super()
|
33
|
+
end
|
14
34
|
end
|
15
|
-
end
|
16
35
|
|
17
|
-
|
18
|
-
|
36
|
+
alias_method :to_default_s, :to_s
|
37
|
+
alias_method :to_formatted_s, :to_s
|
38
|
+
end
|
19
39
|
end
|
40
|
+
|
41
|
+
Range.prepend(ActiveSupport::RangeWithFormat)
|
@@ -1,23 +1,24 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
require "active_support/time_with_zone"
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
def step_with_time_with_zone(n = 1, &block)
|
12
|
-
ensure_iteration_allowed
|
13
|
-
step_without_time_with_zone(n, &block)
|
14
|
-
end
|
15
|
-
alias_method_chain :step, :time_with_zone
|
5
|
+
module ActiveSupport
|
6
|
+
module EachTimeWithZone #:nodoc:
|
7
|
+
def each(&block)
|
8
|
+
ensure_iteration_allowed
|
9
|
+
super
|
10
|
+
end
|
16
11
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
raise TypeError, "can't iterate from #{first.class}"
|
12
|
+
def step(n = 1, &block)
|
13
|
+
ensure_iteration_allowed
|
14
|
+
super
|
21
15
|
end
|
16
|
+
|
17
|
+
private
|
18
|
+
def ensure_iteration_allowed
|
19
|
+
raise TypeError, "can't iterate from #{first.class}" if first.is_a?(TimeWithZone)
|
20
|
+
end
|
22
21
|
end
|
23
22
|
end
|
23
|
+
|
24
|
+
Range.prepend(ActiveSupport::EachTimeWithZone)
|
@@ -1,23 +1,9 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
# Extends the default Range#include? to support range comparisons.
|
5
|
-
# (1..5).include?(1..5) # => true
|
6
|
-
# (1..5).include?(2..3) # => true
|
7
|
-
# (1..5).include?(2..6) # => false
|
8
|
-
#
|
9
|
-
# The native Range#include? behavior is untouched.
|
10
|
-
# ('a'..'f').include?('c') # => true
|
11
|
-
# (5..9).include?(11) # => false
|
12
|
-
def include_with_range?(value)
|
13
|
-
if value.is_a?(::Range)
|
14
|
-
# 1...10 includes 1..9 but it does not include 1..10.
|
15
|
-
operator = exclude_end? && !value.exclude_end? ? :< : :<=
|
16
|
-
include_without_range?(value.first) && value.last.send(operator, last)
|
17
|
-
else
|
18
|
-
include_without_range?(value)
|
19
|
-
end
|
20
|
-
end
|
3
|
+
require "active_support/deprecation"
|
21
4
|
|
22
|
-
|
23
|
-
|
5
|
+
ActiveSupport::Deprecation.warn "You have required `active_support/core_ext/range/include_range`. " \
|
6
|
+
"This file will be removed in Rails 6.1. You should require `active_support/core_ext/range/compare_range` " \
|
7
|
+
"instead."
|
8
|
+
|
9
|
+
require "active_support/core_ext/range/compare_range"
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_support/time_with_zone"
|
4
|
+
|
5
|
+
module ActiveSupport
|
6
|
+
module IncludeTimeWithZone #:nodoc:
|
7
|
+
# Extends the default Range#include? to support ActiveSupport::TimeWithZone.
|
8
|
+
#
|
9
|
+
# (1.hour.ago..1.hour.from_now).include?(Time.current) # => true
|
10
|
+
#
|
11
|
+
def include?(value)
|
12
|
+
if self.begin.is_a?(TimeWithZone)
|
13
|
+
cover?(value)
|
14
|
+
elsif self.end.is_a?(TimeWithZone)
|
15
|
+
cover?(value)
|
16
|
+
else
|
17
|
+
super
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
Range.prepend(ActiveSupport::IncludeTimeWithZone)
|
@@ -1,4 +1,7 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require
|
4
|
-
require
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_support/core_ext/range/conversions"
|
4
|
+
require "active_support/core_ext/range/compare_range"
|
5
|
+
require "active_support/core_ext/range/include_time_with_zone"
|
6
|
+
require "active_support/core_ext/range/overlaps"
|
7
|
+
require "active_support/core_ext/range/each"
|