activesupport 7.2.3.1 → 8.1.4.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 +584 -234
- data/lib/active_support/backtrace_cleaner.rb +72 -1
- data/lib/active_support/benchmark.rb +21 -0
- data/lib/active_support/benchmarkable.rb +3 -2
- data/lib/active_support/cache/file_store.rb +13 -2
- data/lib/active_support/cache/mem_cache_store.rb +17 -14
- data/lib/active_support/cache/memory_store.rb +9 -3
- data/lib/active_support/cache/redis_cache_store.rb +51 -34
- data/lib/active_support/cache/strategy/local_cache.rb +17 -8
- data/lib/active_support/cache/strategy/local_cache_middleware.rb +7 -7
- data/lib/active_support/cache.rb +86 -18
- data/lib/active_support/callbacks.rb +25 -11
- 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 -3
- data/lib/active_support/core_ext/array.rb +7 -7
- data/lib/active_support/core_ext/benchmark.rb +0 -16
- data/lib/active_support/core_ext/big_decimal.rb +1 -1
- data/lib/active_support/core_ext/class/attribute.rb +24 -18
- data/lib/active_support/core_ext/class.rb +2 -2
- data/lib/active_support/core_ext/date/conversions.rb +2 -0
- data/lib/active_support/core_ext/date.rb +5 -5
- data/lib/active_support/core_ext/date_and_time/compatibility.rb +0 -35
- data/lib/active_support/core_ext/date_time/calculations.rb +1 -0
- data/lib/active_support/core_ext/date_time/compatibility.rb +3 -5
- data/lib/active_support/core_ext/date_time.rb +5 -5
- data/lib/active_support/core_ext/digest.rb +1 -1
- data/lib/active_support/core_ext/enumerable.rb +8 -3
- data/lib/active_support/core_ext/erb/util.rb +3 -3
- 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.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 +3 -4
- data/lib/active_support/core_ext/module.rb +11 -11
- data/lib/active_support/core_ext/numeric.rb +3 -3
- data/lib/active_support/core_ext/object/instance_variables.rb +1 -1
- 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.rb +13 -13
- data/lib/active_support/core_ext/pathname.rb +2 -2
- data/lib/active_support/core_ext/range/compare_range.rb +2 -14
- data/lib/active_support/core_ext/range/overlap.rb +3 -3
- data/lib/active_support/core_ext/range/sole.rb +2 -0
- data/lib/active_support/core_ext/range.rb +4 -5
- data/lib/active_support/core_ext/string/filters.rb +2 -0
- data/lib/active_support/core_ext/string/inflections.rb +1 -1
- data/lib/active_support/core_ext/string/multibyte.rb +10 -1
- data/lib/active_support/core_ext/string/output_safety.rb +27 -13
- 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 +11 -2
- data/lib/active_support/core_ext/time/compatibility.rb +2 -27
- data/lib/active_support/core_ext/time/conversions.rb +2 -0
- data/lib/active_support/core_ext/time.rb +5 -5
- data/lib/active_support/current_attributes/test_helper.rb +2 -2
- data/lib/active_support/current_attributes.rb +13 -10
- data/lib/active_support/delegation.rb +25 -44
- data/lib/active_support/dependencies/interlock.rb +11 -5
- data/lib/active_support/dependencies.rb +6 -2
- data/lib/active_support/deprecation/reporting.rb +4 -21
- data/lib/active_support/deprecation.rb +1 -1
- data/lib/active_support/duration.rb +20 -16
- data/lib/active_support/editor.rb +70 -0
- data/lib/active_support/encrypted_configuration.rb +20 -2
- data/lib/active_support/error_reporter.rb +76 -2
- 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 -2
- data/lib/active_support/execution_context.rb +75 -7
- data/lib/active_support/file_update_checker.rb +7 -5
- data/lib/active_support/gem_version.rb +3 -3
- data/lib/active_support/gzip.rb +1 -0
- data/lib/active_support/hash_with_indifferent_access.rb +44 -24
- data/lib/active_support/i18n_railtie.rb +19 -11
- data/lib/active_support/inflector/inflections.rb +34 -16
- data/lib/active_support/inflector/methods.rb +6 -22
- data/lib/active_support/inflector/transliterate.rb +18 -10
- data/lib/active_support/isolated_execution_state.rb +17 -17
- data/lib/active_support/json/decoding.rb +9 -3
- data/lib/active_support/json/encoding.rb +149 -19
- data/lib/active_support/log_subscriber.rb +2 -6
- data/lib/active_support/logger_thread_safe_level.rb +6 -3
- data/lib/active_support/message_encryptors.rb +52 -0
- data/lib/active_support/message_pack/extensions.rb +23 -1
- data/lib/active_support/message_verifiers.rb +52 -0
- data/lib/active_support/messages/rotation_coordinator.rb +9 -0
- data/lib/active_support/messages/rotator.rb +5 -0
- data/lib/active_support/messages/serializer_with_fallback.rb +1 -1
- data/lib/active_support/multibyte/chars.rb +8 -1
- data/lib/active_support/multibyte.rb +4 -0
- data/lib/active_support/notifications/fanout.rb +64 -43
- data/lib/active_support/notifications/instrumenter.rb +1 -1
- data/lib/active_support/notifications.rb +2 -2
- data/lib/active_support/number_helper/number_converter.rb +4 -1
- data/lib/active_support/number_helper/number_to_currency_converter.rb +1 -1
- data/lib/active_support/number_helper/number_to_delimited_converter.rb +3 -4
- data/lib/active_support/number_helper/number_to_phone_converter.rb +3 -7
- data/lib/active_support/number_helper/rounding_helper.rb +1 -1
- data/lib/active_support/number_helper.rb +22 -0
- data/lib/active_support/ordered_options.rb +2 -2
- data/lib/active_support/railtie.rb +32 -9
- data/lib/active_support/security_utils.rb +4 -5
- data/lib/active_support/structured_event_subscriber.rb +99 -0
- data/lib/active_support/subscriber.rb +0 -5
- data/lib/active_support/syntax_error_proxy.rb +9 -1
- data/lib/active_support/tagged_logging.rb +5 -0
- data/lib/active_support/test_case.rb +67 -6
- data/lib/active_support/testing/assertions.rb +118 -27
- data/lib/active_support/testing/autorun.rb +5 -0
- data/lib/active_support/testing/error_reporter_assertions.rb +17 -0
- data/lib/active_support/testing/event_reporter_assertions.rb +227 -0
- data/lib/active_support/testing/isolation.rb +0 -2
- data/lib/active_support/testing/notification_assertions.rb +92 -0
- data/lib/active_support/testing/parallelization/worker.rb +7 -1
- data/lib/active_support/testing/parallelization.rb +17 -0
- data/lib/active_support/testing/tests_without_assertions.rb +1 -1
- data/lib/active_support/testing/time_helpers.rb +9 -4
- data/lib/active_support/time_with_zone.rb +36 -23
- data/lib/active_support/values/time_zone.rb +22 -13
- data/lib/active_support/xml_mini.rb +1 -2
- data/lib/active_support.rb +21 -9
- metadata +33 -17
- data/lib/active_support/core_ext/range/each.rb +0 -24
- data/lib/active_support/proxy_object.rb +0 -20
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module ActiveSupport
|
|
4
|
+
# Provides a DSL for declaring a continuous integration workflow that can be run either locally or in the cloud.
|
|
5
|
+
# Each step is timed, reports success/error, and is aggregated into a collective report that reports total runtime,
|
|
6
|
+
# as well as whether the entire run was successful or not.
|
|
7
|
+
#
|
|
8
|
+
# Example:
|
|
9
|
+
#
|
|
10
|
+
# ActiveSupport::ContinuousIntegration.run do
|
|
11
|
+
# step "Setup", "bin/setup --skip-server"
|
|
12
|
+
# step "Style: Ruby", "bin/rubocop"
|
|
13
|
+
# step "Security: Gem audit", "bin/bundler-audit"
|
|
14
|
+
# step "Tests: Rails", "bin/rails test test:system"
|
|
15
|
+
#
|
|
16
|
+
# if success?
|
|
17
|
+
# step "Signoff: Ready for merge and deploy", "gh signoff"
|
|
18
|
+
# else
|
|
19
|
+
# failure "Skipping signoff; CI failed.", "Fix the issues and try again."
|
|
20
|
+
# end
|
|
21
|
+
# end
|
|
22
|
+
#
|
|
23
|
+
# Starting with Rails 8.1, a default `bin/ci` and `config/ci.rb` file are created to provide out-of-the-box CI.
|
|
24
|
+
class ContinuousIntegration
|
|
25
|
+
COLORS = {
|
|
26
|
+
banner: "\033[1;32m", # Green
|
|
27
|
+
title: "\033[1;35m", # Purple
|
|
28
|
+
subtitle: "\033[1;90m", # Medium Gray
|
|
29
|
+
error: "\033[1;31m", # Red
|
|
30
|
+
success: "\033[1;32m" # Green
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
attr_reader :results
|
|
34
|
+
|
|
35
|
+
# Perform a CI run. Execute each step, show their results and runtime, and exit with a non-zero status if there are any failures.
|
|
36
|
+
#
|
|
37
|
+
# Pass an optional title, subtitle, and a block that declares the steps to be executed.
|
|
38
|
+
#
|
|
39
|
+
# Sets the CI environment variable to "true" to allow for conditional behavior in the app, like enabling eager loading and disabling logging.
|
|
40
|
+
#
|
|
41
|
+
# Example:
|
|
42
|
+
#
|
|
43
|
+
# ActiveSupport::ContinuousIntegration.run do
|
|
44
|
+
# step "Setup", "bin/setup --skip-server"
|
|
45
|
+
# step "Style: Ruby", "bin/rubocop"
|
|
46
|
+
# step "Security: Gem audit", "bin/bundler-audit"
|
|
47
|
+
# step "Tests: Rails", "bin/rails test test:system"
|
|
48
|
+
#
|
|
49
|
+
# if success?
|
|
50
|
+
# step "Signoff: Ready for merge and deploy", "gh signoff"
|
|
51
|
+
# else
|
|
52
|
+
# failure "Skipping signoff; CI failed.", "Fix the issues and try again."
|
|
53
|
+
# end
|
|
54
|
+
# end
|
|
55
|
+
def self.run(title = "Continuous Integration", subtitle = "Running tests, style checks, and security audits", &block)
|
|
56
|
+
new.tap do |ci|
|
|
57
|
+
ENV["CI"] = "true"
|
|
58
|
+
ci.heading title, subtitle, padding: false
|
|
59
|
+
ci.report(title, &block)
|
|
60
|
+
abort unless ci.success?
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def initialize
|
|
65
|
+
@results = []
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
# Declare a step with a title and a command. The command can either be given as a single string or as multiple
|
|
69
|
+
# strings that will be passed to `system` as individual arguments (and therefore correctly escaped for paths etc).
|
|
70
|
+
#
|
|
71
|
+
# Examples:
|
|
72
|
+
#
|
|
73
|
+
# step "Setup", "bin/setup"
|
|
74
|
+
# step "Single test", "bin/rails", "test", "--name", "test_that_is_one"
|
|
75
|
+
def step(title, *command)
|
|
76
|
+
heading title, command.join(" "), type: :title
|
|
77
|
+
report(title) { results << system(*command) }
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
# Returns true if all steps were successful.
|
|
81
|
+
def success?
|
|
82
|
+
results.all?
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
# Display an error heading with the title and optional subtitle to reflect that the run failed.
|
|
86
|
+
def failure(title, subtitle = nil)
|
|
87
|
+
heading title, subtitle, type: :error
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
# Display a colorized heading followed by an optional subtitle.
|
|
91
|
+
#
|
|
92
|
+
# Examples:
|
|
93
|
+
#
|
|
94
|
+
# heading "Smoke Testing", "End-to-end tests verifying key functionality", padding: false
|
|
95
|
+
# heading "Skipping video encoding tests", "Install FFmpeg to run these tests", type: :error
|
|
96
|
+
#
|
|
97
|
+
# See ActiveSupport::ContinuousIntegration::COLORS for a complete list of options.
|
|
98
|
+
def heading(heading, subtitle = nil, type: :banner, padding: true)
|
|
99
|
+
echo "#{padding ? "\n\n" : ""}#{heading}", type: type
|
|
100
|
+
echo "#{subtitle}#{padding ? "\n" : ""}", type: :subtitle if subtitle
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
# Echo text to the terminal in the color corresponding to the type of the text.
|
|
104
|
+
#
|
|
105
|
+
# Examples:
|
|
106
|
+
#
|
|
107
|
+
# echo "This is going to be green!", type: :success
|
|
108
|
+
# echo "This is going to be red!", type: :error
|
|
109
|
+
#
|
|
110
|
+
# See ActiveSupport::ContinuousIntegration::COLORS for a complete list of options.
|
|
111
|
+
def echo(text, type:)
|
|
112
|
+
puts colorize(text, type)
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
# :nodoc:
|
|
116
|
+
def report(title, &block)
|
|
117
|
+
Signal.trap("INT") { abort colorize(:error, "\n❌ #{title} interrupted") }
|
|
118
|
+
|
|
119
|
+
ci = self.class.new
|
|
120
|
+
elapsed = timing { ci.instance_eval(&block) }
|
|
121
|
+
|
|
122
|
+
if ci.success?
|
|
123
|
+
echo "\n✅ #{title} passed in #{elapsed}", type: :success
|
|
124
|
+
else
|
|
125
|
+
echo "\n❌ #{title} failed in #{elapsed}", type: :error
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
results.concat ci.results
|
|
129
|
+
ensure
|
|
130
|
+
Signal.trap("INT", "-")
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
private
|
|
134
|
+
def timing
|
|
135
|
+
started_at = Time.now.to_f
|
|
136
|
+
yield
|
|
137
|
+
min, sec = (Time.now.to_f - started_at).divmod(60)
|
|
138
|
+
"#{"#{min}m" if min > 0}%.2fs" % sec
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
def colorize(text, type)
|
|
142
|
+
"#{COLORS.fetch(type)}#{text}\033[0m"
|
|
143
|
+
end
|
|
144
|
+
end
|
|
145
|
+
end
|
|
@@ -16,11 +16,11 @@ class Array
|
|
|
16
16
|
# ==== Options
|
|
17
17
|
#
|
|
18
18
|
# * <tt>:words_connector</tt> - The sign or word used to join all but the last
|
|
19
|
-
# element in arrays with three or more elements (default: ", ").
|
|
19
|
+
# element in arrays with three or more elements (default: <tt>", "</tt>).
|
|
20
20
|
# * <tt>:last_word_connector</tt> - The sign or word used to join the last element
|
|
21
|
-
# in arrays with three or more elements (default: ", and ").
|
|
21
|
+
# in arrays with three or more elements (default: <tt>", and "</tt>).
|
|
22
22
|
# * <tt>:two_words_connector</tt> - The sign or word used to join the elements
|
|
23
|
-
# in arrays with two elements (default: " and ").
|
|
23
|
+
# in arrays with two elements (default: <tt>" and "</tt>).
|
|
24
24
|
# * <tt>:locale</tt> - If +i18n+ is available, you can set a locale and use
|
|
25
25
|
# the connector options defined on the 'support.array' namespace in the
|
|
26
26
|
# corresponding dictionary file.
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
3
|
+
require_relative "array/wrap"
|
|
4
|
+
require_relative "array/access"
|
|
5
|
+
require_relative "array/conversions"
|
|
6
|
+
require_relative "array/extract"
|
|
7
|
+
require_relative "array/extract_options"
|
|
8
|
+
require_relative "array/grouping"
|
|
9
|
+
require_relative "array/inquiry"
|
|
@@ -1,17 +1 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "benchmark"
|
|
4
|
-
return if Benchmark.respond_to?(:ms)
|
|
5
|
-
|
|
6
|
-
class << Benchmark
|
|
7
|
-
# Benchmark realtime in milliseconds.
|
|
8
|
-
#
|
|
9
|
-
# Benchmark.realtime { User.all }
|
|
10
|
-
# # => 8.0e-05
|
|
11
|
-
#
|
|
12
|
-
# Benchmark.ms { User.all }
|
|
13
|
-
# # => 0.074
|
|
14
|
-
def ms(&block)
|
|
15
|
-
1000 * realtime(&block)
|
|
16
|
-
end
|
|
17
|
-
end
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require "active_support/core_ext/module/redefine_method"
|
|
4
|
+
require "active_support/class_attribute"
|
|
4
5
|
|
|
5
6
|
class Class
|
|
6
7
|
# Declare a class-level attribute whose value is inheritable by subclasses.
|
|
@@ -91,24 +92,31 @@ class Class
|
|
|
91
92
|
raise TypeError, "#{name.inspect} is not a symbol nor a string"
|
|
92
93
|
end
|
|
93
94
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
RUBY
|
|
95
|
+
name = name.to_sym
|
|
96
|
+
namespaced_name = :"__class_attr_#{name}"
|
|
97
|
+
::ActiveSupport::ClassAttribute.redefine(self, name, namespaced_name, default)
|
|
98
98
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
defined?(@#{name}) ? @#{name} : self.class.#{name}
|
|
102
|
-
end
|
|
103
|
-
RUBY
|
|
99
|
+
class_methods << "def #{name}; #{namespaced_name}; end"
|
|
100
|
+
class_methods << "def #{name}=(value); self.#{namespaced_name} = value; end"
|
|
104
101
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
102
|
+
if singleton_class?
|
|
103
|
+
methods << <<~RUBY if instance_reader
|
|
104
|
+
silence_redefinition_of_method(:#{name})
|
|
105
|
+
def #{name}
|
|
106
|
+
self.singleton_class.#{name}
|
|
107
|
+
end
|
|
108
|
+
RUBY
|
|
109
|
+
else
|
|
110
|
+
methods << <<~RUBY if instance_reader
|
|
111
|
+
silence_redefinition_of_method def #{name}
|
|
112
|
+
if defined?(@#{name})
|
|
113
|
+
@#{name}
|
|
114
|
+
else
|
|
115
|
+
self.class.#{name}
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
RUBY
|
|
119
|
+
end
|
|
112
120
|
|
|
113
121
|
methods << <<~RUBY if instance_writer
|
|
114
122
|
silence_redefinition_of_method(:#{name}=)
|
|
@@ -125,7 +133,5 @@ class Class
|
|
|
125
133
|
|
|
126
134
|
location = caller_locations(1, 1).first
|
|
127
135
|
class_eval(["class << self", *class_methods, "end", *methods].join(";").tr("\n", ";"), location.path, location.lineno)
|
|
128
|
-
|
|
129
|
-
attrs.each { |name| public_send("#{name}=", default) }
|
|
130
136
|
end
|
|
131
137
|
end
|
|
@@ -17,6 +17,7 @@ class Date
|
|
|
17
17
|
date.strftime("%B #{day_format}, %Y") # => "April 25th, 2007"
|
|
18
18
|
},
|
|
19
19
|
rfc822: "%d %b %Y",
|
|
20
|
+
rfc2822: "%d %b %Y",
|
|
20
21
|
iso8601: lambda { |date| date.iso8601 }
|
|
21
22
|
}
|
|
22
23
|
|
|
@@ -34,6 +35,7 @@ class Date
|
|
|
34
35
|
# date.to_fs(:long) # => "November 10, 2007"
|
|
35
36
|
# date.to_fs(:long_ordinal) # => "November 10th, 2007"
|
|
36
37
|
# date.to_fs(:rfc822) # => "10 Nov 2007"
|
|
38
|
+
# date.to_fs(:rfc2822) # => "10 Nov 2007"
|
|
37
39
|
# date.to_fs(:iso8601) # => "2007-11-10"
|
|
38
40
|
#
|
|
39
41
|
# == Adding your own date formats to to_fs
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
require_relative "date/acts_like"
|
|
4
|
+
require_relative "date/blank"
|
|
5
|
+
require_relative "date/calculations"
|
|
6
|
+
require_relative "date/conversions"
|
|
7
|
+
require_relative "date/zones"
|
|
@@ -5,41 +5,6 @@ require "active_support/core_ext/module/redefine_method"
|
|
|
5
5
|
|
|
6
6
|
module DateAndTime
|
|
7
7
|
module Compatibility
|
|
8
|
-
# If true, +to_time+ preserves the timezone offset of receiver.
|
|
9
|
-
#
|
|
10
|
-
# NOTE: With Ruby 2.4+ the default for +to_time+ changed from
|
|
11
|
-
# converting to the local system time, to preserving the offset
|
|
12
|
-
# of the receiver. For backwards compatibility we're overriding
|
|
13
|
-
# this behavior, but new apps will have an initializer that sets
|
|
14
|
-
# this to true, because the new behavior is preferred.
|
|
15
|
-
mattr_accessor :preserve_timezone, instance_accessor: false, default: nil
|
|
16
|
-
|
|
17
|
-
singleton_class.silence_redefinition_of_method :preserve_timezone
|
|
18
|
-
|
|
19
|
-
#--
|
|
20
|
-
# This re-implements the behaviour of the mattr_reader, instead
|
|
21
|
-
# of prepending on to it, to avoid overcomplicating a module that
|
|
22
|
-
# is in turn included in several places. This will all go away in
|
|
23
|
-
# Rails 8.0 anyway.
|
|
24
|
-
def self.preserve_timezone # :nodoc:
|
|
25
|
-
if @@preserve_timezone.nil?
|
|
26
|
-
# Only warn once, the first time the value is used (which should
|
|
27
|
-
# be the first time #to_time is called).
|
|
28
|
-
ActiveSupport.deprecator.warn(
|
|
29
|
-
"to_time will always preserve the timezone offset of the receiver in Rails 8.0. " \
|
|
30
|
-
"To opt in to the new behavior, set `ActiveSupport.to_time_preserves_timezone = true`."
|
|
31
|
-
)
|
|
32
|
-
|
|
33
|
-
@@preserve_timezone = false
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
@@preserve_timezone
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
def preserve_timezone # :nodoc:
|
|
40
|
-
Compatibility.preserve_timezone
|
|
41
|
-
end
|
|
42
|
-
|
|
43
8
|
# Change the output of <tt>ActiveSupport::TimeZone.utc_to_local</tt>.
|
|
44
9
|
#
|
|
45
10
|
# When +true+, it returns local times with a UTC offset, with +false+ local
|
|
@@ -80,6 +80,7 @@ class DateTime
|
|
|
80
80
|
# largest to smallest. This order can affect the result around the end of a
|
|
81
81
|
# month.
|
|
82
82
|
def advance(options)
|
|
83
|
+
options = options.dup
|
|
83
84
|
unless options[:weeks].nil?
|
|
84
85
|
options[:weeks], partial_weeks = options[:weeks].divmod(1)
|
|
85
86
|
options[:days] = options.fetch(:days, 0) + 7 * partial_weeks
|
|
@@ -8,11 +8,9 @@ class DateTime
|
|
|
8
8
|
|
|
9
9
|
silence_redefinition_of_method :to_time
|
|
10
10
|
|
|
11
|
-
#
|
|
12
|
-
# as +self
|
|
13
|
-
# in the local system timezone depending on the setting of
|
|
14
|
-
# on the setting of +ActiveSupport.to_time_preserves_timezone+.
|
|
11
|
+
# Return an instance of +Time+ with the same UTC offset
|
|
12
|
+
# as +self+.
|
|
15
13
|
def to_time
|
|
16
|
-
|
|
14
|
+
getlocal(utc_offset)
|
|
17
15
|
end
|
|
18
16
|
end
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
require_relative "date_time/acts_like"
|
|
4
|
+
require_relative "date_time/blank"
|
|
5
|
+
require_relative "date_time/calculations"
|
|
6
|
+
require_relative "date_time/compatibility"
|
|
7
|
+
require_relative "date_time/conversions"
|
|
@@ -192,9 +192,14 @@ module Enumerable
|
|
|
192
192
|
# # => [ Person.find(1), Person.find(5), Person.find(3) ]
|
|
193
193
|
#
|
|
194
194
|
# If the +series+ include keys that have no corresponding element in the Enumerable, these are ignored.
|
|
195
|
-
# If the Enumerable has additional elements that aren't named in the +series+, these are not included in the result
|
|
196
|
-
|
|
197
|
-
|
|
195
|
+
# If the Enumerable has additional elements that aren't named in the +series+, these are not included in the result, unless
|
|
196
|
+
# the +filter+ option is set to +false+.
|
|
197
|
+
def in_order_of(key, series, filter: true)
|
|
198
|
+
if filter
|
|
199
|
+
group_by(&key).values_at(*series).compact.flatten(1)
|
|
200
|
+
else
|
|
201
|
+
sort_by { |v| series.index(v.public_send(key)) || series.size }
|
|
202
|
+
end
|
|
198
203
|
end
|
|
199
204
|
|
|
200
205
|
# Returns the sole item in the enumerable. If there are no items, or more
|
|
@@ -12,7 +12,7 @@ module ActiveSupport
|
|
|
12
12
|
if s.html_safe?
|
|
13
13
|
s
|
|
14
14
|
else
|
|
15
|
-
super(
|
|
15
|
+
super(s)
|
|
16
16
|
end
|
|
17
17
|
end
|
|
18
18
|
alias :unwrapped_html_escape :html_escape # :nodoc:
|
|
@@ -61,7 +61,7 @@ class ERB
|
|
|
61
61
|
# html_escape_once('<< Accept & Checkout')
|
|
62
62
|
# # => "<< Accept & Checkout"
|
|
63
63
|
def html_escape_once(s)
|
|
64
|
-
|
|
64
|
+
s.to_s.gsub(HTML_ESCAPE_ONCE_REGEXP, HTML_ESCAPE).html_safe
|
|
65
65
|
end
|
|
66
66
|
|
|
67
67
|
module_function :html_escape_once
|
|
@@ -169,7 +169,7 @@ class ERB
|
|
|
169
169
|
while !source.eos?
|
|
170
170
|
pos = source.pos
|
|
171
171
|
source.scan_until(/(?:#{start_re}|#{finish_re})/)
|
|
172
|
-
|
|
172
|
+
return [[:PLAIN, source.string]] unless source.matched?
|
|
173
173
|
len = source.pos - source.matched.bytesize - pos
|
|
174
174
|
|
|
175
175
|
case source.matched
|
|
@@ -1,18 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
class Hash
|
|
4
|
-
# Returns a hash that includes everything except given keys.
|
|
5
|
-
# hash = { a: true, b: false, c: nil }
|
|
6
|
-
# hash.except(:c) # => { a: true, b: false }
|
|
7
|
-
# hash.except(:a, :b) # => { c: nil }
|
|
8
|
-
# hash # => { a: true, b: false, c: nil }
|
|
9
|
-
#
|
|
10
|
-
# This is useful for limiting a set of parameters to everything but a few known toggles:
|
|
11
|
-
# @person.update(params[:person].except(:admin))
|
|
12
|
-
def except(*keys)
|
|
13
|
-
slice(*self.keys - keys)
|
|
14
|
-
end unless method_defined?(:except)
|
|
15
|
-
|
|
16
4
|
# Removes the given keys from hash and returns it.
|
|
17
5
|
# hash = { a: true, b: false, c: nil }
|
|
18
6
|
# hash.except!(:c) # => { a: true, b: false }
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
3
|
+
require_relative "hash/conversions"
|
|
4
|
+
require_relative "hash/deep_merge"
|
|
5
|
+
require_relative "hash/deep_transform_values"
|
|
6
|
+
require_relative "hash/except"
|
|
7
|
+
require_relative "hash/indifferent_access"
|
|
8
|
+
require_relative "hash/keys"
|
|
9
|
+
require_relative "hash/reverse_merge"
|
|
10
|
+
require_relative "hash/slice"
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
require_relative "integer/multiple"
|
|
4
|
+
require_relative "integer/inflections"
|
|
5
|
+
require_relative "integer/time"
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
require_relative "kernel/concern"
|
|
4
|
+
require_relative "kernel/reporting"
|
|
5
|
+
require_relative "kernel/singleton_class"
|
|
@@ -24,14 +24,13 @@ class Module
|
|
|
24
24
|
|
|
25
25
|
def attr_internal_naming_format=(format)
|
|
26
26
|
if format.start_with?("@")
|
|
27
|
-
|
|
28
|
-
Setting `attr_internal_naming_format` with a `@` prefix is
|
|
27
|
+
raise ArgumentError, <<~MESSAGE.squish
|
|
28
|
+
Setting `attr_internal_naming_format` with a `@` prefix is not supported.
|
|
29
29
|
|
|
30
30
|
You can simply replace #{format.inspect} by #{format.delete_prefix("@").inspect}.
|
|
31
31
|
MESSAGE
|
|
32
|
-
|
|
33
|
-
format = format.delete_prefix("@")
|
|
34
32
|
end
|
|
33
|
+
|
|
35
34
|
@attr_internal_naming_format = format
|
|
36
35
|
end
|
|
37
36
|
end
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
3
|
+
require_relative "module/aliasing"
|
|
4
|
+
require_relative "module/introspection"
|
|
5
|
+
require_relative "module/anonymous"
|
|
6
|
+
require_relative "module/attribute_accessors"
|
|
7
|
+
require_relative "module/attribute_accessors_per_thread"
|
|
8
|
+
require_relative "module/attr_internal"
|
|
9
|
+
require_relative "module/concerning"
|
|
10
|
+
require_relative "module/delegation"
|
|
11
|
+
require_relative "module/deprecation"
|
|
12
|
+
require_relative "module/redefine_method"
|
|
13
|
+
require_relative "module/remove_method"
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
require_relative "numeric/bytes"
|
|
4
|
+
require_relative "numeric/time"
|
|
5
|
+
require_relative "numeric/conversions"
|