activesupport 7.1.6 → 8.1.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +256 -1133
- data/README.rdoc +1 -1
- data/lib/active_support/array_inquirer.rb +1 -1
- data/lib/active_support/backtrace_cleaner.rb +81 -3
- data/lib/active_support/benchmark.rb +21 -0
- data/lib/active_support/benchmarkable.rb +3 -2
- data/lib/active_support/broadcast_logger.rb +65 -78
- data/lib/active_support/cache/file_store.rb +29 -14
- data/lib/active_support/cache/mem_cache_store.rb +42 -102
- data/lib/active_support/cache/memory_store.rb +11 -6
- data/lib/active_support/cache/null_store.rb +2 -2
- data/lib/active_support/cache/redis_cache_store.rb +58 -46
- data/lib/active_support/cache/serializer_with_fallback.rb +0 -23
- data/lib/active_support/cache/strategy/local_cache.rb +72 -27
- data/lib/active_support/cache/strategy/local_cache_middleware.rb +7 -7
- data/lib/active_support/cache.rb +146 -86
- data/lib/active_support/callbacks.rb +102 -126
- data/lib/active_support/class_attribute.rb +33 -0
- data/lib/active_support/code_generator.rb +9 -0
- data/lib/active_support/concurrency/load_interlock_aware_monitor.rb +8 -62
- data/lib/active_support/concurrency/share_lock.rb +0 -1
- data/lib/active_support/concurrency/thread_monitor.rb +55 -0
- data/lib/active_support/configurable.rb +34 -0
- data/lib/active_support/configuration_file.rb +15 -6
- data/lib/active_support/continuous_integration.rb +145 -0
- data/lib/active_support/core_ext/array/conversions.rb +3 -5
- data/lib/active_support/core_ext/array.rb +7 -7
- data/lib/active_support/core_ext/benchmark.rb +4 -14
- data/lib/active_support/core_ext/big_decimal.rb +1 -1
- data/lib/active_support/core_ext/class/attribute.rb +26 -19
- data/lib/active_support/core_ext/class/subclasses.rb +15 -35
- data/lib/active_support/core_ext/class.rb +2 -2
- data/lib/active_support/core_ext/date/blank.rb +4 -0
- data/lib/active_support/core_ext/date/conversions.rb +2 -2
- data/lib/active_support/core_ext/date.rb +5 -5
- data/lib/active_support/core_ext/date_and_time/compatibility.rb +1 -9
- data/lib/active_support/core_ext/date_time/blank.rb +4 -0
- data/lib/active_support/core_ext/date_time/compatibility.rb +3 -5
- data/lib/active_support/core_ext/date_time/conversions.rb +4 -6
- data/lib/active_support/core_ext/date_time.rb +5 -5
- data/lib/active_support/core_ext/digest/uuid.rb +6 -0
- data/lib/active_support/core_ext/digest.rb +1 -1
- data/lib/active_support/core_ext/enumerable.rb +25 -8
- data/lib/active_support/core_ext/erb/util.rb +10 -5
- data/lib/active_support/core_ext/file.rb +1 -1
- data/lib/active_support/core_ext/hash/deep_merge.rb +1 -0
- data/lib/active_support/core_ext/hash/except.rb +0 -12
- data/lib/active_support/core_ext/hash/keys.rb +4 -4
- data/lib/active_support/core_ext/hash.rb +8 -8
- data/lib/active_support/core_ext/integer.rb +3 -3
- data/lib/active_support/core_ext/kernel.rb +3 -3
- data/lib/active_support/core_ext/module/attr_internal.rb +16 -6
- data/lib/active_support/core_ext/module/delegation.rb +20 -163
- data/lib/active_support/core_ext/module/deprecation.rb +1 -4
- data/lib/active_support/core_ext/module/introspection.rb +3 -0
- data/lib/active_support/core_ext/module.rb +11 -11
- data/lib/active_support/core_ext/numeric/conversions.rb +3 -3
- data/lib/active_support/core_ext/numeric.rb +3 -3
- data/lib/active_support/core_ext/object/blank.rb +45 -1
- data/lib/active_support/core_ext/object/instance_variables.rb +11 -19
- data/lib/active_support/core_ext/object/json.rb +24 -11
- data/lib/active_support/core_ext/object/to_query.rb +7 -1
- data/lib/active_support/core_ext/object/try.rb +2 -2
- data/lib/active_support/core_ext/object/with.rb +5 -3
- data/lib/active_support/core_ext/object.rb +13 -13
- data/lib/active_support/core_ext/pathname/blank.rb +4 -0
- data/lib/active_support/core_ext/pathname.rb +2 -2
- data/lib/active_support/core_ext/range/overlap.rb +4 -4
- data/lib/active_support/core_ext/range/sole.rb +17 -0
- data/lib/active_support/core_ext/range.rb +4 -4
- data/lib/active_support/core_ext/securerandom.rb +4 -4
- data/lib/active_support/core_ext/string/conversions.rb +1 -1
- data/lib/active_support/core_ext/string/filters.rb +4 -4
- data/lib/active_support/core_ext/string/multibyte.rb +13 -4
- data/lib/active_support/core_ext/string/output_safety.rb +19 -19
- data/lib/active_support/core_ext/string.rb +13 -13
- data/lib/active_support/core_ext/symbol.rb +1 -1
- data/lib/active_support/core_ext/thread/backtrace/location.rb +2 -7
- data/lib/active_support/core_ext/time/calculations.rb +25 -30
- data/lib/active_support/core_ext/time/compatibility.rb +2 -3
- data/lib/active_support/core_ext/time/conversions.rb +2 -2
- data/lib/active_support/core_ext/time/zones.rb +1 -1
- data/lib/active_support/core_ext/time.rb +5 -5
- data/lib/active_support/core_ext.rb +1 -2
- data/lib/active_support/current_attributes/test_helper.rb +2 -2
- data/lib/active_support/current_attributes.rb +58 -50
- data/lib/active_support/delegation.rb +200 -0
- data/lib/active_support/dependencies/autoload.rb +0 -12
- data/lib/active_support/dependencies/interlock.rb +11 -5
- data/lib/active_support/dependencies.rb +6 -2
- data/lib/active_support/deprecation/constant_accessor.rb +47 -26
- data/lib/active_support/deprecation/proxy_wrappers.rb +9 -12
- data/lib/active_support/deprecation/reporting.rb +5 -17
- data/lib/active_support/deprecation.rb +8 -5
- data/lib/active_support/descendants_tracker.rb +9 -87
- data/lib/active_support/duration/iso8601_parser.rb +2 -2
- data/lib/active_support/duration/iso8601_serializer.rb +1 -2
- data/lib/active_support/duration.rb +25 -16
- data/lib/active_support/editor.rb +70 -0
- data/lib/active_support/encrypted_configuration.rb +20 -2
- data/lib/active_support/encrypted_file.rb +1 -1
- data/lib/active_support/error_reporter.rb +121 -6
- data/lib/active_support/event_reporter/test_helper.rb +32 -0
- data/lib/active_support/event_reporter.rb +592 -0
- data/lib/active_support/evented_file_update_checker.rb +5 -3
- data/lib/active_support/execution_context.rb +64 -7
- data/lib/active_support/execution_wrapper.rb +1 -2
- data/lib/active_support/file_update_checker.rb +9 -7
- data/lib/active_support/fork_tracker.rb +2 -38
- data/lib/active_support/gem_version.rb +2 -2
- data/lib/active_support/gzip.rb +1 -0
- data/lib/active_support/hash_with_indifferent_access.rb +66 -45
- data/lib/active_support/html_safe_translation.rb +3 -0
- data/lib/active_support/i18n_railtie.rb +19 -11
- data/lib/active_support/inflector/inflections.rb +31 -15
- data/lib/active_support/inflector/transliterate.rb +6 -8
- data/lib/active_support/isolated_execution_state.rb +12 -17
- data/lib/active_support/json/decoding.rb +6 -4
- data/lib/active_support/json/encoding.rb +157 -21
- data/lib/active_support/lazy_load_hooks.rb +1 -1
- data/lib/active_support/log_subscriber.rb +2 -18
- data/lib/active_support/logger.rb +15 -2
- data/lib/active_support/logger_thread_safe_level.rb +4 -9
- data/lib/active_support/message_encryptors.rb +54 -2
- data/lib/active_support/message_pack/extensions.rb +20 -2
- data/lib/active_support/message_verifier.rb +21 -0
- data/lib/active_support/message_verifiers.rb +57 -3
- data/lib/active_support/messages/rotation_coordinator.rb +9 -0
- data/lib/active_support/messages/rotator.rb +10 -0
- data/lib/active_support/multibyte/chars.rb +14 -4
- data/lib/active_support/multibyte.rb +4 -0
- data/lib/active_support/notifications/fanout.rb +68 -50
- data/lib/active_support/notifications/instrumenter.rb +22 -19
- data/lib/active_support/notifications.rb +28 -27
- data/lib/active_support/number_helper/number_converter.rb +2 -2
- data/lib/active_support/number_helper.rb +22 -0
- data/lib/active_support/option_merger.rb +2 -2
- data/lib/active_support/ordered_options.rb +53 -15
- data/lib/active_support/railtie.rb +36 -20
- data/lib/active_support/string_inquirer.rb +1 -1
- data/lib/active_support/structured_event_subscriber.rb +99 -0
- data/lib/active_support/subscriber.rb +1 -5
- data/lib/active_support/syntax_error_proxy.rb +3 -0
- data/lib/active_support/tagged_logging.rb +5 -1
- data/lib/active_support/test_case.rb +63 -6
- data/lib/active_support/testing/assertions.rb +113 -27
- data/lib/active_support/testing/constant_stubbing.rb +30 -8
- data/lib/active_support/testing/deprecation.rb +5 -12
- data/lib/active_support/testing/error_reporter_assertions.rb +18 -1
- data/lib/active_support/testing/event_reporter_assertions.rb +227 -0
- data/lib/active_support/testing/isolation.rb +19 -9
- data/lib/active_support/testing/method_call_assertions.rb +2 -16
- data/lib/active_support/testing/notification_assertions.rb +92 -0
- data/lib/active_support/testing/parallelization/server.rb +18 -2
- data/lib/active_support/testing/parallelization/worker.rb +4 -2
- data/lib/active_support/testing/parallelization.rb +25 -1
- data/lib/active_support/testing/tests_without_assertions.rb +19 -0
- data/lib/active_support/testing/time_helpers.rb +11 -6
- data/lib/active_support/time_with_zone.rb +39 -26
- data/lib/active_support/values/time_zone.rb +26 -17
- data/lib/active_support/xml_mini.rb +14 -4
- data/lib/active_support.rb +22 -9
- metadata +31 -17
- data/lib/active_support/core_ext/range/each.rb +0 -24
- data/lib/active_support/deprecation/instance_delegator.rb +0 -65
- data/lib/active_support/proxy_object.rb +0 -17
- data/lib/active_support/ruby_features.rb +0 -7
- data/lib/active_support/testing/strict_warnings.rb +0 -39
data/README.rdoc
CHANGED
|
@@ -35,6 +35,6 @@ Bug reports for the Ruby on \Rails project can be filed here:
|
|
|
35
35
|
|
|
36
36
|
* https://github.com/rails/rails/issues
|
|
37
37
|
|
|
38
|
-
Feature requests should be discussed on the
|
|
38
|
+
Feature requests should be discussed on the rubyonrails-core forum here:
|
|
39
39
|
|
|
40
40
|
* https://discuss.rubyonrails.org/c/rubyonrails-core
|
|
@@ -17,7 +17,8 @@ module ActiveSupport
|
|
|
17
17
|
# can focus on the rest.
|
|
18
18
|
#
|
|
19
19
|
# bc = ActiveSupport::BacktraceCleaner.new
|
|
20
|
-
#
|
|
20
|
+
# root = "#{Rails.root}/"
|
|
21
|
+
# bc.add_filter { |line| line.delete_prefix(root) } # strip the Rails.root prefix
|
|
21
22
|
# bc.add_silencer { |line| /puma|rubygems/.match?(line) } # skip any lines from puma or rubygems
|
|
22
23
|
# bc.clean(exception.backtrace) # perform the cleanup
|
|
23
24
|
#
|
|
@@ -55,6 +56,18 @@ module ActiveSupport
|
|
|
55
56
|
end
|
|
56
57
|
alias :filter :clean
|
|
57
58
|
|
|
59
|
+
# Given an array of Thread::Backtrace::Location objects, returns an array
|
|
60
|
+
# with the clean ones:
|
|
61
|
+
#
|
|
62
|
+
# clean_locations = backtrace_cleaner.clean_locations(caller_locations)
|
|
63
|
+
#
|
|
64
|
+
# Filters and silencers receive strings as usual. However, the +path+
|
|
65
|
+
# attributes of the locations in the returned array are the original,
|
|
66
|
+
# unfiltered ones, since locations are immutable.
|
|
67
|
+
def clean_locations(locations, kind = :silent)
|
|
68
|
+
locations.select { |location| clean_frame(location, kind) }
|
|
69
|
+
end
|
|
70
|
+
|
|
58
71
|
# Returns the frame with all filters applied.
|
|
59
72
|
# returns +nil+ if the frame was silenced.
|
|
60
73
|
def clean_frame(frame, kind = :silent)
|
|
@@ -73,11 +86,71 @@ module ActiveSupport
|
|
|
73
86
|
end
|
|
74
87
|
end
|
|
75
88
|
|
|
89
|
+
# Thread.each_caller_location does not accept a start in Ruby < 3.4.
|
|
90
|
+
if Thread.method(:each_caller_location).arity == 0
|
|
91
|
+
# Returns the first clean frame of the caller's backtrace, or +nil+.
|
|
92
|
+
#
|
|
93
|
+
# Frames are strings.
|
|
94
|
+
def first_clean_frame(kind = :silent)
|
|
95
|
+
caller_location_skipped = false
|
|
96
|
+
|
|
97
|
+
Thread.each_caller_location do |location|
|
|
98
|
+
unless caller_location_skipped
|
|
99
|
+
caller_location_skipped = true
|
|
100
|
+
next
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
frame = clean_frame(location, kind)
|
|
104
|
+
return frame if frame
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
# Returns the first clean location of the caller's call stack, or +nil+.
|
|
109
|
+
#
|
|
110
|
+
# Locations are Thread::Backtrace::Location objects. Since they are
|
|
111
|
+
# immutable, their +path+ attributes are the original ones, but filters
|
|
112
|
+
# are applied internally so silencers can still rely on them.
|
|
113
|
+
def first_clean_location(kind = :silent)
|
|
114
|
+
caller_location_skipped = false
|
|
115
|
+
|
|
116
|
+
Thread.each_caller_location do |location|
|
|
117
|
+
unless caller_location_skipped
|
|
118
|
+
caller_location_skipped = true
|
|
119
|
+
next
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
return location if clean_frame(location, kind)
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
else
|
|
126
|
+
# Returns the first clean frame of the caller's backtrace, or +nil+.
|
|
127
|
+
#
|
|
128
|
+
# Frames are strings.
|
|
129
|
+
def first_clean_frame(kind = :silent)
|
|
130
|
+
Thread.each_caller_location(2) do |location|
|
|
131
|
+
frame = clean_frame(location, kind)
|
|
132
|
+
return frame if frame
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
# Returns the first clean location of the caller's call stack, or +nil+.
|
|
137
|
+
#
|
|
138
|
+
# Locations are Thread::Backtrace::Location objects. Since they are
|
|
139
|
+
# immutable, their +path+ attributes are the original ones, but filters
|
|
140
|
+
# are applied internally so silencers can still rely on them.
|
|
141
|
+
def first_clean_location(kind = :silent)
|
|
142
|
+
Thread.each_caller_location(2) do |location|
|
|
143
|
+
return location if clean_frame(location, kind)
|
|
144
|
+
end
|
|
145
|
+
end
|
|
146
|
+
end
|
|
147
|
+
|
|
76
148
|
# Adds a filter from the block provided. Each line in the backtrace will be
|
|
77
149
|
# mapped against this filter.
|
|
78
150
|
#
|
|
79
|
-
# # Will turn "/my/rails/root/app/models/person.rb" into "
|
|
80
|
-
#
|
|
151
|
+
# # Will turn "/my/rails/root/app/models/person.rb" into "app/models/person.rb"
|
|
152
|
+
# root = "#{Rails.root}/"
|
|
153
|
+
# backtrace_cleaner.add_filter { |line| line.delete_prefix(root) }
|
|
81
154
|
def add_filter(&block)
|
|
82
155
|
@filters << block
|
|
83
156
|
end
|
|
@@ -108,6 +181,11 @@ module ActiveSupport
|
|
|
108
181
|
private
|
|
109
182
|
FORMATTED_GEMS_PATTERN = /\A[^\/]+ \([\w.]+\) /
|
|
110
183
|
|
|
184
|
+
def initialize_copy(_other)
|
|
185
|
+
@filters = @filters.dup
|
|
186
|
+
@silencers = @silencers.dup
|
|
187
|
+
end
|
|
188
|
+
|
|
111
189
|
def add_gem_filter
|
|
112
190
|
gems_paths = (Gem.path | [Gem.default_dir]).map { |p| Regexp.escape(p) }
|
|
113
191
|
return if gems_paths.empty?
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module ActiveSupport
|
|
4
|
+
module Benchmark # :nodoc:
|
|
5
|
+
# Benchmark realtime in the specified time unit. By default,
|
|
6
|
+
# the returned unit is in seconds.
|
|
7
|
+
#
|
|
8
|
+
# ActiveSupport::Benchmark.realtime { sleep 0.1 }
|
|
9
|
+
# # => 0.10007
|
|
10
|
+
#
|
|
11
|
+
# ActiveSupport::Benchmark.realtime(:float_millisecond) { sleep 0.1 }
|
|
12
|
+
# # => 100.07
|
|
13
|
+
#
|
|
14
|
+
# `unit` can be any of the values accepted by Ruby's `Process.clock_gettime`.
|
|
15
|
+
def self.realtime(unit = :float_second, &block)
|
|
16
|
+
time_start = Process.clock_gettime(Process::CLOCK_MONOTONIC, unit)
|
|
17
|
+
yield
|
|
18
|
+
Process.clock_gettime(Process::CLOCK_MONOTONIC, unit) - time_start
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require "active_support/core_ext/benchmark"
|
|
4
3
|
require "active_support/core_ext/hash/keys"
|
|
5
4
|
|
|
6
5
|
module ActiveSupport
|
|
@@ -41,7 +40,9 @@ module ActiveSupport
|
|
|
41
40
|
options[:level] ||= :info
|
|
42
41
|
|
|
43
42
|
result = nil
|
|
44
|
-
ms = Benchmark.
|
|
43
|
+
ms = ActiveSupport::Benchmark.realtime(:float_millisecond) do
|
|
44
|
+
result = options[:silence] ? logger.silence(&block) : yield
|
|
45
|
+
end
|
|
45
46
|
logger.public_send(options[:level], "%s (%.1fms)" % [ message, ms ])
|
|
46
47
|
result
|
|
47
48
|
else
|
|
@@ -76,7 +76,6 @@ module ActiveSupport
|
|
|
76
76
|
|
|
77
77
|
# Returns all the logger that are part of this broadcast.
|
|
78
78
|
attr_reader :broadcasts
|
|
79
|
-
attr_reader :formatter
|
|
80
79
|
attr_accessor :progname
|
|
81
80
|
|
|
82
81
|
def initialize(*loggers)
|
|
@@ -105,142 +104,130 @@ module ActiveSupport
|
|
|
105
104
|
@broadcasts.delete(logger)
|
|
106
105
|
end
|
|
107
106
|
|
|
108
|
-
def level
|
|
109
|
-
@broadcasts.
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
def <<(message)
|
|
113
|
-
dispatch { |logger| logger.<<(message) }
|
|
114
|
-
end
|
|
115
|
-
|
|
116
|
-
def add(...)
|
|
117
|
-
dispatch { |logger| logger.add(...) }
|
|
118
|
-
end
|
|
119
|
-
alias_method :log, :add
|
|
120
|
-
|
|
121
|
-
def debug(...)
|
|
122
|
-
dispatch { |logger| logger.debug(...) }
|
|
123
|
-
end
|
|
124
|
-
|
|
125
|
-
def info(...)
|
|
126
|
-
dispatch { |logger| logger.info(...) }
|
|
127
|
-
end
|
|
128
|
-
|
|
129
|
-
def warn(...)
|
|
130
|
-
dispatch { |logger| logger.warn(...) }
|
|
131
|
-
end
|
|
132
|
-
|
|
133
|
-
def error(...)
|
|
134
|
-
dispatch { |logger| logger.error(...) }
|
|
135
|
-
end
|
|
136
|
-
|
|
137
|
-
def fatal(...)
|
|
138
|
-
dispatch { |logger| logger.fatal(...) }
|
|
139
|
-
end
|
|
140
|
-
|
|
141
|
-
def unknown(...)
|
|
142
|
-
dispatch { |logger| logger.unknown(...) }
|
|
107
|
+
def local_level=(level)
|
|
108
|
+
@broadcasts.each do |logger|
|
|
109
|
+
logger.local_level = level if logger.respond_to?(:local_level=)
|
|
110
|
+
end
|
|
143
111
|
end
|
|
144
112
|
|
|
145
|
-
def
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
@formatter = formatter
|
|
149
|
-
end
|
|
113
|
+
def local_level
|
|
114
|
+
loggers = @broadcasts.select { |logger| logger.respond_to?(:local_level) }
|
|
150
115
|
|
|
151
|
-
|
|
152
|
-
|
|
116
|
+
loggers.map do |logger|
|
|
117
|
+
logger.local_level
|
|
118
|
+
end.first
|
|
153
119
|
end
|
|
154
|
-
alias_method :sev_threshold=, :level=
|
|
155
120
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
121
|
+
LOGGER_METHODS = %w[
|
|
122
|
+
<< log add debug info warn error fatal unknown
|
|
123
|
+
level= sev_threshold= close
|
|
124
|
+
formatter formatter=
|
|
125
|
+
] # :nodoc:
|
|
126
|
+
LOGGER_METHODS.each do |method|
|
|
127
|
+
class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
|
128
|
+
def #{method}(...)
|
|
129
|
+
dispatch(:#{method}, ...)
|
|
130
|
+
end
|
|
131
|
+
RUBY
|
|
160
132
|
end
|
|
161
133
|
|
|
162
|
-
|
|
163
|
-
|
|
134
|
+
# Returns the lowest level of all the loggers in the broadcast.
|
|
135
|
+
def level
|
|
136
|
+
@broadcasts.map(&:level).min
|
|
164
137
|
end
|
|
165
138
|
|
|
166
|
-
#
|
|
167
|
-
# to at least one broadcast.
|
|
139
|
+
# True if the log level allows entries with severity +Logger::DEBUG+ to be written
|
|
140
|
+
# to at least one broadcast. False otherwise.
|
|
168
141
|
def debug?
|
|
169
142
|
@broadcasts.any? { |logger| logger.debug? }
|
|
170
143
|
end
|
|
171
144
|
|
|
172
|
-
# Sets the log level to Logger::DEBUG for the whole broadcast.
|
|
145
|
+
# Sets the log level to +Logger::DEBUG+ for the whole broadcast.
|
|
173
146
|
def debug!
|
|
174
|
-
dispatch
|
|
147
|
+
dispatch(:debug!)
|
|
175
148
|
end
|
|
176
149
|
|
|
177
|
-
#
|
|
178
|
-
# to at least one broadcast.
|
|
150
|
+
# True if the log level allows entries with severity +Logger::INFO+ to be written
|
|
151
|
+
# to at least one broadcast. False otherwise.
|
|
179
152
|
def info?
|
|
180
153
|
@broadcasts.any? { |logger| logger.info? }
|
|
181
154
|
end
|
|
182
155
|
|
|
183
|
-
# Sets the log level to Logger::INFO for the whole broadcast.
|
|
156
|
+
# Sets the log level to +Logger::INFO+ for the whole broadcast.
|
|
184
157
|
def info!
|
|
185
|
-
dispatch
|
|
158
|
+
dispatch(:info!)
|
|
186
159
|
end
|
|
187
160
|
|
|
188
|
-
#
|
|
189
|
-
# to at least one broadcast.
|
|
161
|
+
# True if the log level allows entries with severity +Logger::WARN+ to be written
|
|
162
|
+
# to at least one broadcast. False otherwise.
|
|
190
163
|
def warn?
|
|
191
164
|
@broadcasts.any? { |logger| logger.warn? }
|
|
192
165
|
end
|
|
193
166
|
|
|
194
|
-
# Sets the log level to Logger::WARN for the whole broadcast.
|
|
167
|
+
# Sets the log level to +Logger::WARN+ for the whole broadcast.
|
|
195
168
|
def warn!
|
|
196
|
-
dispatch
|
|
169
|
+
dispatch(:warn!)
|
|
197
170
|
end
|
|
198
171
|
|
|
199
|
-
#
|
|
200
|
-
# to at least one broadcast.
|
|
172
|
+
# True if the log level allows entries with severity +Logger::ERROR+ to be written
|
|
173
|
+
# to at least one broadcast. False otherwise.
|
|
201
174
|
def error?
|
|
202
175
|
@broadcasts.any? { |logger| logger.error? }
|
|
203
176
|
end
|
|
204
177
|
|
|
205
|
-
# Sets the log level to Logger::ERROR for the whole broadcast.
|
|
178
|
+
# Sets the log level to +Logger::ERROR+ for the whole broadcast.
|
|
206
179
|
def error!
|
|
207
|
-
dispatch
|
|
180
|
+
dispatch(:error!)
|
|
208
181
|
end
|
|
209
182
|
|
|
210
|
-
#
|
|
211
|
-
# to at least one broadcast.
|
|
183
|
+
# True if the log level allows entries with severity +Logger::FATAL+ to be written
|
|
184
|
+
# to at least one broadcast. False otherwise.
|
|
212
185
|
def fatal?
|
|
213
186
|
@broadcasts.any? { |logger| logger.fatal? }
|
|
214
187
|
end
|
|
215
188
|
|
|
216
|
-
# Sets the log level to Logger::FATAL for the whole broadcast.
|
|
189
|
+
# Sets the log level to +Logger::FATAL+ for the whole broadcast.
|
|
217
190
|
def fatal!
|
|
218
|
-
dispatch
|
|
191
|
+
dispatch(:fatal!)
|
|
219
192
|
end
|
|
220
193
|
|
|
221
194
|
def initialize_copy(other)
|
|
222
195
|
@broadcasts = []
|
|
223
196
|
@progname = other.progname.dup
|
|
224
|
-
@formatter = other.formatter.dup
|
|
225
197
|
|
|
226
198
|
broadcast_to(*other.broadcasts.map(&:dup))
|
|
227
199
|
end
|
|
228
200
|
|
|
229
201
|
private
|
|
230
|
-
def dispatch(&block)
|
|
231
|
-
|
|
232
|
-
|
|
202
|
+
def dispatch(method, *args, **kwargs, &block)
|
|
203
|
+
if block_given?
|
|
204
|
+
# Maintain semantics that the first logger yields the block
|
|
205
|
+
# as normal, but subsequent loggers won't re-execute the block.
|
|
206
|
+
# Instead, the initial result is immediately returned.
|
|
207
|
+
called, result = false, nil
|
|
208
|
+
block = proc { |*args, **kwargs|
|
|
209
|
+
if called then result
|
|
210
|
+
else
|
|
211
|
+
called = true
|
|
212
|
+
result = yield(*args, **kwargs)
|
|
213
|
+
end
|
|
214
|
+
}
|
|
215
|
+
end
|
|
216
|
+
|
|
217
|
+
@broadcasts.map { |logger|
|
|
218
|
+
logger.send(method, *args, **kwargs, &block)
|
|
219
|
+
}.first
|
|
233
220
|
end
|
|
234
221
|
|
|
235
|
-
def method_missing(name,
|
|
222
|
+
def method_missing(name, ...)
|
|
236
223
|
loggers = @broadcasts.select { |logger| logger.respond_to?(name) }
|
|
237
224
|
|
|
238
225
|
if loggers.none?
|
|
239
|
-
super
|
|
226
|
+
super
|
|
240
227
|
elsif loggers.one?
|
|
241
|
-
loggers.first.send(name,
|
|
228
|
+
loggers.first.send(name, ...)
|
|
242
229
|
else
|
|
243
|
-
loggers.map { |logger| logger.send(name,
|
|
230
|
+
loggers.map { |logger| logger.send(name, ...) }
|
|
244
231
|
end
|
|
245
232
|
end
|
|
246
233
|
|
|
@@ -57,8 +57,13 @@ module ActiveSupport
|
|
|
57
57
|
# cache.write("baz", 5)
|
|
58
58
|
# cache.increment("baz") # => 6
|
|
59
59
|
#
|
|
60
|
-
def increment(name, amount = 1, options
|
|
61
|
-
|
|
60
|
+
def increment(name, amount = 1, **options)
|
|
61
|
+
options = merged_options(options)
|
|
62
|
+
key = normalize_key(name, options)
|
|
63
|
+
|
|
64
|
+
instrument(:increment, key, amount: amount) do
|
|
65
|
+
modify_value(name, amount, options)
|
|
66
|
+
end
|
|
62
67
|
end
|
|
63
68
|
|
|
64
69
|
# Decrement a cached integer value. Returns the updated value.
|
|
@@ -72,14 +77,20 @@ module ActiveSupport
|
|
|
72
77
|
# cache.write("baz", 5)
|
|
73
78
|
# cache.decrement("baz") # => 4
|
|
74
79
|
#
|
|
75
|
-
def decrement(name, amount = 1, options
|
|
76
|
-
|
|
80
|
+
def decrement(name, amount = 1, **options)
|
|
81
|
+
options = merged_options(options)
|
|
82
|
+
key = normalize_key(name, options)
|
|
83
|
+
|
|
84
|
+
instrument(:decrement, key, amount: amount) do
|
|
85
|
+
modify_value(name, -amount, options)
|
|
86
|
+
end
|
|
77
87
|
end
|
|
78
88
|
|
|
79
89
|
def delete_matched(matcher, options = nil)
|
|
80
90
|
options = merged_options(options)
|
|
91
|
+
matcher = key_matcher(matcher, options)
|
|
92
|
+
|
|
81
93
|
instrument(:delete_matched, matcher.inspect) do
|
|
82
|
-
matcher = key_matcher(matcher, options)
|
|
83
94
|
search_dir(cache_path) do |path|
|
|
84
95
|
key = file_path_key(path)
|
|
85
96
|
delete_entry(path, **options) if key.match(matcher)
|
|
@@ -209,18 +220,22 @@ module ActiveSupport
|
|
|
209
220
|
# Modifies the amount of an integer value that is stored in the cache.
|
|
210
221
|
# If the key is not found it is created and set to +amount+.
|
|
211
222
|
def modify_value(name, amount, options)
|
|
212
|
-
|
|
223
|
+
options = merged_options(options)
|
|
224
|
+
key = normalize_key(name, options)
|
|
225
|
+
version = normalize_version(name, options)
|
|
226
|
+
amount = Integer(amount)
|
|
213
227
|
|
|
214
|
-
lock_file(
|
|
215
|
-
|
|
228
|
+
lock_file(key) do
|
|
229
|
+
entry = read_entry(key, **options)
|
|
216
230
|
|
|
217
|
-
if
|
|
218
|
-
|
|
219
|
-
write(name, num, options)
|
|
220
|
-
num
|
|
221
|
-
else
|
|
222
|
-
write(name, Integer(amount), options)
|
|
231
|
+
if !entry || entry.expired? || entry.mismatched?(version)
|
|
232
|
+
write(name, amount, options)
|
|
223
233
|
amount
|
|
234
|
+
else
|
|
235
|
+
num = entry.value.to_i + amount
|
|
236
|
+
entry = Entry.new(num, expires_at: entry.expires_at, version: entry.version)
|
|
237
|
+
write_entry(key, entry)
|
|
238
|
+
num
|
|
224
239
|
end
|
|
225
240
|
end
|
|
226
241
|
end
|