activesupport 5.1.6 → 5.2.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 +5 -5
- data/CHANGELOG.md +325 -576
- data/MIT-LICENSE +1 -1
- data/README.rdoc +3 -3
- data/lib/active_support/all.rb +2 -0
- data/lib/active_support/array_inquirer.rb +2 -0
- data/lib/active_support/backtrace_cleaner.rb +2 -0
- data/lib/active_support/benchmarkable.rb +2 -0
- data/lib/active_support/builder.rb +2 -0
- data/lib/active_support/cache/file_store.rb +5 -4
- data/lib/active_support/cache/mem_cache_store.rb +37 -27
- data/lib/active_support/cache/memory_store.rb +2 -0
- data/lib/active_support/cache/null_store.rb +2 -0
- data/lib/active_support/cache/redis_cache_store.rb +454 -0
- data/lib/active_support/cache/strategy/local_cache.rb +33 -2
- data/lib/active_support/cache/strategy/local_cache_middleware.rb +2 -0
- data/lib/active_support/cache.rb +181 -64
- data/lib/active_support/callbacks.rb +28 -39
- data/lib/active_support/concern.rb +3 -1
- data/lib/active_support/concurrency/share_lock.rb +2 -0
- data/lib/active_support/configurable.rb +2 -0
- data/lib/active_support/core_ext/array/access.rb +4 -2
- data/lib/active_support/core_ext/array/conversions.rb +2 -0
- data/lib/active_support/core_ext/array/extract_options.rb +2 -0
- data/lib/active_support/core_ext/array/grouping.rb +2 -0
- data/lib/active_support/core_ext/array/inquiry.rb +2 -0
- data/lib/active_support/core_ext/array/prepend_and_append.rb +4 -2
- data/lib/active_support/core_ext/array/wrap.rb +2 -0
- data/lib/active_support/core_ext/array.rb +2 -0
- data/lib/active_support/core_ext/benchmark.rb +2 -0
- data/lib/active_support/core_ext/big_decimal/conversions.rb +2 -0
- data/lib/active_support/core_ext/big_decimal.rb +2 -0
- data/lib/active_support/core_ext/class/attribute.rb +34 -16
- data/lib/active_support/core_ext/class/attribute_accessors.rb +2 -0
- data/lib/active_support/core_ext/class/subclasses.rb +1 -2
- data/lib/active_support/core_ext/class.rb +2 -0
- data/lib/active_support/core_ext/date/acts_like.rb +2 -0
- data/lib/active_support/core_ext/date/blank.rb +2 -0
- data/lib/active_support/core_ext/date/calculations.rb +2 -0
- data/lib/active_support/core_ext/date/conversions.rb +10 -9
- data/lib/active_support/core_ext/date/zones.rb +2 -0
- data/lib/active_support/core_ext/date.rb +2 -0
- data/lib/active_support/core_ext/date_and_time/calculations.rb +50 -16
- data/lib/active_support/core_ext/date_and_time/compatibility.rb +3 -1
- data/lib/active_support/core_ext/date_and_time/zones.rb +2 -0
- data/lib/active_support/core_ext/date_time/acts_like.rb +2 -0
- data/lib/active_support/core_ext/date_time/blank.rb +2 -0
- data/lib/active_support/core_ext/date_time/calculations.rb +2 -0
- data/lib/active_support/core_ext/date_time/compatibility.rb +7 -5
- data/lib/active_support/core_ext/date_time/conversions.rb +2 -0
- data/lib/active_support/core_ext/date_time.rb +2 -0
- data/lib/active_support/core_ext/digest/uuid.rb +3 -1
- data/lib/active_support/core_ext/enumerable.rb +3 -1
- data/lib/active_support/core_ext/file/atomic.rb +2 -0
- data/lib/active_support/core_ext/file.rb +2 -0
- data/lib/active_support/core_ext/hash/compact.rb +2 -0
- data/lib/active_support/core_ext/hash/conversions.rb +4 -2
- data/lib/active_support/core_ext/hash/deep_merge.rb +8 -12
- data/lib/active_support/core_ext/hash/except.rb +2 -0
- data/lib/active_support/core_ext/hash/indifferent_access.rb +2 -0
- data/lib/active_support/core_ext/hash/keys.rb +2 -0
- data/lib/active_support/core_ext/hash/reverse_merge.rb +5 -2
- data/lib/active_support/core_ext/hash/slice.rb +4 -4
- data/lib/active_support/core_ext/hash/transform_values.rb +2 -0
- data/lib/active_support/core_ext/hash.rb +2 -0
- data/lib/active_support/core_ext/integer/inflections.rb +2 -0
- data/lib/active_support/core_ext/integer/multiple.rb +2 -0
- data/lib/active_support/core_ext/integer/time.rb +7 -14
- data/lib/active_support/core_ext/integer.rb +2 -0
- data/lib/active_support/core_ext/kernel/agnostics.rb +2 -0
- data/lib/active_support/core_ext/kernel/concern.rb +2 -0
- data/lib/active_support/core_ext/kernel/reporting.rb +2 -0
- data/lib/active_support/core_ext/kernel/singleton_class.rb +2 -0
- data/lib/active_support/core_ext/kernel.rb +2 -0
- data/lib/active_support/core_ext/load_error.rb +2 -7
- data/lib/active_support/core_ext/marshal.rb +2 -0
- data/lib/active_support/core_ext/module/aliasing.rb +2 -0
- data/lib/active_support/core_ext/module/anonymous.rb +2 -0
- data/lib/active_support/core_ext/module/attr_internal.rb +2 -0
- data/lib/active_support/core_ext/module/attribute_accessors.rb +21 -24
- data/lib/active_support/core_ext/module/attribute_accessors_per_thread.rb +2 -0
- data/lib/active_support/core_ext/module/concerning.rb +7 -8
- data/lib/active_support/core_ext/module/delegation.rb +31 -29
- data/lib/active_support/core_ext/module/deprecation.rb +2 -0
- data/lib/active_support/core_ext/module/introspection.rb +2 -0
- data/lib/active_support/core_ext/module/reachable.rb +3 -0
- data/lib/active_support/core_ext/module/redefine_method.rb +49 -0
- data/lib/active_support/core_ext/module/remove_method.rb +5 -23
- data/lib/active_support/core_ext/module.rb +3 -0
- data/lib/active_support/core_ext/name_error.rb +7 -0
- data/lib/active_support/core_ext/numeric/bytes.rb +2 -0
- data/lib/active_support/core_ext/numeric/conversions.rb +9 -7
- data/lib/active_support/core_ext/numeric/inquiry.rb +2 -0
- data/lib/active_support/core_ext/numeric/time.rb +7 -15
- data/lib/active_support/core_ext/numeric.rb +2 -0
- data/lib/active_support/core_ext/object/acts_like.rb +12 -1
- data/lib/active_support/core_ext/object/blank.rb +12 -1
- data/lib/active_support/core_ext/object/conversions.rb +2 -0
- data/lib/active_support/core_ext/object/deep_dup.rb +2 -0
- data/lib/active_support/core_ext/object/duplicable.rb +10 -8
- data/lib/active_support/core_ext/object/inclusion.rb +2 -0
- data/lib/active_support/core_ext/object/instance_variables.rb +2 -0
- data/lib/active_support/core_ext/object/json.rb +8 -0
- data/lib/active_support/core_ext/object/to_param.rb +2 -0
- data/lib/active_support/core_ext/object/to_query.rb +2 -0
- data/lib/active_support/core_ext/object/try.rb +2 -0
- data/lib/active_support/core_ext/object/with_options.rb +3 -1
- data/lib/active_support/core_ext/object.rb +2 -0
- data/lib/active_support/core_ext/range/conversions.rb +9 -1
- data/lib/active_support/core_ext/range/each.rb +5 -1
- data/lib/active_support/core_ext/range/include_range.rb +2 -0
- data/lib/active_support/core_ext/range/include_time_with_zone.rb +23 -0
- data/lib/active_support/core_ext/range/overlaps.rb +2 -0
- data/lib/active_support/core_ext/range.rb +3 -0
- data/lib/active_support/core_ext/regexp.rb +2 -0
- data/lib/active_support/core_ext/securerandom.rb +2 -0
- data/lib/active_support/core_ext/string/access.rb +2 -0
- data/lib/active_support/core_ext/string/behavior.rb +2 -0
- data/lib/active_support/core_ext/string/conversions.rb +2 -0
- data/lib/active_support/core_ext/string/exclude.rb +2 -0
- data/lib/active_support/core_ext/string/filters.rb +2 -0
- data/lib/active_support/core_ext/string/indent.rb +2 -0
- data/lib/active_support/core_ext/string/inflections.rb +26 -12
- data/lib/active_support/core_ext/string/inquiry.rb +2 -0
- data/lib/active_support/core_ext/string/multibyte.rb +4 -0
- data/lib/active_support/core_ext/string/output_safety.rb +6 -7
- data/lib/active_support/core_ext/string/starts_ends_with.rb +2 -0
- data/lib/active_support/core_ext/string/strip.rb +2 -0
- data/lib/active_support/core_ext/string/zones.rb +2 -0
- data/lib/active_support/core_ext/string.rb +2 -0
- data/lib/active_support/core_ext/time/acts_like.rb +2 -0
- data/lib/active_support/core_ext/time/calculations.rb +23 -15
- data/lib/active_support/core_ext/time/compatibility.rb +4 -2
- data/lib/active_support/core_ext/time/conversions.rb +2 -0
- data/lib/active_support/core_ext/time/zones.rb +6 -4
- data/lib/active_support/core_ext/time.rb +2 -0
- data/lib/active_support/core_ext/uri.rb +4 -1
- data/lib/active_support/core_ext.rb +3 -1
- data/lib/active_support/current_attributes.rb +195 -0
- data/lib/active_support/dependencies/autoload.rb +2 -0
- data/lib/active_support/dependencies/interlock.rb +2 -0
- data/lib/active_support/dependencies.rb +16 -25
- data/lib/active_support/deprecation/behaviors.rb +24 -9
- data/lib/active_support/deprecation/constant_accessor.rb +4 -2
- data/lib/active_support/deprecation/instance_delegator.rb +2 -0
- data/lib/active_support/deprecation/method_wrappers.rb +8 -8
- data/lib/active_support/deprecation/proxy_wrappers.rb +5 -2
- data/lib/active_support/deprecation/reporting.rb +5 -3
- data/lib/active_support/deprecation.rb +4 -2
- data/lib/active_support/descendants_tracker.rb +2 -0
- data/lib/active_support/digest.rb +20 -0
- data/lib/active_support/duration/iso8601_parser.rb +4 -2
- data/lib/active_support/duration/iso8601_serializer.rb +4 -2
- data/lib/active_support/duration.rb +11 -7
- data/lib/active_support/encrypted_configuration.rb +49 -0
- data/lib/active_support/encrypted_file.rb +99 -0
- data/lib/active_support/evented_file_update_checker.rb +2 -0
- data/lib/active_support/execution_wrapper.rb +2 -0
- data/lib/active_support/executor.rb +2 -0
- data/lib/active_support/file_update_checker.rb +2 -0
- data/lib/active_support/gem_version.rb +4 -2
- data/lib/active_support/gzip.rb +2 -0
- data/lib/active_support/hash_with_indifferent_access.rb +41 -1
- data/lib/active_support/i18n.rb +3 -1
- data/lib/active_support/i18n_railtie.rb +4 -6
- data/lib/active_support/inflections.rb +2 -0
- data/lib/active_support/inflector/inflections.rb +20 -4
- data/lib/active_support/inflector/methods.rb +41 -24
- data/lib/active_support/inflector/transliterate.rb +17 -8
- data/lib/active_support/inflector.rb +2 -0
- data/lib/active_support/json/decoding.rb +2 -0
- data/lib/active_support/json/encoding.rb +2 -0
- data/lib/active_support/json.rb +2 -0
- data/lib/active_support/key_generator.rb +3 -1
- data/lib/active_support/lazy_load_hooks.rb +2 -0
- data/lib/active_support/log_subscriber/test_helper.rb +2 -0
- data/lib/active_support/log_subscriber.rb +3 -2
- data/lib/active_support/logger.rb +2 -0
- data/lib/active_support/logger_silence.rb +3 -2
- data/lib/active_support/logger_thread_safe_level.rb +2 -0
- data/lib/active_support/message_encryptor.rb +95 -22
- data/lib/active_support/message_verifier.rb +78 -7
- data/lib/active_support/messages/metadata.rb +71 -0
- data/lib/active_support/messages/rotation_configuration.rb +22 -0
- data/lib/active_support/messages/rotator.rb +56 -0
- data/lib/active_support/multibyte/chars.rb +2 -0
- data/lib/active_support/multibyte/unicode.rb +4 -2
- data/lib/active_support/multibyte.rb +2 -0
- data/lib/active_support/notifications/fanout.rb +2 -0
- data/lib/active_support/notifications/instrumenter.rb +2 -0
- data/lib/active_support/notifications.rb +2 -0
- data/lib/active_support/number_helper/number_converter.rb +2 -0
- data/lib/active_support/number_helper/number_to_currency_converter.rb +2 -0
- data/lib/active_support/number_helper/number_to_delimited_converter.rb +2 -0
- data/lib/active_support/number_helper/number_to_human_converter.rb +2 -0
- data/lib/active_support/number_helper/number_to_human_size_converter.rb +2 -0
- data/lib/active_support/number_helper/number_to_percentage_converter.rb +2 -0
- data/lib/active_support/number_helper/number_to_phone_converter.rb +3 -1
- data/lib/active_support/number_helper/number_to_rounded_converter.rb +2 -20
- data/lib/active_support/number_helper/rounding_helper.rb +6 -4
- data/lib/active_support/number_helper.rb +2 -0
- data/lib/active_support/option_merger.rb +2 -0
- data/lib/active_support/ordered_hash.rb +2 -0
- data/lib/active_support/ordered_options.rb +4 -2
- data/lib/active_support/per_thread_registry.rb +2 -0
- data/lib/active_support/proxy_object.rb +2 -0
- data/lib/active_support/rails.rb +2 -0
- data/lib/active_support/railtie.rb +37 -8
- data/lib/active_support/reloader.rb +7 -5
- data/lib/active_support/rescuable.rb +3 -2
- data/lib/active_support/security_utils.rb +15 -11
- data/lib/active_support/string_inquirer.rb +2 -0
- data/lib/active_support/subscriber.rb +2 -0
- data/lib/active_support/tagged_logging.rb +2 -0
- data/lib/active_support/test_case.rb +2 -1
- data/lib/active_support/testing/assertions.rb +31 -14
- data/lib/active_support/testing/autorun.rb +2 -0
- data/lib/active_support/testing/constant_lookup.rb +2 -0
- data/lib/active_support/testing/declarative.rb +2 -0
- data/lib/active_support/testing/deprecation.rb +2 -0
- data/lib/active_support/testing/file_fixtures.rb +2 -0
- data/lib/active_support/testing/isolation.rb +3 -1
- data/lib/active_support/testing/method_call_assertions.rb +2 -0
- data/lib/active_support/testing/setup_and_teardown.rb +10 -1
- data/lib/active_support/testing/stream.rb +2 -0
- data/lib/active_support/testing/tagged_logging.rb +2 -0
- data/lib/active_support/testing/time_helpers.rb +33 -3
- data/lib/active_support/time.rb +2 -0
- data/lib/active_support/time_with_zone.rb +38 -0
- data/lib/active_support/values/time_zone.rb +19 -8
- data/lib/active_support/version.rb +2 -0
- data/lib/active_support/xml_mini/jdom.rb +4 -2
- data/lib/active_support/xml_mini/libxml.rb +3 -1
- data/lib/active_support/xml_mini/libxmlsax.rb +4 -2
- data/lib/active_support/xml_mini/nokogiri.rb +3 -1
- data/lib/active_support/xml_mini/nokogirisax.rb +3 -1
- data/lib/active_support/xml_mini/rexml.rb +3 -1
- data/lib/active_support/xml_mini.rb +3 -1
- data/lib/active_support.rb +5 -13
- metadata +15 -5
@@ -1,11 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "active_support/core_ext/kernel/singleton_class"
|
2
|
-
require "active_support/core_ext/module/
|
4
|
+
require "active_support/core_ext/module/redefine_method"
|
3
5
|
require "active_support/core_ext/array/extract_options"
|
4
6
|
|
5
7
|
class Class
|
6
8
|
# Declare a class-level attribute whose value is inheritable by subclasses.
|
7
9
|
# Subclasses can change their own value and it will not impact parent class.
|
8
10
|
#
|
11
|
+
# ==== Options
|
12
|
+
#
|
13
|
+
# * <tt>:instance_reader</tt> - Sets the instance reader method (defaults to true).
|
14
|
+
# * <tt>:instance_writer</tt> - Sets the instance writer method (defaults to true).
|
15
|
+
# * <tt>:instance_accessor</tt> - Sets both instance methods (defaults to true).
|
16
|
+
# * <tt>:instance_predicate</tt> - Sets a predicate method (defaults to true).
|
17
|
+
# * <tt>:default</tt> - Sets a default value for the attribute (defaults to nil).
|
18
|
+
#
|
19
|
+
# ==== Examples
|
20
|
+
#
|
9
21
|
# class Base
|
10
22
|
# class_attribute :setting
|
11
23
|
# end
|
@@ -68,32 +80,35 @@ class Class
|
|
68
80
|
# object.setting = false # => NoMethodError
|
69
81
|
#
|
70
82
|
# To opt out of both instance methods, pass <tt>instance_accessor: false</tt>.
|
83
|
+
#
|
84
|
+
# To set a default value for the attribute, pass <tt>default:</tt>, like so:
|
85
|
+
#
|
86
|
+
# class_attribute :settings, default: {}
|
71
87
|
def class_attribute(*attrs)
|
72
88
|
options = attrs.extract_options!
|
73
|
-
instance_reader
|
74
|
-
instance_writer
|
89
|
+
instance_reader = options.fetch(:instance_accessor, true) && options.fetch(:instance_reader, true)
|
90
|
+
instance_writer = options.fetch(:instance_accessor, true) && options.fetch(:instance_writer, true)
|
75
91
|
instance_predicate = options.fetch(:instance_predicate, true)
|
92
|
+
default_value = options.fetch(:default, nil)
|
76
93
|
|
77
94
|
attrs.each do |name|
|
78
|
-
|
95
|
+
singleton_class.silence_redefinition_of_method(name)
|
79
96
|
define_singleton_method(name) { nil }
|
80
97
|
|
81
|
-
|
98
|
+
singleton_class.silence_redefinition_of_method("#{name}?")
|
82
99
|
define_singleton_method("#{name}?") { !!public_send(name) } if instance_predicate
|
83
100
|
|
84
101
|
ivar = "@#{name}"
|
85
102
|
|
86
|
-
|
103
|
+
singleton_class.silence_redefinition_of_method("#{name}=")
|
87
104
|
define_singleton_method("#{name}=") do |val|
|
88
105
|
singleton_class.class_eval do
|
89
|
-
|
90
|
-
define_method(name) { val }
|
106
|
+
redefine_method(name) { val }
|
91
107
|
end
|
92
108
|
|
93
109
|
if singleton_class?
|
94
110
|
class_eval do
|
95
|
-
|
96
|
-
define_method(name) do
|
111
|
+
redefine_method(name) do
|
97
112
|
if instance_variable_defined? ivar
|
98
113
|
instance_variable_get ivar
|
99
114
|
else
|
@@ -106,8 +121,7 @@ class Class
|
|
106
121
|
end
|
107
122
|
|
108
123
|
if instance_reader
|
109
|
-
|
110
|
-
define_method(name) do
|
124
|
+
redefine_method(name) do
|
111
125
|
if instance_variable_defined?(ivar)
|
112
126
|
instance_variable_get ivar
|
113
127
|
else
|
@@ -115,13 +129,17 @@ class Class
|
|
115
129
|
end
|
116
130
|
end
|
117
131
|
|
118
|
-
|
119
|
-
define_method("#{name}?") { !!public_send(name) } if instance_predicate
|
132
|
+
redefine_method("#{name}?") { !!public_send(name) } if instance_predicate
|
120
133
|
end
|
121
134
|
|
122
135
|
if instance_writer
|
123
|
-
|
124
|
-
|
136
|
+
redefine_method("#{name}=") do |val|
|
137
|
+
instance_variable_set ivar, val
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
unless default_value.nil?
|
142
|
+
self.send("#{name}=", default_value)
|
125
143
|
end
|
126
144
|
end
|
127
145
|
end
|
@@ -1,7 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "date"
|
2
4
|
require "active_support/inflector/methods"
|
3
5
|
require "active_support/core_ext/date/zones"
|
4
|
-
require "active_support/core_ext/module/
|
6
|
+
require "active_support/core_ext/module/redefine_method"
|
5
7
|
|
6
8
|
class Date
|
7
9
|
DATE_FORMATS = {
|
@@ -17,14 +19,6 @@ class Date
|
|
17
19
|
iso8601: lambda { |date| date.iso8601 }
|
18
20
|
}
|
19
21
|
|
20
|
-
# Ruby 1.9 has Date#to_time which converts to localtime only.
|
21
|
-
remove_method :to_time
|
22
|
-
|
23
|
-
# Ruby 1.9 has Date#xmlschema which converts to a string without the time
|
24
|
-
# component. This removal may generate an issue on FreeBSD, that's why we
|
25
|
-
# need to use remove_possible_method here
|
26
|
-
remove_possible_method :xmlschema
|
27
|
-
|
28
22
|
# Convert to a formatted string. See DATE_FORMATS for predefined formats.
|
29
23
|
#
|
30
24
|
# This method is aliased to <tt>to_s</tt>.
|
@@ -70,6 +64,8 @@ class Date
|
|
70
64
|
alias_method :default_inspect, :inspect
|
71
65
|
alias_method :inspect, :readable_inspect
|
72
66
|
|
67
|
+
silence_redefinition_of_method :to_time
|
68
|
+
|
73
69
|
# Converts a Date instance to a Time, where the time is set to the beginning of the day.
|
74
70
|
# The timezone can be either :local or :utc (default :local).
|
75
71
|
#
|
@@ -79,11 +75,16 @@ class Date
|
|
79
75
|
# date.to_time(:local) # => 2007-11-10 00:00:00 0800
|
80
76
|
#
|
81
77
|
# date.to_time(:utc) # => 2007-11-10 00:00:00 UTC
|
78
|
+
#
|
79
|
+
# NOTE: The :local timezone is Ruby's *process* timezone, i.e. ENV['TZ'].
|
80
|
+
# If the *application's* timezone is needed, then use +in_time_zone+ instead.
|
82
81
|
def to_time(form = :local)
|
83
82
|
raise ArgumentError, "Expected :local or :utc, got #{form.inspect}." unless [:local, :utc].include?(form)
|
84
83
|
::Time.send(form, year, month, day)
|
85
84
|
end
|
86
85
|
|
86
|
+
silence_redefinition_of_method :xmlschema
|
87
|
+
|
87
88
|
# Returns a string which represents the time in used time zone as DateTime
|
88
89
|
# defined by XML Schema:
|
89
90
|
#
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "active_support/core_ext/object/try"
|
2
4
|
|
3
5
|
module DateAndTime
|
@@ -18,9 +20,9 @@ module DateAndTime
|
|
18
20
|
advance(days: -1)
|
19
21
|
end
|
20
22
|
|
21
|
-
# Returns a new date/time
|
22
|
-
def prev_day
|
23
|
-
advance(days: -
|
23
|
+
# Returns a new date/time the specified number of days ago.
|
24
|
+
def prev_day(days = 1)
|
25
|
+
advance(days: -days)
|
24
26
|
end
|
25
27
|
|
26
28
|
# Returns a new date/time representing tomorrow.
|
@@ -28,9 +30,9 @@ module DateAndTime
|
|
28
30
|
advance(days: 1)
|
29
31
|
end
|
30
32
|
|
31
|
-
# Returns a new date/time
|
32
|
-
def next_day
|
33
|
-
advance(days:
|
33
|
+
# Returns a new date/time the specified number of days in the future.
|
34
|
+
def next_day(days = 1)
|
35
|
+
advance(days: days)
|
34
36
|
end
|
35
37
|
|
36
38
|
# Returns true if the date/time is today.
|
@@ -186,9 +188,9 @@ module DateAndTime
|
|
186
188
|
end
|
187
189
|
end
|
188
190
|
|
189
|
-
#
|
190
|
-
def next_month
|
191
|
-
|
191
|
+
# Returns a new date/time the specified number of months in the future.
|
192
|
+
def next_month(months = 1)
|
193
|
+
advance(months: months)
|
192
194
|
end
|
193
195
|
|
194
196
|
# Short-hand for months_since(3)
|
@@ -196,9 +198,9 @@ module DateAndTime
|
|
196
198
|
months_since(3)
|
197
199
|
end
|
198
200
|
|
199
|
-
#
|
200
|
-
def next_year
|
201
|
-
|
201
|
+
# Returns a new date/time the specified number of years in the future.
|
202
|
+
def next_year(years = 1)
|
203
|
+
advance(years: years)
|
202
204
|
end
|
203
205
|
|
204
206
|
# Returns a new date/time representing the given day in the previous week.
|
@@ -221,11 +223,15 @@ module DateAndTime
|
|
221
223
|
end
|
222
224
|
alias_method :last_weekday, :prev_weekday
|
223
225
|
|
226
|
+
# Returns a new date/time the specified number of months ago.
|
227
|
+
def prev_month(months = 1)
|
228
|
+
advance(months: -months)
|
229
|
+
end
|
230
|
+
|
224
231
|
# Short-hand for months_ago(1).
|
225
|
-
def
|
232
|
+
def last_month
|
226
233
|
months_ago(1)
|
227
234
|
end
|
228
|
-
alias_method :last_month, :prev_month
|
229
235
|
|
230
236
|
# Short-hand for months_ago(3).
|
231
237
|
def prev_quarter
|
@@ -233,11 +239,15 @@ module DateAndTime
|
|
233
239
|
end
|
234
240
|
alias_method :last_quarter, :prev_quarter
|
235
241
|
|
242
|
+
# Returns a new date/time the specified number of years ago.
|
243
|
+
def prev_year(years = 1)
|
244
|
+
advance(years: -years)
|
245
|
+
end
|
246
|
+
|
236
247
|
# Short-hand for years_ago(1).
|
237
|
-
def
|
248
|
+
def last_year
|
238
249
|
years_ago(1)
|
239
250
|
end
|
240
|
-
alias_method :last_year, :prev_year
|
241
251
|
|
242
252
|
# Returns the number of days to the start of the week on the given day.
|
243
253
|
# Week is assumed to start on +start_day+, default is
|
@@ -320,6 +330,30 @@ module DateAndTime
|
|
320
330
|
beginning_of_year..end_of_year
|
321
331
|
end
|
322
332
|
|
333
|
+
# Returns a new date/time representing the next occurrence of the specified day of week.
|
334
|
+
#
|
335
|
+
# today = Date.today # => Thu, 14 Dec 2017
|
336
|
+
# today.next_occurring(:monday) # => Mon, 18 Dec 2017
|
337
|
+
# today.next_occurring(:thursday) # => Thu, 21 Dec 2017
|
338
|
+
def next_occurring(day_of_week)
|
339
|
+
current_day_number = wday != 0 ? wday - 1 : 6
|
340
|
+
from_now = DAYS_INTO_WEEK.fetch(day_of_week) - current_day_number
|
341
|
+
from_now += 7 unless from_now > 0
|
342
|
+
advance(days: from_now)
|
343
|
+
end
|
344
|
+
|
345
|
+
# Returns a new date/time representing the previous occurrence of the specified day of week.
|
346
|
+
#
|
347
|
+
# today = Date.today # => Thu, 14 Dec 2017
|
348
|
+
# today.prev_occurring(:monday) # => Mon, 11 Dec 2017
|
349
|
+
# today.prev_occurring(:thursday) # => Thu, 07 Dec 2017
|
350
|
+
def prev_occurring(day_of_week)
|
351
|
+
current_day_number = wday != 0 ? wday - 1 : 6
|
352
|
+
ago = current_day_number - DAYS_INTO_WEEK.fetch(day_of_week)
|
353
|
+
ago += 7 unless ago > 0
|
354
|
+
advance(days: -ago)
|
355
|
+
end
|
356
|
+
|
323
357
|
private
|
324
358
|
def first_hour(date_or_time)
|
325
359
|
date_or_time.acts_like?(:time) ? date_or_time.beginning_of_day : date_or_time
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "active_support/core_ext/module/attribute_accessors"
|
2
4
|
|
3
5
|
module DateAndTime
|
@@ -9,6 +11,6 @@ module DateAndTime
|
|
9
11
|
# of the receiver. For backwards compatibility we're overriding
|
10
12
|
# this behavior, but new apps will have an initializer that sets
|
11
13
|
# this to true, because the new behavior is preferred.
|
12
|
-
mattr_accessor
|
14
|
+
mattr_accessor :preserve_timezone, instance_writer: false, default: false
|
13
15
|
end
|
14
16
|
end
|
@@ -1,14 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "active_support/core_ext/date_and_time/compatibility"
|
2
|
-
require "active_support/core_ext/module/
|
4
|
+
require "active_support/core_ext/module/redefine_method"
|
3
5
|
|
4
6
|
class DateTime
|
5
7
|
include DateAndTime::Compatibility
|
6
8
|
|
7
|
-
|
9
|
+
silence_redefinition_of_method :to_time
|
8
10
|
|
9
|
-
# Either return an instance of
|
10
|
-
# as +self+ or an instance of
|
11
|
-
# in the
|
11
|
+
# Either return an instance of +Time+ with the same UTC offset
|
12
|
+
# as +self+ or an instance of +Time+ representing the same time
|
13
|
+
# in the local system timezone depending on the setting of
|
12
14
|
# on the setting of +ActiveSupport.to_time_preserves_timezone+.
|
13
15
|
def to_time
|
14
16
|
preserve_timezone ? getlocal(utc_offset) : getlocal
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "securerandom"
|
2
4
|
|
3
5
|
module Digest
|
@@ -12,7 +14,7 @@ module Digest
|
|
12
14
|
# Using Digest::MD5 generates version 3 UUIDs; Digest::SHA1 generates version 5 UUIDs.
|
13
15
|
# uuid_from_hash always generates the same UUID for a given name and namespace combination.
|
14
16
|
#
|
15
|
-
# See RFC 4122 for details of UUID at:
|
17
|
+
# See RFC 4122 for details of UUID at: https://www.ietf.org/rfc/rfc4122.txt
|
16
18
|
def self.uuid_from_hash(hash_class, uuid_namespace, name)
|
17
19
|
if hash_class == Digest::MD5
|
18
20
|
version = 3
|
@@ -1,5 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Enumerable
|
2
|
-
# Enumerable#sum was added in Ruby 2.4 but it only works with Numeric elements
|
4
|
+
# Enumerable#sum was added in Ruby 2.4, but it only works with Numeric elements
|
3
5
|
# when we omit an identity.
|
4
6
|
#
|
5
7
|
# We tried shimming it to attempt the fast native method, rescue TypeError,
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "active_support/xml_mini"
|
2
4
|
require "active_support/time"
|
3
5
|
require "active_support/core_ext/object/blank"
|
@@ -163,7 +165,7 @@ module ActiveSupport
|
|
163
165
|
Hash[params.map { |k, v| [k.to_s.tr("-", "_"), normalize_keys(v)] } ]
|
164
166
|
when Array
|
165
167
|
params.map { |v| normalize_keys(v) }
|
166
|
-
|
168
|
+
else
|
167
169
|
params
|
168
170
|
end
|
169
171
|
end
|
@@ -176,7 +178,7 @@ module ActiveSupport
|
|
176
178
|
process_array(value)
|
177
179
|
when String
|
178
180
|
value
|
179
|
-
|
181
|
+
else
|
180
182
|
raise "can't typecast #{value.class.name} - #{value.inspect}"
|
181
183
|
end
|
182
184
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class Hash
|
2
4
|
# Returns a new hash with +self+ and +other_hash+ merged recursively.
|
3
5
|
#
|
@@ -19,20 +21,14 @@ class Hash
|
|
19
21
|
|
20
22
|
# Same as +deep_merge+, but modifies +self+.
|
21
23
|
def deep_merge!(other_hash, &block)
|
22
|
-
other_hash
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
24
|
+
merge!(other_hash) do |key, this_val, other_val|
|
25
|
+
if this_val.is_a?(Hash) && other_val.is_a?(Hash)
|
26
|
+
this_val.deep_merge(other_val, &block)
|
27
|
+
elsif block_given?
|
28
|
+
block.call(key, this_val, other_val)
|
27
29
|
else
|
28
|
-
|
29
|
-
block.call(current_key, this_value, other_value)
|
30
|
-
else
|
31
|
-
other_value
|
32
|
-
end
|
30
|
+
other_val
|
33
31
|
end
|
34
32
|
end
|
35
|
-
|
36
|
-
self
|
37
33
|
end
|
38
34
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class Hash
|
2
4
|
# Merges the caller into +other_hash+. For example,
|
3
5
|
#
|
@@ -12,11 +14,12 @@ class Hash
|
|
12
14
|
def reverse_merge(other_hash)
|
13
15
|
other_hash.merge(self)
|
14
16
|
end
|
17
|
+
alias_method :with_defaults, :reverse_merge
|
15
18
|
|
16
19
|
# Destructive +reverse_merge+.
|
17
20
|
def reverse_merge!(other_hash)
|
18
|
-
|
19
|
-
merge!(other_hash) { |key, left, right| left }
|
21
|
+
replace(reverse_merge(other_hash))
|
20
22
|
end
|
21
23
|
alias_method :reverse_update, :reverse_merge!
|
24
|
+
alias_method :with_defaults!, :reverse_merge!
|
22
25
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class Hash
|
2
4
|
# Slices a hash to include only the given keys. Returns a hash containing
|
3
5
|
# the given keys.
|
@@ -19,9 +21,8 @@ class Hash
|
|
19
21
|
# valid_keys = [:mass, :velocity, :time]
|
20
22
|
# search(options.slice(*valid_keys))
|
21
23
|
def slice(*keys)
|
22
|
-
keys.
|
23
|
-
|
24
|
-
end
|
24
|
+
keys.each_with_object(Hash.new) { |k, hash| hash[k] = self[k] if has_key?(k) }
|
25
|
+
end unless method_defined?(:slice)
|
25
26
|
|
26
27
|
# Replaces the hash with only the given keys.
|
27
28
|
# Returns a hash containing the removed key/value pairs.
|
@@ -29,7 +30,6 @@ class Hash
|
|
29
30
|
# { a: 1, b: 2, c: 3, d: 4 }.slice!(:a, :b)
|
30
31
|
# # => {:c=>3, :d=>4}
|
31
32
|
def slice!(*keys)
|
32
|
-
keys.map! { |key| convert_key(key) } if respond_to?(:convert_key, true)
|
33
33
|
omit = slice(*self.keys - keys)
|
34
34
|
hash = slice(*keys)
|
35
35
|
hash.default = default
|