activesupport 7.0.7.2 → 7.1.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +742 -285
- data/MIT-LICENSE +1 -1
- data/README.rdoc +4 -4
- data/lib/active_support/actionable_error.rb +3 -1
- data/lib/active_support/array_inquirer.rb +2 -0
- data/lib/active_support/backtrace_cleaner.rb +25 -5
- data/lib/active_support/benchmarkable.rb +1 -0
- data/lib/active_support/builder.rb +1 -1
- data/lib/active_support/cache/coder.rb +153 -0
- data/lib/active_support/cache/entry.rb +128 -0
- data/lib/active_support/cache/file_store.rb +36 -9
- data/lib/active_support/cache/mem_cache_store.rb +84 -68
- data/lib/active_support/cache/memory_store.rb +76 -24
- data/lib/active_support/cache/null_store.rb +6 -0
- data/lib/active_support/cache/redis_cache_store.rb +128 -131
- data/lib/active_support/cache/serializer_with_fallback.rb +175 -0
- data/lib/active_support/cache/strategy/local_cache.rb +20 -8
- data/lib/active_support/cache.rb +304 -246
- data/lib/active_support/callbacks.rb +38 -18
- data/lib/active_support/concern.rb +4 -2
- data/lib/active_support/concurrency/load_interlock_aware_monitor.rb +42 -3
- data/lib/active_support/concurrency/null_lock.rb +13 -0
- data/lib/active_support/configurable.rb +10 -0
- data/lib/active_support/core_ext/array/conversions.rb +2 -1
- data/lib/active_support/core_ext/array.rb +0 -1
- data/lib/active_support/core_ext/class/subclasses.rb +13 -10
- data/lib/active_support/core_ext/date/conversions.rb +1 -0
- data/lib/active_support/core_ext/date.rb +0 -1
- data/lib/active_support/core_ext/date_and_time/calculations.rb +10 -0
- data/lib/active_support/core_ext/date_time/conversions.rb +6 -2
- data/lib/active_support/core_ext/date_time.rb +0 -1
- data/lib/active_support/core_ext/digest/uuid.rb +1 -10
- data/lib/active_support/core_ext/enumerable.rb +3 -75
- data/lib/active_support/core_ext/erb/util.rb +196 -0
- data/lib/active_support/core_ext/hash/conversions.rb +1 -1
- data/lib/active_support/core_ext/module/attribute_accessors.rb +6 -0
- data/lib/active_support/core_ext/module/attribute_accessors_per_thread.rb +34 -16
- data/lib/active_support/core_ext/module/delegation.rb +40 -11
- data/lib/active_support/core_ext/module/deprecation.rb +15 -12
- data/lib/active_support/core_ext/module/introspection.rb +0 -1
- data/lib/active_support/core_ext/numeric/bytes.rb +9 -0
- data/lib/active_support/core_ext/numeric/conversions.rb +2 -0
- data/lib/active_support/core_ext/numeric.rb +0 -1
- data/lib/active_support/core_ext/object/deep_dup.rb +16 -0
- data/lib/active_support/core_ext/object/inclusion.rb +13 -5
- data/lib/active_support/core_ext/object/instance_variables.rb +22 -12
- data/lib/active_support/core_ext/object/json.rb +10 -2
- data/lib/active_support/core_ext/object/with.rb +44 -0
- data/lib/active_support/core_ext/object/with_options.rb +3 -3
- data/lib/active_support/core_ext/object.rb +1 -0
- data/lib/active_support/core_ext/pathname/blank.rb +16 -0
- data/lib/active_support/core_ext/pathname/existence.rb +2 -0
- data/lib/active_support/core_ext/pathname.rb +1 -0
- data/lib/active_support/core_ext/range/conversions.rb +28 -7
- data/lib/active_support/core_ext/range/{overlaps.rb → overlap.rb} +5 -3
- data/lib/active_support/core_ext/range.rb +1 -2
- data/lib/active_support/core_ext/securerandom.rb +24 -12
- data/lib/active_support/core_ext/string/filters.rb +20 -14
- data/lib/active_support/core_ext/string/inflections.rb +16 -5
- data/lib/active_support/core_ext/string/output_safety.rb +38 -174
- data/lib/active_support/core_ext/thread/backtrace/location.rb +12 -0
- data/lib/active_support/core_ext/time/calculations.rb +18 -2
- data/lib/active_support/core_ext/time/conversions.rb +2 -2
- data/lib/active_support/core_ext/time/zones.rb +4 -4
- data/lib/active_support/core_ext/time.rb +0 -1
- data/lib/active_support/current_attributes.rb +15 -6
- data/lib/active_support/dependencies/autoload.rb +17 -12
- data/lib/active_support/deprecation/behaviors.rb +53 -32
- data/lib/active_support/deprecation/constant_accessor.rb +5 -4
- data/lib/active_support/deprecation/deprecators.rb +104 -0
- data/lib/active_support/deprecation/disallowed.rb +3 -5
- data/lib/active_support/deprecation/instance_delegator.rb +31 -4
- data/lib/active_support/deprecation/method_wrappers.rb +6 -23
- data/lib/active_support/deprecation/proxy_wrappers.rb +37 -22
- data/lib/active_support/deprecation/reporting.rb +35 -21
- data/lib/active_support/deprecation.rb +32 -5
- data/lib/active_support/deprecator.rb +7 -0
- data/lib/active_support/descendants_tracker.rb +104 -132
- data/lib/active_support/duration/iso8601_serializer.rb +0 -2
- data/lib/active_support/duration.rb +2 -1
- data/lib/active_support/encrypted_configuration.rb +30 -9
- data/lib/active_support/encrypted_file.rb +8 -3
- data/lib/active_support/environment_inquirer.rb +22 -2
- data/lib/active_support/error_reporter/test_helper.rb +15 -0
- data/lib/active_support/error_reporter.rb +121 -35
- data/lib/active_support/execution_wrapper.rb +4 -4
- data/lib/active_support/file_update_checker.rb +4 -2
- data/lib/active_support/fork_tracker.rb +10 -2
- data/lib/active_support/gem_version.rb +4 -4
- data/lib/active_support/gzip.rb +2 -0
- data/lib/active_support/hash_with_indifferent_access.rb +35 -17
- data/lib/active_support/i18n.rb +1 -1
- data/lib/active_support/i18n_railtie.rb +20 -13
- data/lib/active_support/inflector/inflections.rb +2 -0
- data/lib/active_support/inflector/methods.rb +22 -10
- data/lib/active_support/inflector/transliterate.rb +3 -1
- data/lib/active_support/isolated_execution_state.rb +26 -22
- data/lib/active_support/json/decoding.rb +2 -1
- data/lib/active_support/json/encoding.rb +25 -43
- data/lib/active_support/key_generator.rb +9 -1
- data/lib/active_support/lazy_load_hooks.rb +6 -4
- data/lib/active_support/locale/en.yml +2 -0
- data/lib/active_support/log_subscriber.rb +78 -33
- data/lib/active_support/logger.rb +1 -1
- data/lib/active_support/logger_thread_safe_level.rb +9 -21
- data/lib/active_support/message_encryptor.rb +197 -53
- data/lib/active_support/message_encryptors.rb +140 -0
- data/lib/active_support/message_pack/cache_serializer.rb +23 -0
- data/lib/active_support/message_pack/extensions.rb +292 -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 +212 -93
- data/lib/active_support/message_verifiers.rb +134 -0
- data/lib/active_support/messages/codec.rb +65 -0
- data/lib/active_support/messages/metadata.rb +111 -45
- data/lib/active_support/messages/rotation_coordinator.rb +93 -0
- data/lib/active_support/messages/rotator.rb +34 -32
- data/lib/active_support/messages/serializer_with_fallback.rb +158 -0
- data/lib/active_support/multibyte/chars.rb +2 -0
- data/lib/active_support/multibyte/unicode.rb +9 -37
- data/lib/active_support/notifications/fanout.rb +239 -81
- data/lib/active_support/notifications/instrumenter.rb +71 -14
- data/lib/active_support/notifications.rb +1 -1
- data/lib/active_support/number_helper/number_converter.rb +2 -2
- data/lib/active_support/number_helper/number_to_human_size_converter.rb +1 -1
- data/lib/active_support/number_helper/number_to_phone_converter.rb +1 -0
- data/lib/active_support/ordered_hash.rb +3 -3
- data/lib/active_support/ordered_options.rb +14 -0
- data/lib/active_support/parameter_filter.rb +84 -69
- data/lib/active_support/proxy_object.rb +2 -0
- data/lib/active_support/railtie.rb +33 -21
- data/lib/active_support/reloader.rb +12 -4
- data/lib/active_support/rescuable.rb +2 -0
- data/lib/active_support/secure_compare_rotator.rb +16 -9
- data/lib/active_support/string_inquirer.rb +3 -1
- data/lib/active_support/subscriber.rb +9 -27
- data/lib/active_support/syntax_error_proxy.rb +49 -0
- data/lib/active_support/tagged_logging.rb +60 -24
- data/lib/active_support/test_case.rb +153 -6
- data/lib/active_support/testing/assertions.rb +25 -9
- data/lib/active_support/testing/autorun.rb +0 -2
- data/lib/active_support/testing/constant_stubbing.rb +32 -0
- data/lib/active_support/testing/deprecation.rb +25 -25
- data/lib/active_support/testing/error_reporter_assertions.rb +108 -0
- data/lib/active_support/testing/isolation.rb +1 -1
- data/lib/active_support/testing/method_call_assertions.rb +21 -8
- data/lib/active_support/testing/parallelize_executor.rb +8 -3
- data/lib/active_support/testing/stream.rb +1 -1
- data/lib/active_support/testing/strict_warnings.rb +38 -0
- data/lib/active_support/testing/time_helpers.rb +32 -14
- data/lib/active_support/time_with_zone.rb +6 -42
- data/lib/active_support/values/time_zone.rb +9 -7
- data/lib/active_support/version.rb +1 -1
- data/lib/active_support/xml_mini/jdom.rb +3 -10
- data/lib/active_support/xml_mini/nokogiri.rb +1 -1
- data/lib/active_support/xml_mini/nokogirisax.rb +1 -1
- data/lib/active_support/xml_mini/rexml.rb +1 -1
- data/lib/active_support/xml_mini.rb +2 -2
- data/lib/active_support.rb +13 -3
- metadata +103 -18
- data/lib/active_support/core_ext/array/deprecated_conversions.rb +0 -25
- data/lib/active_support/core_ext/date/deprecated_conversions.rb +0 -37
- data/lib/active_support/core_ext/date_time/deprecated_conversions.rb +0 -33
- data/lib/active_support/core_ext/numeric/deprecated_conversions.rb +0 -60
- data/lib/active_support/core_ext/range/deprecated_conversions.rb +0 -33
- data/lib/active_support/core_ext/range/include_time_with_zone.rb +0 -5
- data/lib/active_support/core_ext/time/deprecated_conversions.rb +0 -33
- data/lib/active_support/core_ext/uri.rb +0 -5
- data/lib/active_support/per_thread_registry.rb +0 -65
@@ -9,7 +9,9 @@ require "active_support/core_ext/object/blank"
|
|
9
9
|
require "thread"
|
10
10
|
|
11
11
|
module ActiveSupport
|
12
|
-
#
|
12
|
+
# = Active Support \Callbacks
|
13
|
+
#
|
14
|
+
# \Callbacks are code hooks that are run at key points in an object's life cycle.
|
13
15
|
# The typical use case is to have a base class define a set of callbacks
|
14
16
|
# relevant to the other functionality it supplies, so that subclasses can
|
15
17
|
# install callbacks that enhance or modify the base functionality without
|
@@ -68,7 +70,7 @@ module ActiveSupport
|
|
68
70
|
class_attribute :__callbacks, instance_writer: false, default: {}
|
69
71
|
end
|
70
72
|
|
71
|
-
CALLBACK_FILTER_TYPES = [:before, :after, :around]
|
73
|
+
CALLBACK_FILTER_TYPES = [:before, :after, :around].freeze
|
72
74
|
|
73
75
|
# Runs the callbacks for the given event.
|
74
76
|
#
|
@@ -92,14 +94,15 @@ module ActiveSupport
|
|
92
94
|
# callback can be as noisy as it likes -- but when control has passed
|
93
95
|
# smoothly through and into the supplied block, we want as little evidence
|
94
96
|
# as possible that we were here.
|
95
|
-
def run_callbacks(kind)
|
97
|
+
def run_callbacks(kind, type = nil)
|
96
98
|
callbacks = __callbacks[kind.to_sym]
|
97
99
|
|
98
100
|
if callbacks.empty?
|
99
101
|
yield if block_given?
|
100
102
|
else
|
101
103
|
env = Filters::Environment.new(self, false, nil)
|
102
|
-
|
104
|
+
|
105
|
+
next_sequence = callbacks.compile(type)
|
103
106
|
|
104
107
|
# Common case: no 'around' callbacks defined
|
105
108
|
if next_sequence.final?
|
@@ -612,7 +615,8 @@ module ActiveSupport
|
|
612
615
|
terminator: default_terminator
|
613
616
|
}.merge!(config)
|
614
617
|
@chain = []
|
615
|
-
@
|
618
|
+
@all_callbacks = nil
|
619
|
+
@single_callbacks = {}
|
616
620
|
@mutex = Mutex.new
|
617
621
|
end
|
618
622
|
|
@@ -621,32 +625,45 @@ module ActiveSupport
|
|
621
625
|
def empty?; @chain.empty?; end
|
622
626
|
|
623
627
|
def insert(index, o)
|
624
|
-
@
|
628
|
+
@all_callbacks = nil
|
629
|
+
@single_callbacks.clear
|
625
630
|
@chain.insert(index, o)
|
626
631
|
end
|
627
632
|
|
628
633
|
def delete(o)
|
629
|
-
@
|
634
|
+
@all_callbacks = nil
|
635
|
+
@single_callbacks.clear
|
630
636
|
@chain.delete(o)
|
631
637
|
end
|
632
638
|
|
633
639
|
def clear
|
634
|
-
@
|
640
|
+
@all_callbacks = nil
|
641
|
+
@single_callbacks.clear
|
635
642
|
@chain.clear
|
636
643
|
self
|
637
644
|
end
|
638
645
|
|
639
646
|
def initialize_copy(other)
|
640
|
-
@
|
647
|
+
@all_callbacks = nil
|
648
|
+
@single_callbacks = {}
|
641
649
|
@chain = other.chain.dup
|
642
650
|
@mutex = Mutex.new
|
643
651
|
end
|
644
652
|
|
645
|
-
def compile
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
|
653
|
+
def compile(type)
|
654
|
+
if type.nil?
|
655
|
+
@all_callbacks || @mutex.synchronize do
|
656
|
+
final_sequence = CallbackSequence.new
|
657
|
+
@all_callbacks ||= @chain.reverse.inject(final_sequence) do |callback_sequence, callback|
|
658
|
+
callback.apply(callback_sequence)
|
659
|
+
end
|
660
|
+
end
|
661
|
+
else
|
662
|
+
@single_callbacks[type] || @mutex.synchronize do
|
663
|
+
final_sequence = CallbackSequence.new
|
664
|
+
@single_callbacks[type] ||= @chain.reverse.inject(final_sequence) do |callback_sequence, callback|
|
665
|
+
type == callback.kind ? callback.apply(callback_sequence) : callback_sequence
|
666
|
+
end
|
650
667
|
end
|
651
668
|
end
|
652
669
|
end
|
@@ -664,19 +681,22 @@ module ActiveSupport
|
|
664
681
|
|
665
682
|
private
|
666
683
|
def append_one(callback)
|
667
|
-
@
|
684
|
+
@all_callbacks = nil
|
685
|
+
@single_callbacks.clear
|
668
686
|
remove_duplicates(callback)
|
669
687
|
@chain.push(callback)
|
670
688
|
end
|
671
689
|
|
672
690
|
def prepend_one(callback)
|
673
|
-
@
|
691
|
+
@all_callbacks = nil
|
692
|
+
@single_callbacks.clear
|
674
693
|
remove_duplicates(callback)
|
675
694
|
@chain.unshift(callback)
|
676
695
|
end
|
677
696
|
|
678
697
|
def remove_duplicates(callback)
|
679
|
-
@
|
698
|
+
@all_callbacks = nil
|
699
|
+
@single_callbacks.clear
|
680
700
|
@chain.delete_if { |c| callback.duplicates?(c) }
|
681
701
|
end
|
682
702
|
|
@@ -703,7 +723,7 @@ module ActiveSupport
|
|
703
723
|
# This is used internally to append, prepend and skip callbacks to the
|
704
724
|
# CallbackChain.
|
705
725
|
def __update_callbacks(name) # :nodoc:
|
706
|
-
|
726
|
+
self.descendants.prepend(self).reverse_each do |target|
|
707
727
|
chain = target.get_callbacks name
|
708
728
|
yield target, chain.dup
|
709
729
|
end
|
@@ -1,6 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module ActiveSupport
|
4
|
+
# = Active Support \Concern
|
5
|
+
#
|
4
6
|
# A typical module looks like this:
|
5
7
|
#
|
6
8
|
# module M
|
@@ -16,7 +18,7 @@ module ActiveSupport
|
|
16
18
|
# end
|
17
19
|
# end
|
18
20
|
#
|
19
|
-
# By using
|
21
|
+
# By using +ActiveSupport::Concern+ the above module could instead be
|
20
22
|
# written as:
|
21
23
|
#
|
22
24
|
# require "active_support/concern"
|
@@ -73,7 +75,7 @@ module ActiveSupport
|
|
73
75
|
# end
|
74
76
|
#
|
75
77
|
# Unfortunately this won't work, since when +Foo+ is included, its <tt>base</tt>
|
76
|
-
# is the +Bar+ module, not the +Host+ class. With
|
78
|
+
# is the +Bar+ module, not the +Host+ class. With +ActiveSupport::Concern+,
|
77
79
|
# module dependencies are properly resolved:
|
78
80
|
#
|
79
81
|
# require "active_support/concern"
|
@@ -4,9 +4,7 @@ require "monitor"
|
|
4
4
|
|
5
5
|
module ActiveSupport
|
6
6
|
module Concurrency
|
7
|
-
|
8
|
-
# the lock.
|
9
|
-
class LoadInterlockAwareMonitor < Monitor
|
7
|
+
module LoadInterlockAwareMonitorMixin # :nodoc:
|
10
8
|
EXCEPTION_NEVER = { Exception => :never }.freeze
|
11
9
|
EXCEPTION_IMMEDIATE = { Exception => :immediate }.freeze
|
12
10
|
private_constant :EXCEPTION_NEVER, :EXCEPTION_IMMEDIATE
|
@@ -29,5 +27,46 @@ module ActiveSupport
|
|
29
27
|
end
|
30
28
|
end
|
31
29
|
end
|
30
|
+
# A monitor that will permit dependency loading while blocked waiting for
|
31
|
+
# the lock.
|
32
|
+
class LoadInterlockAwareMonitor < Monitor
|
33
|
+
include LoadInterlockAwareMonitorMixin
|
34
|
+
end
|
35
|
+
|
36
|
+
class ThreadLoadInterlockAwareMonitor # :nodoc:
|
37
|
+
prepend LoadInterlockAwareMonitorMixin
|
38
|
+
|
39
|
+
def initialize
|
40
|
+
@owner = nil
|
41
|
+
@count = 0
|
42
|
+
@mutex = Mutex.new
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
def mon_try_enter
|
47
|
+
if @owner != Thread.current
|
48
|
+
return false unless @mutex.try_lock
|
49
|
+
@owner = Thread.current
|
50
|
+
end
|
51
|
+
@count += 1
|
52
|
+
end
|
53
|
+
|
54
|
+
def mon_enter
|
55
|
+
@mutex.lock if @owner != Thread.current
|
56
|
+
@owner = Thread.current
|
57
|
+
@count += 1
|
58
|
+
end
|
59
|
+
|
60
|
+
def mon_exit
|
61
|
+
unless @owner == Thread.current
|
62
|
+
raise ThreadError, "current thread not owner"
|
63
|
+
end
|
64
|
+
|
65
|
+
@count -= 1
|
66
|
+
return unless @count == 0
|
67
|
+
@owner = nil
|
68
|
+
@mutex.unlock
|
69
|
+
end
|
70
|
+
end
|
32
71
|
end
|
33
72
|
end
|
@@ -4,6 +4,8 @@ require "active_support/concern"
|
|
4
4
|
require "active_support/ordered_options"
|
5
5
|
|
6
6
|
module ActiveSupport
|
7
|
+
# = Active Support \Configurable
|
8
|
+
#
|
7
9
|
# Configurable provides a <tt>config</tt> method to store and retrieve
|
8
10
|
# configuration options as an OrderedOptions.
|
9
11
|
module Configurable
|
@@ -125,6 +127,14 @@ module ActiveSupport
|
|
125
127
|
end
|
126
128
|
end
|
127
129
|
private :config_accessor
|
130
|
+
|
131
|
+
private
|
132
|
+
def inherited(subclass)
|
133
|
+
super
|
134
|
+
subclass.class_eval do
|
135
|
+
@_config = nil
|
136
|
+
end
|
137
|
+
end
|
128
138
|
end
|
129
139
|
|
130
140
|
# Reads and writes attributes from a configuration OrderedOptions.
|
@@ -100,11 +100,12 @@ class Array
|
|
100
100
|
collect(&:id).join(",")
|
101
101
|
end
|
102
102
|
else
|
103
|
-
|
103
|
+
to_s
|
104
104
|
end
|
105
105
|
end
|
106
106
|
alias_method :to_formatted_s, :to_fs
|
107
107
|
alias_method :to_default_s, :to_s
|
108
|
+
deprecate to_default_s: :to_s, deprecator: ActiveSupport.deprecator
|
108
109
|
|
109
110
|
# Returns a string that represents the array in XML by invoking +to_xml+
|
110
111
|
# on each element. Active Record collections delegate their representation
|
@@ -3,7 +3,6 @@
|
|
3
3
|
require "active_support/core_ext/array/wrap"
|
4
4
|
require "active_support/core_ext/array/access"
|
5
5
|
require "active_support/core_ext/array/conversions"
|
6
|
-
require "active_support/core_ext/array/deprecated_conversions" unless ENV["RAILS_DISABLE_DEPRECATED_TO_S_CONVERSION"]
|
7
6
|
require "active_support/core_ext/array/extract"
|
8
7
|
require "active_support/core_ext/array/extract_options"
|
9
8
|
require "active_support/core_ext/array/grouping"
|
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "active_support/ruby_features"
|
4
|
+
require "active_support/descendants_tracker"
|
4
5
|
|
5
6
|
class Class
|
6
7
|
if ActiveSupport::RubyFeatures::CLASS_SUBCLASSES
|
@@ -26,16 +27,18 @@ class Class
|
|
26
27
|
k.singleton_class? || k == self
|
27
28
|
end
|
28
29
|
end
|
30
|
+
|
31
|
+
# Returns an array with the direct children of +self+.
|
32
|
+
#
|
33
|
+
# class Foo; end
|
34
|
+
# class Bar < Foo; end
|
35
|
+
# class Baz < Bar; end
|
36
|
+
#
|
37
|
+
# Foo.subclasses # => [Bar]
|
38
|
+
def subclasses
|
39
|
+
descendants.select { |descendant| descendant.superclass == self }
|
40
|
+
end
|
29
41
|
end
|
30
42
|
|
31
|
-
|
32
|
-
#
|
33
|
-
# class Foo; end
|
34
|
-
# class Bar < Foo; end
|
35
|
-
# class Baz < Bar; end
|
36
|
-
#
|
37
|
-
# Foo.subclasses # => [Bar]
|
38
|
-
def subclasses
|
39
|
-
descendants.select { |descendant| descendant.superclass == self }
|
40
|
-
end unless ActiveSupport::RubyFeatures::CLASS_SUBCLASSES
|
43
|
+
prepend ActiveSupport::DescendantsTracker::ReloadedClassesFiltering
|
41
44
|
end
|
@@ -57,6 +57,7 @@ class Date
|
|
57
57
|
end
|
58
58
|
alias_method :to_formatted_s, :to_fs
|
59
59
|
alias_method :to_default_s, :to_s
|
60
|
+
deprecate to_default_s: :to_s, deprecator: ActiveSupport.deprecator
|
60
61
|
|
61
62
|
# Overrides the default inspect method with a human readable one, e.g., "Mon, 21 Feb 2005"
|
62
63
|
def readable_inspect
|
@@ -4,5 +4,4 @@ require "active_support/core_ext/date/acts_like"
|
|
4
4
|
require "active_support/core_ext/date/blank"
|
5
5
|
require "active_support/core_ext/date/calculations"
|
6
6
|
require "active_support/core_ext/date/conversions"
|
7
|
-
require "active_support/core_ext/date/deprecated_conversions" unless ENV["RAILS_DISABLE_DEPRECATED_TO_S_CONVERSION"]
|
8
7
|
require "active_support/core_ext/date/zones"
|
@@ -157,6 +157,16 @@ module DateAndTime
|
|
157
157
|
end
|
158
158
|
alias :at_end_of_quarter :end_of_quarter
|
159
159
|
|
160
|
+
# Returns the quarter for a date/time.
|
161
|
+
#
|
162
|
+
# Date.new(2010, 1, 31).quarter # => 1
|
163
|
+
# Date.new(2010, 4, 12).quarter # => 2
|
164
|
+
# Date.new(2010, 9, 15).quarter # => 3
|
165
|
+
# Date.new(2010, 12, 25).quarter # => 4
|
166
|
+
def quarter
|
167
|
+
(month / 3.0).ceil
|
168
|
+
end
|
169
|
+
|
160
170
|
# Returns a new date/time at the beginning of the year.
|
161
171
|
#
|
162
172
|
# today = Date.today # => Fri, 10 Jul 2015
|
@@ -36,11 +36,15 @@ class DateTime
|
|
36
36
|
if formatter = ::Time::DATE_FORMATS[format]
|
37
37
|
formatter.respond_to?(:call) ? formatter.call(self).to_s : strftime(formatter)
|
38
38
|
else
|
39
|
-
|
39
|
+
to_s
|
40
40
|
end
|
41
41
|
end
|
42
42
|
alias_method :to_formatted_s, :to_fs
|
43
|
-
|
43
|
+
if instance_methods(false).include?(:to_s)
|
44
|
+
alias_method :to_default_s, :to_s
|
45
|
+
deprecate to_default_s: :to_s, deprecator: ActiveSupport.deprecator
|
46
|
+
end
|
47
|
+
|
44
48
|
|
45
49
|
# Returns a formatted string of the offset from UTC, or an alternative
|
46
50
|
# string if the time zone is already UTC.
|
@@ -5,4 +5,3 @@ require "active_support/core_ext/date_time/blank"
|
|
5
5
|
require "active_support/core_ext/date_time/calculations"
|
6
6
|
require "active_support/core_ext/date_time/compatibility"
|
7
7
|
require "active_support/core_ext/date_time/conversions"
|
8
|
-
require "active_support/core_ext/date_time/deprecated_conversions" unless ENV["RAILS_DISABLE_DEPRECATED_TO_S_CONVERSION"]
|
@@ -10,8 +10,6 @@ module Digest
|
|
10
10
|
OID_NAMESPACE = "k\xA7\xB8\x12\x9D\xAD\x11\xD1\x80\xB4\x00\xC0O\xD40\xC8" # :nodoc:
|
11
11
|
X500_NAMESPACE = "k\xA7\xB8\x14\x9D\xAD\x11\xD1\x80\xB4\x00\xC0O\xD40\xC8" # :nodoc:
|
12
12
|
|
13
|
-
mattr_accessor :use_rfc4122_namespaced_uuids, instance_accessor: false, default: false
|
14
|
-
|
15
13
|
# Generates a v5 non-random UUID (Universally Unique IDentifier).
|
16
14
|
#
|
17
15
|
# Using OpenSSL::Digest::MD5 generates version 3 UUIDs; OpenSSL::Digest::SHA1 generates version 5 UUIDs.
|
@@ -58,19 +56,12 @@ module Digest
|
|
58
56
|
def self.pack_uuid_namespace(namespace)
|
59
57
|
if [DNS_NAMESPACE, OID_NAMESPACE, URL_NAMESPACE, X500_NAMESPACE].include?(namespace)
|
60
58
|
namespace
|
61
|
-
|
59
|
+
else
|
62
60
|
match_data = namespace.match(/\A(\h{8})-(\h{4})-(\h{4})-(\h{4})-(\h{4})(\h{8})\z/)
|
63
61
|
|
64
62
|
raise ArgumentError, "Only UUIDs are valid namespace identifiers" unless match_data.present?
|
65
63
|
|
66
64
|
match_data.captures.map { |s| s.to_i(16) }.pack("NnnnnN")
|
67
|
-
else
|
68
|
-
ActiveSupport::Deprecation.warn <<~WARNING.squish
|
69
|
-
Providing a namespace ID that is not one of the constants defined on Digest::UUID generates an incorrect UUID value according to RFC 4122.
|
70
|
-
To enable the correct behavior, set the Rails.application.config.active_support.use_rfc4122_namespaced_uuids configuration option to true.
|
71
|
-
WARNING
|
72
|
-
|
73
|
-
namespace
|
74
65
|
end
|
75
66
|
end
|
76
67
|
|
@@ -25,18 +25,6 @@ module Enumerable
|
|
25
25
|
ActiveSupport::EnumerableCoreExt::SoleItemExpectedError = remove_const(:SoleItemExpectedError)
|
26
26
|
singleton_class.prepend(ActiveSupport::EnumerableCoreExt::Constants)
|
27
27
|
|
28
|
-
# Enumerable#sum was added in Ruby 2.4, but it only works with Numeric elements
|
29
|
-
# when we omit an identity.
|
30
|
-
|
31
|
-
# :stopdoc:
|
32
|
-
|
33
|
-
# We can't use Refinements here because Refinements with Module which will be prepended
|
34
|
-
# doesn't work well https://bugs.ruby-lang.org/issues/13446
|
35
|
-
alias :_original_sum_with_required_identity :sum
|
36
|
-
private :_original_sum_with_required_identity
|
37
|
-
|
38
|
-
# :startdoc:
|
39
|
-
|
40
28
|
# Calculates the minimum from the extracted elements.
|
41
29
|
#
|
42
30
|
# payments = [Payment.new(5), Payment.new(15), Payment.new(10)]
|
@@ -53,50 +41,6 @@ module Enumerable
|
|
53
41
|
map(&key).max
|
54
42
|
end
|
55
43
|
|
56
|
-
# Calculates a sum from the elements.
|
57
|
-
#
|
58
|
-
# payments.sum { |p| p.price * p.tax_rate }
|
59
|
-
# payments.sum(&:price)
|
60
|
-
#
|
61
|
-
# The latter is a shortcut for:
|
62
|
-
#
|
63
|
-
# payments.inject(0) { |sum, p| sum + p.price }
|
64
|
-
#
|
65
|
-
# It can also calculate the sum without the use of a block.
|
66
|
-
#
|
67
|
-
# [5, 15, 10].sum # => 30
|
68
|
-
# ['foo', 'bar'].sum('') # => "foobar"
|
69
|
-
# [[1, 2], [3, 1, 5]].sum([]) # => [1, 2, 3, 1, 5]
|
70
|
-
#
|
71
|
-
# The default sum of an empty list is zero. You can override this default:
|
72
|
-
#
|
73
|
-
# [].sum(Payment.new(0)) { |i| i.amount } # => Payment.new(0)
|
74
|
-
def sum(identity = nil, &block)
|
75
|
-
if identity
|
76
|
-
_original_sum_with_required_identity(identity, &block)
|
77
|
-
elsif block_given?
|
78
|
-
map(&block).sum
|
79
|
-
else
|
80
|
-
first = true
|
81
|
-
|
82
|
-
reduce(nil) do |sum, value|
|
83
|
-
if first
|
84
|
-
first = false
|
85
|
-
|
86
|
-
unless value.is_a?(Numeric) || value.respond_to?(:coerce)
|
87
|
-
ActiveSupport::Deprecation.warn(<<-MSG.squish)
|
88
|
-
Rails 7.0 has deprecated Enumerable.sum in favor of Ruby's native implementation available since 2.4.
|
89
|
-
Sum of non-numeric elements requires an initial argument.
|
90
|
-
MSG
|
91
|
-
end
|
92
|
-
value
|
93
|
-
else
|
94
|
-
sum + value
|
95
|
-
end
|
96
|
-
end || 0
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
44
|
# Convert an enumerable to a hash, using the block result as the key and the
|
101
45
|
# element as the value.
|
102
46
|
#
|
@@ -289,38 +233,22 @@ end
|
|
289
233
|
class Range # :nodoc:
|
290
234
|
# Optimize range sum to use arithmetic progression if a block is not given and
|
291
235
|
# we have a range of numeric values.
|
292
|
-
def sum(
|
236
|
+
def sum(initial_value = 0)
|
293
237
|
if block_given? || !(first.is_a?(Integer) && last.is_a?(Integer))
|
294
238
|
super
|
295
239
|
else
|
296
240
|
actual_last = exclude_end? ? (last - 1) : last
|
297
241
|
if actual_last >= first
|
298
|
-
sum =
|
242
|
+
sum = initial_value || 0
|
299
243
|
sum + (actual_last - first + 1) * (actual_last + first) / 2
|
300
244
|
else
|
301
|
-
|
245
|
+
initial_value || 0
|
302
246
|
end
|
303
247
|
end
|
304
248
|
end
|
305
249
|
end
|
306
250
|
|
307
|
-
# Using Refinements here in order not to expose our internal method
|
308
|
-
using Module.new {
|
309
|
-
refine Array do
|
310
|
-
alias :orig_sum :sum
|
311
|
-
end
|
312
|
-
}
|
313
|
-
|
314
251
|
class Array # :nodoc:
|
315
|
-
def sum(init = nil, &block)
|
316
|
-
if init.is_a?(Numeric) || first.is_a?(Numeric)
|
317
|
-
init ||= 0
|
318
|
-
orig_sum(init, &block)
|
319
|
-
else
|
320
|
-
super
|
321
|
-
end
|
322
|
-
end
|
323
|
-
|
324
252
|
# Removes all blank elements from the +Array+ in place and returns self.
|
325
253
|
# Uses Object#blank? for determining if an item is blank.
|
326
254
|
#
|