activesupport 6.0.3.7 → 7.0.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of activesupport might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/CHANGELOG.md +220 -533
- data/MIT-LICENSE +1 -1
- data/README.rdoc +1 -1
- data/lib/active_support/actionable_error.rb +1 -1
- data/lib/active_support/array_inquirer.rb +2 -2
- data/lib/active_support/backtrace_cleaner.rb +3 -3
- data/lib/active_support/benchmarkable.rb +3 -3
- data/lib/active_support/cache/file_store.rb +18 -11
- data/lib/active_support/cache/mem_cache_store.rb +143 -37
- data/lib/active_support/cache/memory_store.rb +56 -28
- data/lib/active_support/cache/null_store.rb +10 -2
- data/lib/active_support/cache/redis_cache_store.rb +63 -88
- data/lib/active_support/cache/strategy/local_cache.rb +46 -57
- data/lib/active_support/cache.rb +273 -82
- data/lib/active_support/callbacks.rb +226 -118
- data/lib/active_support/code_generator.rb +65 -0
- data/lib/active_support/concern.rb +49 -5
- data/lib/active_support/concurrency/load_interlock_aware_monitor.rb +2 -4
- data/lib/active_support/concurrency/share_lock.rb +2 -2
- data/lib/active_support/configurable.rb +9 -6
- data/lib/active_support/configuration_file.rb +51 -0
- data/lib/active_support/core_ext/array/access.rb +1 -5
- data/lib/active_support/core_ext/array/conversions.rb +9 -7
- data/lib/active_support/core_ext/array/deprecated_conversions.rb +25 -0
- data/lib/active_support/core_ext/array/grouping.rb +6 -6
- data/lib/active_support/core_ext/array.rb +1 -0
- data/lib/active_support/core_ext/benchmark.rb +2 -2
- data/lib/active_support/core_ext/big_decimal/conversions.rb +1 -1
- data/lib/active_support/core_ext/class/attribute.rb +34 -44
- data/lib/active_support/core_ext/class/subclasses.rb +21 -40
- data/lib/active_support/core_ext/date/blank.rb +1 -1
- data/lib/active_support/core_ext/date/calculations.rb +4 -4
- data/lib/active_support/core_ext/date/conversions.rb +5 -4
- data/lib/active_support/core_ext/date/deprecated_conversions.rb +26 -0
- data/lib/active_support/core_ext/date.rb +1 -0
- data/lib/active_support/core_ext/date_and_time/calculations.rb +13 -0
- data/lib/active_support/core_ext/date_and_time/compatibility.rb +15 -0
- data/lib/active_support/core_ext/date_time/blank.rb +1 -1
- data/lib/active_support/core_ext/date_time/conversions.rb +5 -5
- data/lib/active_support/core_ext/date_time/deprecated_conversions.rb +22 -0
- data/lib/active_support/core_ext/date_time.rb +1 -0
- data/lib/active_support/core_ext/digest/uuid.rb +39 -13
- data/lib/active_support/core_ext/enumerable.rb +139 -15
- data/lib/active_support/core_ext/file/atomic.rb +1 -1
- data/lib/active_support/core_ext/hash/conversions.rb +2 -2
- data/lib/active_support/core_ext/hash/deep_transform_values.rb +1 -1
- data/lib/active_support/core_ext/hash/except.rb +1 -1
- data/lib/active_support/core_ext/hash/keys.rb +2 -2
- data/lib/active_support/core_ext/hash/slice.rb +3 -2
- data/lib/active_support/core_ext/kernel/reporting.rb +4 -4
- data/lib/active_support/core_ext/load_error.rb +1 -1
- data/lib/active_support/core_ext/module/attr_internal.rb +2 -2
- data/lib/active_support/core_ext/module/attribute_accessors.rb +25 -29
- data/lib/active_support/core_ext/module/attribute_accessors_per_thread.rb +26 -13
- data/lib/active_support/core_ext/module/concerning.rb +8 -2
- data/lib/active_support/core_ext/module/delegation.rb +40 -36
- data/lib/active_support/core_ext/module/introspection.rb +1 -25
- data/lib/active_support/core_ext/name_error.rb +23 -2
- data/lib/active_support/core_ext/numeric/conversions.rb +79 -72
- data/lib/active_support/core_ext/numeric/deprecated_conversions.rb +60 -0
- data/lib/active_support/core_ext/numeric.rb +1 -0
- data/lib/active_support/core_ext/object/blank.rb +2 -2
- data/lib/active_support/core_ext/object/deep_dup.rb +1 -1
- data/lib/active_support/core_ext/object/duplicable.rb +11 -0
- data/lib/active_support/core_ext/object/json.rb +42 -26
- data/lib/active_support/core_ext/object/to_query.rb +2 -2
- data/lib/active_support/core_ext/object/try.rb +20 -20
- data/lib/active_support/core_ext/object/with_options.rb +20 -1
- data/lib/active_support/core_ext/pathname/existence.rb +21 -0
- data/lib/active_support/core_ext/pathname.rb +3 -0
- data/lib/active_support/core_ext/range/compare_range.rb +6 -25
- data/lib/active_support/core_ext/range/conversions.rb +8 -8
- data/lib/active_support/core_ext/range/deprecated_conversions.rb +26 -0
- data/lib/active_support/core_ext/range/each.rb +1 -1
- data/lib/active_support/core_ext/range/include_time_with_zone.rb +4 -20
- data/lib/active_support/core_ext/range.rb +1 -1
- data/lib/active_support/core_ext/regexp.rb +8 -1
- data/lib/active_support/core_ext/string/access.rb +5 -24
- data/lib/active_support/core_ext/string/conversions.rb +1 -0
- data/lib/active_support/core_ext/string/filters.rb +1 -1
- data/lib/active_support/core_ext/string/inflections.rb +39 -5
- data/lib/active_support/core_ext/string/inquiry.rb +1 -0
- data/lib/active_support/core_ext/string/multibyte.rb +2 -2
- data/lib/active_support/core_ext/string/output_safety.rb +69 -45
- data/lib/active_support/core_ext/string/starts_ends_with.rb +2 -2
- data/lib/active_support/core_ext/symbol/starts_ends_with.rb +6 -0
- data/lib/active_support/core_ext/symbol.rb +3 -0
- data/lib/active_support/core_ext/time/calculations.rb +26 -6
- data/lib/active_support/core_ext/time/conversions.rb +6 -3
- data/lib/active_support/core_ext/time/deprecated_conversions.rb +22 -0
- data/lib/active_support/core_ext/time/zones.rb +4 -19
- data/lib/active_support/core_ext/time.rb +1 -0
- data/lib/active_support/core_ext/uri.rb +3 -23
- data/lib/active_support/core_ext.rb +2 -1
- data/lib/active_support/current_attributes/test_helper.rb +13 -0
- data/lib/active_support/current_attributes.rb +39 -16
- data/lib/active_support/dependencies/interlock.rb +10 -18
- data/lib/active_support/dependencies/require_dependency.rb +28 -0
- data/lib/active_support/dependencies.rb +58 -764
- data/lib/active_support/deprecation/behaviors.rb +19 -3
- data/lib/active_support/deprecation/disallowed.rb +56 -0
- data/lib/active_support/deprecation/instance_delegator.rb +0 -1
- data/lib/active_support/deprecation/method_wrappers.rb +6 -5
- data/lib/active_support/deprecation/proxy_wrappers.rb +4 -4
- data/lib/active_support/deprecation/reporting.rb +50 -7
- data/lib/active_support/deprecation.rb +6 -1
- data/lib/active_support/descendants_tracker.rb +177 -64
- data/lib/active_support/digest.rb +5 -3
- data/lib/active_support/duration/iso8601_parser.rb +3 -3
- data/lib/active_support/duration/iso8601_serializer.rb +24 -10
- data/lib/active_support/duration.rb +134 -55
- data/lib/active_support/encrypted_configuration.rb +11 -1
- data/lib/active_support/encrypted_file.rb +20 -3
- data/lib/active_support/environment_inquirer.rb +20 -0
- data/lib/active_support/error_reporter.rb +117 -0
- data/lib/active_support/evented_file_update_checker.rb +70 -134
- data/lib/active_support/execution_context/test_helper.rb +13 -0
- data/lib/active_support/execution_context.rb +53 -0
- data/lib/active_support/execution_wrapper.rb +30 -4
- data/lib/active_support/executor/test_helper.rb +7 -0
- data/lib/active_support/fork_tracker.rb +71 -0
- data/lib/active_support/gem_version.rb +3 -3
- data/lib/active_support/hash_with_indifferent_access.rb +51 -25
- data/lib/active_support/html_safe_translation.rb +43 -0
- data/lib/active_support/i18n.rb +1 -0
- data/lib/active_support/i18n_railtie.rb +14 -19
- data/lib/active_support/inflector/inflections.rb +24 -9
- data/lib/active_support/inflector/methods.rb +29 -49
- data/lib/active_support/inflector/transliterate.rb +4 -4
- data/lib/active_support/isolated_execution_state.rb +56 -0
- data/lib/active_support/json/decoding.rb +4 -4
- data/lib/active_support/json/encoding.rb +8 -4
- data/lib/active_support/key_generator.rb +19 -2
- data/lib/active_support/locale/en.yml +8 -4
- data/lib/active_support/log_subscriber.rb +21 -3
- data/lib/active_support/logger.rb +1 -1
- data/lib/active_support/logger_silence.rb +2 -26
- data/lib/active_support/logger_thread_safe_level.rb +34 -21
- data/lib/active_support/message_encryptor.rb +12 -10
- data/lib/active_support/message_verifier.rb +50 -18
- data/lib/active_support/messages/metadata.rb +11 -3
- data/lib/active_support/messages/rotation_configuration.rb +2 -1
- data/lib/active_support/messages/rotator.rb +6 -5
- data/lib/active_support/multibyte/chars.rb +13 -52
- data/lib/active_support/multibyte/unicode.rb +1 -87
- data/lib/active_support/multibyte.rb +1 -1
- data/lib/active_support/notifications/fanout.rb +110 -69
- data/lib/active_support/notifications/instrumenter.rb +37 -29
- data/lib/active_support/notifications.rb +47 -26
- data/lib/active_support/number_helper/number_converter.rb +2 -4
- data/lib/active_support/number_helper/number_to_currency_converter.rb +10 -9
- data/lib/active_support/number_helper/number_to_delimited_converter.rb +1 -1
- data/lib/active_support/number_helper/number_to_human_converter.rb +1 -1
- data/lib/active_support/number_helper/number_to_human_size_converter.rb +2 -2
- data/lib/active_support/number_helper/number_to_phone_converter.rb +1 -1
- data/lib/active_support/number_helper/number_to_rounded_converter.rb +9 -5
- data/lib/active_support/number_helper/rounding_helper.rb +12 -32
- data/lib/active_support/number_helper.rb +29 -16
- data/lib/active_support/option_merger.rb +9 -16
- data/lib/active_support/ordered_hash.rb +1 -1
- data/lib/active_support/ordered_options.rb +8 -2
- data/lib/active_support/parameter_filter.rb +21 -11
- data/lib/active_support/per_thread_registry.rb +6 -1
- data/lib/active_support/rails.rb +1 -4
- data/lib/active_support/railtie.rb +77 -5
- data/lib/active_support/rescuable.rb +6 -6
- data/lib/active_support/ruby_features.rb +7 -0
- data/lib/active_support/secure_compare_rotator.rb +51 -0
- data/lib/active_support/security_utils.rb +19 -12
- data/lib/active_support/string_inquirer.rb +2 -2
- data/lib/active_support/subscriber.rb +19 -25
- data/lib/active_support/tagged_logging.rb +31 -6
- data/lib/active_support/test_case.rb +9 -21
- data/lib/active_support/testing/assertions.rb +49 -12
- data/lib/active_support/testing/deprecation.rb +52 -1
- data/lib/active_support/testing/isolation.rb +2 -2
- data/lib/active_support/testing/method_call_assertions.rb +5 -5
- data/lib/active_support/testing/parallelization/server.rb +82 -0
- data/lib/active_support/testing/parallelization/worker.rb +103 -0
- data/lib/active_support/testing/parallelization.rb +16 -95
- data/lib/active_support/testing/parallelize_executor.rb +76 -0
- data/lib/active_support/testing/stream.rb +3 -5
- data/lib/active_support/testing/tagged_logging.rb +1 -1
- data/lib/active_support/testing/time_helpers.rb +53 -5
- data/lib/active_support/time_with_zone.rb +120 -55
- data/lib/active_support/values/time_zone.rb +49 -18
- data/lib/active_support/xml_mini/jdom.rb +1 -1
- data/lib/active_support/xml_mini/libxml.rb +5 -5
- data/lib/active_support/xml_mini/libxmlsax.rb +1 -1
- data/lib/active_support/xml_mini/nokogiri.rb +4 -4
- data/lib/active_support/xml_mini/nokogirisax.rb +1 -1
- data/lib/active_support/xml_mini/rexml.rb +9 -2
- data/lib/active_support/xml_mini.rb +5 -4
- data/lib/active_support.rb +29 -1
- metadata +46 -45
- data/lib/active_support/core_ext/array/prepend_and_append.rb +0 -5
- data/lib/active_support/core_ext/hash/compact.rb +0 -5
- data/lib/active_support/core_ext/hash/transform_values.rb +0 -5
- data/lib/active_support/core_ext/marshal.rb +0 -24
- data/lib/active_support/core_ext/module/reachable.rb +0 -6
- data/lib/active_support/core_ext/numeric/inquiry.rb +0 -5
- data/lib/active_support/core_ext/range/include_range.rb +0 -9
- data/lib/active_support/dependencies/zeitwerk_integration.rb +0 -117
@@ -17,14 +17,12 @@ module ActiveSupport
|
|
17
17
|
ActiveSupport::Dependencies.interlock.permit_concurrent_loads { super }
|
18
18
|
end
|
19
19
|
|
20
|
-
def synchronize
|
20
|
+
def synchronize(&block)
|
21
21
|
Thread.handle_interrupt(EXCEPTION_NEVER) do
|
22
22
|
mon_enter
|
23
23
|
|
24
24
|
begin
|
25
|
-
Thread.handle_interrupt(EXCEPTION_IMMEDIATE)
|
26
|
-
yield
|
27
|
-
end
|
25
|
+
Thread.handle_interrupt(EXCEPTION_IMMEDIATE, &block)
|
28
26
|
ensure
|
29
27
|
mon_exit
|
30
28
|
end
|
@@ -215,9 +215,9 @@ module ActiveSupport
|
|
215
215
|
@waiting.any? { |t, (p, _)| compatible.include?(p) && @waiting.all? { |t2, (_, c2)| t == t2 || c2.include?(p) } }
|
216
216
|
end
|
217
217
|
|
218
|
-
def wait_for(method)
|
218
|
+
def wait_for(method, &block)
|
219
219
|
@sleeping[Thread.current] = method
|
220
|
-
@cv.wait_while
|
220
|
+
@cv.wait_while(&block)
|
221
221
|
ensure
|
222
222
|
@sleeping.delete Thread.current
|
223
223
|
end
|
@@ -5,7 +5,7 @@ require "active_support/ordered_options"
|
|
5
5
|
|
6
6
|
module ActiveSupport
|
7
7
|
# Configurable provides a <tt>config</tt> method to store and retrieve
|
8
|
-
# configuration options as an <tt>
|
8
|
+
# configuration options as an <tt>OrderedOptions</tt>.
|
9
9
|
module Configurable
|
10
10
|
extend ActiveSupport::Concern
|
11
11
|
|
@@ -94,17 +94,19 @@ module ActiveSupport
|
|
94
94
|
# User.new.allowed_access = true # => NoMethodError
|
95
95
|
# User.new.allowed_access # => NoMethodError
|
96
96
|
#
|
97
|
-
# Also you can pass a block to set up the attribute with a default value.
|
97
|
+
# Also you can pass <tt>default</tt> or a block to set up the attribute with a default value.
|
98
98
|
#
|
99
99
|
# class User
|
100
100
|
# include ActiveSupport::Configurable
|
101
|
+
# config_accessor :allowed_access, default: false
|
101
102
|
# config_accessor :hair_colors do
|
102
103
|
# [:brown, :black, :blonde, :red]
|
103
104
|
# end
|
104
105
|
# end
|
105
106
|
#
|
107
|
+
# User.allowed_access # => false
|
106
108
|
# User.hair_colors # => [:brown, :black, :blonde, :red]
|
107
|
-
def config_accessor(*names, instance_reader: true, instance_writer: true, instance_accessor: true) # :doc:
|
109
|
+
def config_accessor(*names, instance_reader: true, instance_writer: true, instance_accessor: true, default: nil) # :doc:
|
108
110
|
names.each do |name|
|
109
111
|
raise NameError.new("invalid config attribute name") unless /\A[_A-Za-z]\w*\z/.match?(name)
|
110
112
|
|
@@ -118,15 +120,16 @@ module ActiveSupport
|
|
118
120
|
class_eval reader, __FILE__, reader_line if instance_reader
|
119
121
|
class_eval writer, __FILE__, writer_line if instance_writer
|
120
122
|
end
|
121
|
-
|
123
|
+
|
124
|
+
send("#{name}=", block_given? ? yield : default)
|
122
125
|
end
|
123
126
|
end
|
124
127
|
private :config_accessor
|
125
128
|
end
|
126
129
|
|
127
|
-
# Reads and writes attributes from a configuration <tt>
|
130
|
+
# Reads and writes attributes from a configuration <tt>OrderedOptions</tt>.
|
128
131
|
#
|
129
|
-
# require
|
132
|
+
# require "active_support/configurable"
|
130
133
|
#
|
131
134
|
# class User
|
132
135
|
# include ActiveSupport::Configurable
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ActiveSupport
|
4
|
+
# Reads a YAML configuration file, evaluating any ERB, then
|
5
|
+
# parsing the resulting YAML.
|
6
|
+
#
|
7
|
+
# Warns in case of YAML confusing characters, like invisible
|
8
|
+
# non-breaking spaces.
|
9
|
+
class ConfigurationFile # :nodoc:
|
10
|
+
class FormatError < StandardError; end
|
11
|
+
|
12
|
+
def initialize(content_path)
|
13
|
+
@content_path = content_path.to_s
|
14
|
+
@content = read content_path
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.parse(content_path, **options)
|
18
|
+
new(content_path).parse(**options)
|
19
|
+
end
|
20
|
+
|
21
|
+
def parse(context: nil, **options)
|
22
|
+
source = render(context)
|
23
|
+
if YAML.respond_to?(:unsafe_load)
|
24
|
+
YAML.unsafe_load(source, **options) || {}
|
25
|
+
else
|
26
|
+
YAML.load(source, **options) || {}
|
27
|
+
end
|
28
|
+
rescue Psych::SyntaxError => error
|
29
|
+
raise "YAML syntax error occurred while parsing #{@content_path}. " \
|
30
|
+
"Please note that YAML must be consistently indented using spaces. Tabs are not allowed. " \
|
31
|
+
"Error: #{error.message}"
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
def read(content_path)
|
36
|
+
require "yaml"
|
37
|
+
require "erb"
|
38
|
+
|
39
|
+
File.read(content_path).tap do |content|
|
40
|
+
if content.include?("\u00A0")
|
41
|
+
warn "#{content_path} contains invisible non-breaking spaces, you may want to remove those"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def render(context)
|
47
|
+
erb = ERB.new(@content).tap { |e| e.filename = @content_path }
|
48
|
+
context ? erb.result(context) : erb.result
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -16,12 +16,12 @@ class Array
|
|
16
16
|
#
|
17
17
|
# ==== Options
|
18
18
|
#
|
19
|
-
# * <tt>:words_connector</tt> - The sign or word used to join the
|
20
|
-
# in arrays with
|
21
|
-
# * <tt>:two_words_connector</tt> - The sign or word used to join the elements
|
22
|
-
# in arrays with two elements (default: " and ").
|
19
|
+
# * <tt>:words_connector</tt> - The sign or word used to join all but the last
|
20
|
+
# element in arrays with three or more elements (default: ", ").
|
23
21
|
# * <tt>:last_word_connector</tt> - The sign or word used to join the last element
|
24
22
|
# in arrays with three or more elements (default: ", and ").
|
23
|
+
# * <tt>:two_words_connector</tt> - The sign or word used to join the elements
|
24
|
+
# in arrays with two elements (default: " and ").
|
25
25
|
# * <tt>:locale</tt> - If +i18n+ is available, you can set a locale and use
|
26
26
|
# the connector options defined on the 'support.array' namespace in the
|
27
27
|
# corresponding dictionary file.
|
@@ -66,7 +66,7 @@ class Array
|
|
66
66
|
two_words_connector: " and ",
|
67
67
|
last_word_connector: ", and "
|
68
68
|
}
|
69
|
-
if defined?(I18n)
|
69
|
+
if options[:locale] != false && defined?(I18n)
|
70
70
|
i18n_connectors = I18n.translate(:'support.array', locale: options[:locale], default: {})
|
71
71
|
default_connectors.merge!(i18n_connectors)
|
72
72
|
end
|
@@ -87,6 +87,8 @@ class Array
|
|
87
87
|
# Extends <tt>Array#to_s</tt> to convert a collection of elements into a
|
88
88
|
# comma separated id list if <tt>:db</tt> argument is given as the format.
|
89
89
|
#
|
90
|
+
# This method is aliased to <tt>to_fs</tt>.
|
91
|
+
#
|
90
92
|
# Blog.all.to_formatted_s(:db) # => "1,2,3"
|
91
93
|
# Blog.none.to_formatted_s(:db) # => "null"
|
92
94
|
# [1,2].to_formatted_s # => "[1, 2]"
|
@@ -102,8 +104,8 @@ class Array
|
|
102
104
|
to_default_s
|
103
105
|
end
|
104
106
|
end
|
107
|
+
alias_method :to_fs, :to_formatted_s
|
105
108
|
alias_method :to_default_s, :to_s
|
106
|
-
alias_method :to_s, :to_formatted_s
|
107
109
|
|
108
110
|
# Returns a string that represents the array in XML by invoking +to_xml+
|
109
111
|
# on each element. Active Record collections delegate their representation
|
@@ -187,7 +189,7 @@ class Array
|
|
187
189
|
options[:indent] ||= 2
|
188
190
|
options[:builder] ||= Builder::XmlMarkup.new(indent: options[:indent])
|
189
191
|
options[:root] ||= \
|
190
|
-
if first.class != Hash && all?
|
192
|
+
if first.class != Hash && all?(first.class)
|
191
193
|
underscored = ActiveSupport::Inflector.underscore(first.class.name)
|
192
194
|
ActiveSupport::Inflector.pluralize(underscored).tr("/", "_")
|
193
195
|
else
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Array
|
4
|
+
NOT_SET = Object.new # :nodoc:
|
5
|
+
def to_s(format = NOT_SET) # :nodoc:
|
6
|
+
case format
|
7
|
+
when :db
|
8
|
+
ActiveSupport::Deprecation.warn(
|
9
|
+
"Array#to_s(#{format.inspect}) is deprecated. Please use Array#to_formatted_s(#{format.inspect}) instead."
|
10
|
+
)
|
11
|
+
if empty?
|
12
|
+
"null"
|
13
|
+
else
|
14
|
+
collect(&:id).join(",")
|
15
|
+
end
|
16
|
+
when NOT_SET
|
17
|
+
to_default_s
|
18
|
+
else
|
19
|
+
ActiveSupport::Deprecation.warn(
|
20
|
+
"Array#to_s(#{format.inspect}) is deprecated. Please use Array#to_formatted_s(#{format.inspect}) instead."
|
21
|
+
)
|
22
|
+
to_default_s
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -19,7 +19,7 @@ class Array
|
|
19
19
|
# ["1", "2"]
|
20
20
|
# ["3", "4"]
|
21
21
|
# ["5"]
|
22
|
-
def in_groups_of(number, fill_with = nil)
|
22
|
+
def in_groups_of(number, fill_with = nil, &block)
|
23
23
|
if number.to_i <= 0
|
24
24
|
raise ArgumentError,
|
25
25
|
"Group size must be a positive integer, was #{number.inspect}"
|
@@ -36,7 +36,7 @@ class Array
|
|
36
36
|
end
|
37
37
|
|
38
38
|
if block_given?
|
39
|
-
collection.each_slice(number
|
39
|
+
collection.each_slice(number, &block)
|
40
40
|
else
|
41
41
|
collection.each_slice(number).to_a
|
42
42
|
end
|
@@ -59,7 +59,7 @@ class Array
|
|
59
59
|
# ["1", "2", "3"]
|
60
60
|
# ["4", "5"]
|
61
61
|
# ["6", "7"]
|
62
|
-
def in_groups(number, fill_with = nil)
|
62
|
+
def in_groups(number, fill_with = nil, &block)
|
63
63
|
# size.div number gives minor group size;
|
64
64
|
# size % number gives how many objects need extra accommodation;
|
65
65
|
# each group hold either division or division + 1 items.
|
@@ -79,7 +79,7 @@ class Array
|
|
79
79
|
end
|
80
80
|
|
81
81
|
if block_given?
|
82
|
-
groups.each
|
82
|
+
groups.each(&block)
|
83
83
|
else
|
84
84
|
groups
|
85
85
|
end
|
@@ -90,11 +90,11 @@ class Array
|
|
90
90
|
#
|
91
91
|
# [1, 2, 3, 4, 5].split(3) # => [[1, 2], [4, 5]]
|
92
92
|
# (1..10).to_a.split { |i| i % 3 == 0 } # => [[1, 2], [4, 5], [7, 8], [10]]
|
93
|
-
def split(value = nil)
|
93
|
+
def split(value = nil, &block)
|
94
94
|
arr = dup
|
95
95
|
result = []
|
96
96
|
if block_given?
|
97
|
-
while (idx = arr.index
|
97
|
+
while (idx = arr.index(&block))
|
98
98
|
result << arr.shift(idx)
|
99
99
|
arr.shift
|
100
100
|
end
|
@@ -3,6 +3,7 @@
|
|
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"]
|
6
7
|
require "active_support/core_ext/array/extract"
|
7
8
|
require "active_support/core_ext/array/extract_options"
|
8
9
|
require "active_support/core_ext/array/grouping"
|
@@ -1,8 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "active_support/core_ext/kernel/singleton_class"
|
4
3
|
require "active_support/core_ext/module/redefine_method"
|
5
|
-
require "active_support/core_ext/array/extract_options"
|
6
4
|
|
7
5
|
class Class
|
8
6
|
# Declare a class-level attribute whose value is inheritable by subclasses.
|
@@ -84,58 +82,50 @@ class Class
|
|
84
82
|
# To set a default value for the attribute, pass <tt>default:</tt>, like so:
|
85
83
|
#
|
86
84
|
# class_attribute :settings, default: {}
|
87
|
-
def class_attribute(
|
88
|
-
|
89
|
-
instance_accessor: true,
|
90
|
-
instance_reader: instance_accessor,
|
91
|
-
instance_writer: instance_accessor,
|
92
|
-
instance_predicate: true,
|
93
|
-
default: nil
|
94
|
-
)
|
95
|
-
attrs.each do |name|
|
96
|
-
singleton_class.silence_redefinition_of_method(name)
|
97
|
-
define_singleton_method(name) { default }
|
98
|
-
|
99
|
-
singleton_class.silence_redefinition_of_method("#{name}?")
|
100
|
-
define_singleton_method("#{name}?") { !!public_send(name) } if instance_predicate
|
85
|
+
def class_attribute(*attrs, instance_accessor: true,
|
86
|
+
instance_reader: instance_accessor, instance_writer: instance_accessor, instance_predicate: true, default: nil)
|
101
87
|
|
102
|
-
|
88
|
+
class_methods, methods = [], []
|
89
|
+
attrs.each do |name|
|
90
|
+
unless name.is_a?(Symbol) || name.is_a?(String)
|
91
|
+
raise TypeError, "#{name.inspect} is not a symbol nor a string"
|
92
|
+
end
|
103
93
|
|
104
|
-
|
105
|
-
|
106
|
-
|
94
|
+
class_methods << <<~RUBY # In case the method exists and is not public
|
95
|
+
silence_redefinition_of_method def #{name}
|
96
|
+
end
|
97
|
+
RUBY
|
107
98
|
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
if instance_variable_defined? ivar
|
112
|
-
instance_variable_get ivar
|
113
|
-
else
|
114
|
-
singleton_class.send name
|
115
|
-
end
|
116
|
-
end
|
117
|
-
end
|
99
|
+
methods << <<~RUBY if instance_reader
|
100
|
+
silence_redefinition_of_method def #{name}
|
101
|
+
defined?(@#{name}) ? @#{name} : self.class.#{name}
|
118
102
|
end
|
119
|
-
|
120
|
-
end
|
103
|
+
RUBY
|
121
104
|
|
122
|
-
|
123
|
-
|
124
|
-
if
|
125
|
-
|
126
|
-
|
127
|
-
self.class.public_send name
|
128
|
-
end
|
105
|
+
class_methods << <<~RUBY
|
106
|
+
silence_redefinition_of_method def #{name}=(value)
|
107
|
+
redefine_method(:#{name}) { value } if singleton_class?
|
108
|
+
redefine_singleton_method(:#{name}) { value }
|
109
|
+
value
|
129
110
|
end
|
111
|
+
RUBY
|
130
112
|
|
131
|
-
|
132
|
-
|
113
|
+
methods << <<~RUBY if instance_writer
|
114
|
+
silence_redefinition_of_method(:#{name}=)
|
115
|
+
attr_writer :#{name}
|
116
|
+
RUBY
|
133
117
|
|
134
|
-
if
|
135
|
-
|
136
|
-
|
118
|
+
if instance_predicate
|
119
|
+
class_methods << "silence_redefinition_of_method def #{name}?; !!self.#{name}; end"
|
120
|
+
if instance_reader
|
121
|
+
methods << "silence_redefinition_of_method def #{name}?; !!self.#{name}; end"
|
137
122
|
end
|
138
123
|
end
|
139
124
|
end
|
125
|
+
|
126
|
+
location = caller_locations(1, 1).first
|
127
|
+
class_eval(["class << self", *class_methods, "end", *methods].join(";").tr("\n", ";"), location.path, location.lineno)
|
128
|
+
|
129
|
+
attrs.each { |name| public_send("#{name}=", default) }
|
140
130
|
end
|
141
131
|
end
|
@@ -1,41 +1,26 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
begin
|
5
|
-
# Test if this Ruby supports each_object against singleton_class
|
6
|
-
ObjectSpace.each_object(Numeric.singleton_class) { }
|
3
|
+
require "active_support/ruby_features"
|
7
4
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
descendants.unshift k unless k == self
|
26
|
-
end
|
27
|
-
descendants
|
28
|
-
end
|
29
|
-
rescue StandardError # JRuby 9.0.4.0 and earlier
|
30
|
-
def descendants
|
31
|
-
descendants = []
|
32
|
-
ObjectSpace.each_object(Class) do |k|
|
33
|
-
descendants.unshift k if k < self
|
34
|
-
end
|
35
|
-
descendants.uniq!
|
36
|
-
descendants
|
5
|
+
class Class
|
6
|
+
# Returns an array with all classes that are < than its receiver.
|
7
|
+
#
|
8
|
+
# class C; end
|
9
|
+
# C.descendants # => []
|
10
|
+
#
|
11
|
+
# class B < C; end
|
12
|
+
# C.descendants # => [B]
|
13
|
+
#
|
14
|
+
# class A < B; end
|
15
|
+
# C.descendants # => [B, A]
|
16
|
+
#
|
17
|
+
# class D < C; end
|
18
|
+
# C.descendants # => [B, A, D]
|
19
|
+
def descendants
|
20
|
+
ObjectSpace.each_object(singleton_class).reject do |k|
|
21
|
+
k.singleton_class? || k == self
|
37
22
|
end
|
38
|
-
end
|
23
|
+
end unless ActiveSupport::RubyFeatures::CLASS_SUBCLASSES
|
39
24
|
|
40
25
|
# Returns an array with the direct children of +self+.
|
41
26
|
#
|
@@ -45,10 +30,6 @@ class Class
|
|
45
30
|
#
|
46
31
|
# Foo.subclasses # => [Bar]
|
47
32
|
def subclasses
|
48
|
-
|
49
|
-
|
50
|
-
subclasses << k unless chain.any? { |c| c > k }
|
51
|
-
end
|
52
|
-
subclasses
|
53
|
-
end
|
33
|
+
descendants.select { |descendant| descendant.superclass == self }
|
34
|
+
end unless ActiveSupport::RubyFeatures::CLASS_SUBCLASSES
|
54
35
|
end
|
@@ -17,7 +17,7 @@ class Date
|
|
17
17
|
# If <tt>Date.beginning_of_week</tt> has not been set for the current request, returns the week start specified in <tt>config.beginning_of_week</tt>.
|
18
18
|
# If no config.beginning_of_week was specified, returns :monday.
|
19
19
|
def beginning_of_week
|
20
|
-
|
20
|
+
::ActiveSupport::IsolatedExecutionState[:beginning_of_week] || beginning_of_week_default || :monday
|
21
21
|
end
|
22
22
|
|
23
23
|
# Sets <tt>Date.beginning_of_week</tt> to a week start (e.g. :monday) for current request/thread.
|
@@ -25,7 +25,7 @@ class Date
|
|
25
25
|
# This method accepts any of the following day symbols:
|
26
26
|
# :monday, :tuesday, :wednesday, :thursday, :friday, :saturday, :sunday
|
27
27
|
def beginning_of_week=(week_start)
|
28
|
-
|
28
|
+
::ActiveSupport::IsolatedExecutionState[:beginning_of_week] = find_beginning_of_week!(week_start)
|
29
29
|
end
|
30
30
|
|
31
31
|
# Returns week start day symbol (e.g. :monday), or raises an +ArgumentError+ for invalid day symbol.
|
@@ -87,7 +87,7 @@ class Date
|
|
87
87
|
end
|
88
88
|
alias :at_end_of_day :end_of_day
|
89
89
|
|
90
|
-
def plus_with_duration(other)
|
90
|
+
def plus_with_duration(other) # :nodoc:
|
91
91
|
if ActiveSupport::Duration === other
|
92
92
|
other.since(self)
|
93
93
|
else
|
@@ -97,7 +97,7 @@ class Date
|
|
97
97
|
alias_method :plus_without_duration, :+
|
98
98
|
alias_method :+, :plus_with_duration
|
99
99
|
|
100
|
-
def minus_with_duration(other)
|
100
|
+
def minus_with_duration(other) # :nodoc:
|
101
101
|
if ActiveSupport::Duration === other
|
102
102
|
plus_with_duration(-other)
|
103
103
|
else
|
@@ -10,6 +10,7 @@ class Date
|
|
10
10
|
short: "%d %b",
|
11
11
|
long: "%B %d, %Y",
|
12
12
|
db: "%Y-%m-%d",
|
13
|
+
inspect: "%Y-%m-%d",
|
13
14
|
number: "%Y%m%d",
|
14
15
|
long_ordinal: lambda { |date|
|
15
16
|
day_format = ActiveSupport::Inflector.ordinalize(date.day)
|
@@ -21,12 +22,12 @@ class Date
|
|
21
22
|
|
22
23
|
# Convert to a formatted string. See DATE_FORMATS for predefined formats.
|
23
24
|
#
|
24
|
-
# This method is aliased to <tt>
|
25
|
+
# This method is aliased to <tt>to_fs</tt>.
|
25
26
|
#
|
26
27
|
# date = Date.new(2007, 11, 10) # => Sat, 10 Nov 2007
|
27
28
|
#
|
28
29
|
# date.to_formatted_s(:db) # => "2007-11-10"
|
29
|
-
# date.
|
30
|
+
# date.to_fs(:db) # => "2007-11-10"
|
30
31
|
#
|
31
32
|
# date.to_formatted_s(:short) # => "10 Nov"
|
32
33
|
# date.to_formatted_s(:number) # => "20071110"
|
@@ -54,8 +55,8 @@ class Date
|
|
54
55
|
to_default_s
|
55
56
|
end
|
56
57
|
end
|
58
|
+
alias_method :to_fs, :to_formatted_s
|
57
59
|
alias_method :to_default_s, :to_s
|
58
|
-
alias_method :to_s, :to_formatted_s
|
59
60
|
|
60
61
|
# Overrides the default inspect method with a human readable one, e.g., "Mon, 21 Feb 2005"
|
61
62
|
def readable_inspect
|
@@ -80,7 +81,7 @@ class Date
|
|
80
81
|
# If the *application's* timezone is needed, then use +in_time_zone+ instead.
|
81
82
|
def to_time(form = :local)
|
82
83
|
raise ArgumentError, "Expected :local or :utc, got #{form.inspect}." unless [:local, :utc].include?(form)
|
83
|
-
::Time.
|
84
|
+
::Time.public_send(form, year, month, day)
|
84
85
|
end
|
85
86
|
|
86
87
|
silence_redefinition_of_method :xmlschema
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "date"
|
4
|
+
|
5
|
+
class Date
|
6
|
+
NOT_SET = Object.new # :nodoc:
|
7
|
+
def to_s(format = NOT_SET) # :nodoc:
|
8
|
+
if formatter = DATE_FORMATS[format]
|
9
|
+
ActiveSupport::Deprecation.warn(
|
10
|
+
"Date#to_s(#{format.inspect}) is deprecated. Please use Date#to_formatted_s(#{format.inspect}) instead."
|
11
|
+
)
|
12
|
+
if formatter.respond_to?(:call)
|
13
|
+
formatter.call(self).to_s
|
14
|
+
else
|
15
|
+
strftime(formatter)
|
16
|
+
end
|
17
|
+
elsif format == NOT_SET
|
18
|
+
to_default_s
|
19
|
+
else
|
20
|
+
ActiveSupport::Deprecation.warn(
|
21
|
+
"Date#to_s(#{format.inspect}) is deprecated. Please use Date#to_formatted_s(#{format.inspect}) instead."
|
22
|
+
)
|
23
|
+
to_default_s
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -4,4 +4,5 @@ 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"]
|
7
8
|
require "active_support/core_ext/date/zones"
|
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "active_support/core_ext/object/try"
|
4
|
+
require "active_support/core_ext/date_time/conversions"
|
4
5
|
|
5
6
|
module DateAndTime
|
6
7
|
module Calculations
|
@@ -30,6 +31,18 @@ module DateAndTime
|
|
30
31
|
to_date == ::Date.current
|
31
32
|
end
|
32
33
|
|
34
|
+
# Returns true if the date/time is tomorrow.
|
35
|
+
def tomorrow?
|
36
|
+
to_date == ::Date.current.tomorrow
|
37
|
+
end
|
38
|
+
alias :next_day? :tomorrow?
|
39
|
+
|
40
|
+
# Returns true if the date/time is yesterday.
|
41
|
+
def yesterday?
|
42
|
+
to_date == ::Date.current.yesterday
|
43
|
+
end
|
44
|
+
alias :prev_day? :yesterday?
|
45
|
+
|
33
46
|
# Returns true if the date/time is in the past.
|
34
47
|
def past?
|
35
48
|
self < self.class.current
|
@@ -12,5 +12,20 @@ module DateAndTime
|
|
12
12
|
# this behavior, but new apps will have an initializer that sets
|
13
13
|
# this to true, because the new behavior is preferred.
|
14
14
|
mattr_accessor :preserve_timezone, instance_writer: false, default: false
|
15
|
+
|
16
|
+
# Change the output of <tt>ActiveSupport::TimeZone.utc_to_local</tt>.
|
17
|
+
#
|
18
|
+
# When `true`, it returns local times with a UTC offset, with `false` local
|
19
|
+
# times are returned as UTC.
|
20
|
+
#
|
21
|
+
# # Given this zone:
|
22
|
+
# zone = ActiveSupport::TimeZone["Eastern Time (US & Canada)"]
|
23
|
+
#
|
24
|
+
# # With `utc_to_local_returns_utc_offset_times = false`, local time is converted to UTC:
|
25
|
+
# zone.utc_to_local(Time.utc(2000, 1)) # => 1999-12-31 19:00:00 UTC
|
26
|
+
#
|
27
|
+
# # With `utc_to_local_returns_utc_offset_times = true`, local time is returned with UTC offset:
|
28
|
+
# zone.utc_to_local(Time.utc(2000, 1)) # => 1999-12-31 19:00:00 -0500
|
29
|
+
mattr_accessor :utc_to_local_returns_utc_offset_times, instance_writer: false, default: false
|
15
30
|
end
|
16
31
|
end
|