activesupport 4.2.5 → 4.2.9
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 +175 -0
- data/lib/active_support.rb +9 -0
- data/lib/active_support/cache/mem_cache_store.rb +1 -1
- data/lib/active_support/callbacks.rb +1 -1
- data/lib/active_support/core_ext/class/subclasses.rb +0 -2
- data/lib/active_support/core_ext/date_and_time/compatibility.rb +15 -0
- data/lib/active_support/core_ext/date_time.rb +1 -0
- data/lib/active_support/core_ext/date_time/calculations.rb +22 -2
- data/lib/active_support/core_ext/date_time/compatibility.rb +15 -0
- data/lib/active_support/core_ext/enumerable.rb +16 -0
- data/lib/active_support/core_ext/hash/compact.rb +19 -15
- data/lib/active_support/core_ext/hash/conversions.rb +1 -2
- data/lib/active_support/core_ext/hash/transform_values.rb +2 -2
- data/lib/active_support/core_ext/marshal.rb +8 -5
- data/lib/active_support/core_ext/numeric/conversions.rb +9 -1
- data/lib/active_support/core_ext/object/duplicable.rb +58 -32
- data/lib/active_support/core_ext/string/access.rb +1 -1
- data/lib/active_support/core_ext/string/conversions.rb +1 -1
- data/lib/active_support/core_ext/time.rb +1 -0
- data/lib/active_support/core_ext/time/calculations.rb +10 -1
- data/lib/active_support/core_ext/time/compatibility.rb +14 -0
- data/lib/active_support/gem_version.rb +1 -1
- data/lib/active_support/hash_with_indifferent_access.rb +9 -0
- data/lib/active_support/inflector/methods.rb +1 -1
- data/lib/active_support/logger.rb +50 -0
- data/lib/active_support/logger_silence.rb +7 -4
- data/lib/active_support/logger_thread_safe_level.rb +32 -0
- data/lib/active_support/message_encryptor.rb +8 -1
- data/lib/active_support/per_thread_registry.rb +2 -0
- data/lib/active_support/security_utils.rb +7 -0
- data/lib/active_support/testing/time_helpers.rb +16 -13
- data/lib/active_support/time_with_zone.rb +28 -16
- data/lib/active_support/values/time_zone.rb +5 -3
- data/lib/active_support/xml_mini.rb +30 -15
- data/lib/active_support/xml_mini/libxml.rb +1 -3
- data/lib/active_support/xml_mini/libxmlsax.rb +1 -4
- data/lib/active_support/xml_mini/nokogiri.rb +1 -3
- data/lib/active_support/xml_mini/nokogirisax.rb +1 -3
- data/lib/active_support/xml_mini/rexml.rb +1 -3
- metadata +7 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2ec63f027f194fd2f7f901f4b10dd0d77d26874b
|
4
|
+
data.tar.gz: 29092cda97238f978d33704180231f6b4cb4819b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7f899b3ae526befc5e03e6e5c2924283bc2a150084acdff79376700e177ac21f93b5156d850215f4f6cbff0c340a61f695abc76cb77618c7065711d338a294b6
|
7
|
+
data.tar.gz: 2393b3194ec6f3710483518826d29f304b0fd1a012d357429976e63d15fe0f67e8fa7ad043bcb13d6cb282e514b87340b291a779e79c42c8e84e7c3deaf61105
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,178 @@
|
|
1
|
+
## Rails 4.2.9 (June 26, 2017) ##
|
2
|
+
|
3
|
+
* Fixed bug in `DateAndTime::Compatibility#to_time` that caused it to
|
4
|
+
raise `RuntimeError: can't modify frozen Time` when called on any frozen `Time`.
|
5
|
+
Properly pass through the frozen `Time` or `ActiveSupport::TimeWithZone` object
|
6
|
+
when calling `#to_time`.
|
7
|
+
|
8
|
+
*Kevin McPhillips* & *Andrew White*
|
9
|
+
|
10
|
+
* Restore the return type of `DateTime#utc`
|
11
|
+
|
12
|
+
In Rails 5.0 the return type of `DateTime#utc` was changed to `Time` to be
|
13
|
+
consistent with the new `DateTime#localtime` method. When these changes were
|
14
|
+
backported in #27553 this inadvertently changed the return type in a patcn
|
15
|
+
release. Since `DateTime#localtime` was new in Rails 4.2.8 it's okay to
|
16
|
+
restore the return type of `DateTime#utc` but keep `DateTime#localtime` as
|
17
|
+
returning `Time` without breaking backwards compatibility.
|
18
|
+
|
19
|
+
*Andrew White*
|
20
|
+
|
21
|
+
* In Core Extensions, make `MarshalWithAutoloading#load` pass through the second, optional
|
22
|
+
argument for `Marshal#load( source [, proc] )`. This way we don't have to do
|
23
|
+
`Marshal.method(:load).super_method.call(sourse, proc)` just to be able to pass a proc.
|
24
|
+
|
25
|
+
*Jeff Latz*
|
26
|
+
|
27
|
+
* Cache `ActiveSupport::TimeWithZone#to_datetime` before freezing.
|
28
|
+
|
29
|
+
*Adam Rice*
|
30
|
+
|
31
|
+
* `AS::Testing::TimeHelpers#travel_to` now changes `DateTime.now` as well as
|
32
|
+
`Time.now` and `Date.today`.
|
33
|
+
|
34
|
+
*Yuki Nishijima*
|
35
|
+
|
36
|
+
|
37
|
+
## Rails 4.2.8 (February 21, 2017) ##
|
38
|
+
|
39
|
+
* Make `getlocal` and `getutc` always return instances of `Time` for
|
40
|
+
`ActiveSupport::TimeWithZone` and `DateTime`. This eliminates a possible
|
41
|
+
stack level too deep error in `to_time` where `ActiveSupport::TimeWithZone`
|
42
|
+
was wrapping a `DateTime` instance. As a consequence of this the internal
|
43
|
+
time value in `ActiveSupport::TimeWithZone` is now always an instance of
|
44
|
+
`Time` in the UTC timezone, whether that's as the UTC time directly or
|
45
|
+
a representation of the local time in the timezone. There should be no
|
46
|
+
consequences of this internal change and if there are it's a bug due to
|
47
|
+
leaky abstractions.
|
48
|
+
|
49
|
+
*Andrew White*
|
50
|
+
|
51
|
+
* Add `DateTime#subsec` to return the fraction of a second as a `Rational`.
|
52
|
+
|
53
|
+
*Andrew White*
|
54
|
+
|
55
|
+
* Add additional aliases for `DateTime#utc` to mirror the ones on
|
56
|
+
`ActiveSupport::TimeWithZone` and `Time`.
|
57
|
+
|
58
|
+
*Andrew White*
|
59
|
+
|
60
|
+
* Add `DateTime#localtime` to return an instance of `Time` in the system's
|
61
|
+
local timezone. Also aliased to `getlocal`.
|
62
|
+
|
63
|
+
*Andrew White*, *Yuichiro Kaneko*
|
64
|
+
|
65
|
+
* Add `Time#sec_fraction` to return the fraction of a second as a `Rational`.
|
66
|
+
|
67
|
+
*Andrew White*
|
68
|
+
|
69
|
+
* Add `ActiveSupport.to_time_preserves_timezone` config option to control
|
70
|
+
how `to_time` handles timezones. In Ruby 2.4+ the behavior will change
|
71
|
+
from converting to the local system timezone, to preserving the timezone
|
72
|
+
of the receiver. This config option defaults to false so that apps made
|
73
|
+
with earlier versions of Rails are not affected when upgrading, e.g:
|
74
|
+
|
75
|
+
>> ENV['TZ'] = 'US/Eastern'
|
76
|
+
|
77
|
+
>> "2016-04-23T10:23:12.000Z".to_time
|
78
|
+
=> "2016-04-23T06:23:12.000-04:00"
|
79
|
+
|
80
|
+
>> ActiveSupport.to_time_preserves_timezone = true
|
81
|
+
|
82
|
+
>> "2016-04-23T10:23:12.000Z".to_time
|
83
|
+
=> "2016-04-23T10:23:12.000Z"
|
84
|
+
|
85
|
+
Fixes #24617.
|
86
|
+
|
87
|
+
*Andrew White*
|
88
|
+
|
89
|
+
* Add `init_with` to `ActiveSupport::TimeWithZone` and `ActiveSupport::TimeZone`
|
90
|
+
|
91
|
+
It is helpful to be able to run apps concurrently written in successive
|
92
|
+
versions of Rails to aid migration, e.g. run Rails 4.2 and 5.0 variants
|
93
|
+
of your application at the same time to carry out A/B testing.
|
94
|
+
|
95
|
+
To do this serialization formats need to be cross compatible and the
|
96
|
+
change in 3aa26cf didn't meet this criteria because the Psych loader
|
97
|
+
checks for the existence of `init_with` before setting the instance
|
98
|
+
variables and the wrapping behavior of `ActiveSupport::TimeWithZone`
|
99
|
+
tries to see if the `Time` instance responds to `init_with` before the
|
100
|
+
`@time` variable is set.
|
101
|
+
|
102
|
+
To fix this we backported just the `init_with` behavior from the change
|
103
|
+
in 3aa26cf. If the revived instance is then written out to YAML again
|
104
|
+
it will revert to the default Rails 4.2 behavior of converting it to
|
105
|
+
a UTC timestamp string.
|
106
|
+
|
107
|
+
Fixes #26296.
|
108
|
+
|
109
|
+
*Andrew White*
|
110
|
+
|
111
|
+
* Fix `ActiveSupport::TimeWithZone#in` across DST boundaries.
|
112
|
+
|
113
|
+
Previously calls to `in` were being sent to the non-DST aware
|
114
|
+
method `Time#since` via `method_missing`. It is now aliased to
|
115
|
+
the DST aware `ActiveSupport::TimeWithZone#since` which handles
|
116
|
+
transitions across DST boundaries, e.g:
|
117
|
+
|
118
|
+
Time.zone = "US/Eastern"
|
119
|
+
|
120
|
+
t = Time.zone.local(2016,11,6,1)
|
121
|
+
# => Sun, 06 Nov 2016 01:00:00 EDT -05:00
|
122
|
+
|
123
|
+
t.in(1.hour)
|
124
|
+
# => Sun, 06 Nov 2016 01:00:00 EST -05:00
|
125
|
+
|
126
|
+
Fixes #26580.
|
127
|
+
|
128
|
+
*Thomas Balthazar*
|
129
|
+
|
130
|
+
|
131
|
+
## Rails 4.2.7 (July 12, 2016) ##
|
132
|
+
|
133
|
+
* Fixed `ActiveSupport::Logger.broadcast` so that calls to `#silence` now
|
134
|
+
properly delegate to all loggers. Silencing now properly suppresses logging
|
135
|
+
to both the log and the console.
|
136
|
+
|
137
|
+
*Kevin McPhillips*
|
138
|
+
|
139
|
+
* Backported `ActiveSupport::LoggerThreadSafeLevel`. Assigning the
|
140
|
+
`Rails.logger.level` is now thread safe.
|
141
|
+
|
142
|
+
*Kevin McPhillips*
|
143
|
+
|
144
|
+
* Fixed a problem with ActiveSupport::SafeBuffer.titleize calling capitalize
|
145
|
+
on nil.
|
146
|
+
|
147
|
+
*Brian McManus*
|
148
|
+
|
149
|
+
* Time zones: Ensure that the UTC offset reflects DST changes that occurred
|
150
|
+
since the app started. Removes UTC offset caching, reducing performance,
|
151
|
+
but this is still relatively quick and isn't in any hot paths.
|
152
|
+
|
153
|
+
*Alexey Shein*
|
154
|
+
|
155
|
+
* Prevent `Marshal.load` from looping infinitely when trying to autoload a constant
|
156
|
+
which resolves to a different name.
|
157
|
+
|
158
|
+
*Olek Janiszewski*
|
159
|
+
|
160
|
+
|
161
|
+
## Rails 4.2.6 (March 07, 2016) ##
|
162
|
+
|
163
|
+
* No changes.
|
164
|
+
|
165
|
+
|
166
|
+
## Rails 4.2.5.2 (February 26, 2016) ##
|
167
|
+
|
168
|
+
* No changes.
|
169
|
+
|
170
|
+
|
171
|
+
## Rails 4.2.5.1 (January 25, 2015) ##
|
172
|
+
|
173
|
+
* No changes.
|
174
|
+
|
175
|
+
|
1
176
|
## Rails 4.2.5 (November 12, 2015) ##
|
2
177
|
|
3
178
|
* Fix `TimeWithZone#eql?` to properly handle `TimeWithZone` created from `DateTime`:
|
data/lib/active_support.rb
CHANGED
@@ -26,6 +26,7 @@ require "active_support/dependencies/autoload"
|
|
26
26
|
require "active_support/version"
|
27
27
|
require "active_support/logger"
|
28
28
|
require "active_support/lazy_load_hooks"
|
29
|
+
require "active_support/core_ext/date_and_time/compatibility"
|
29
30
|
|
30
31
|
module ActiveSupport
|
31
32
|
extend ActiveSupport::Autoload
|
@@ -80,6 +81,14 @@ module ActiveSupport
|
|
80
81
|
def self.test_order # :nodoc:
|
81
82
|
@@test_order
|
82
83
|
end
|
84
|
+
|
85
|
+
def self.to_time_preserves_timezone
|
86
|
+
DateAndTime::Compatibility.preserve_timezone
|
87
|
+
end
|
88
|
+
|
89
|
+
def self.to_time_preserves_timezone=(value)
|
90
|
+
DateAndTime::Compatibility.preserve_timezone = value
|
91
|
+
end
|
83
92
|
end
|
84
93
|
|
85
94
|
autoload :I18n, "active_support/i18n"
|
@@ -67,7 +67,7 @@ module ActiveSupport
|
|
67
67
|
options = names.extract_options!
|
68
68
|
options = merged_options(options)
|
69
69
|
keys_to_names = Hash[names.map{|name| [escape_key(namespaced_key(name, options)), name]}]
|
70
|
-
raw_values = @data.get_multi(keys_to_names.keys
|
70
|
+
raw_values = @data.get_multi(keys_to_names.keys)
|
71
71
|
values = {}
|
72
72
|
raw_values.each do |key, value|
|
73
73
|
entry = deserialize_entry(value)
|
@@ -770,7 +770,7 @@ module ActiveSupport
|
|
770
770
|
options = names.extract_options!
|
771
771
|
|
772
772
|
names.each do |name|
|
773
|
-
class_attribute "_#{name}_callbacks"
|
773
|
+
class_attribute "_#{name}_callbacks", instance_writer: false
|
774
774
|
set_callbacks name, CallbackChain.new(name, options)
|
775
775
|
|
776
776
|
module_eval <<-RUBY, __FILE__, __LINE__ + 1
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'active_support/core_ext/module/attribute_accessors'
|
2
|
+
require 'active_support/core_ext/module/remove_method'
|
3
|
+
|
4
|
+
module DateAndTime
|
5
|
+
module Compatibility
|
6
|
+
# If true, +to_time+ preserves the timezone offset of receiver.
|
7
|
+
#
|
8
|
+
# NOTE: With Ruby 2.4+ the default for +to_time+ changed from
|
9
|
+
# converting to the local system time, to preserving the offset
|
10
|
+
# of the receiver. For backwards compatibility we're overriding
|
11
|
+
# this behavior, but new apps will have an initializer that sets
|
12
|
+
# this to true, because the new behavior is preferred.
|
13
|
+
mattr_accessor(:preserve_timezone, instance_writer: false) { false }
|
14
|
+
end
|
15
|
+
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'active_support/core_ext/date_time/acts_like'
|
2
2
|
require 'active_support/core_ext/date_time/calculations'
|
3
|
+
require 'active_support/core_ext/date_time/compatibility'
|
3
4
|
require 'active_support/core_ext/date_time/conversions'
|
4
5
|
require 'active_support/core_ext/date_time/zones'
|
@@ -24,6 +24,13 @@ class DateTime
|
|
24
24
|
end_of_day.to_i - to_i
|
25
25
|
end
|
26
26
|
|
27
|
+
# Returns the fraction of a second as a +Rational+
|
28
|
+
#
|
29
|
+
# DateTime.new(2012, 8, 29, 0, 0, 0.5).subsec # => (1/2)
|
30
|
+
def subsec
|
31
|
+
sec_fraction
|
32
|
+
end
|
33
|
+
|
27
34
|
# Returns a new DateTime where one or more of the elements have been changed
|
28
35
|
# according to the +options+ parameter. The time options (<tt>:hour</tt>,
|
29
36
|
# <tt>:min</tt>, <tt>:sec</tt>) reset cascadingly, so if only the hour is
|
@@ -139,14 +146,27 @@ class DateTime
|
|
139
146
|
end
|
140
147
|
alias :at_end_of_minute :end_of_minute
|
141
148
|
|
142
|
-
#
|
149
|
+
# Returns a <tt>Time</tt> instance of the simultaneous time in the system timezone.
|
150
|
+
def localtime(utc_offset = nil)
|
151
|
+
utc = new_offset(0)
|
152
|
+
|
153
|
+
Time.utc(
|
154
|
+
utc.year, utc.month, utc.day,
|
155
|
+
utc.hour, utc.min, utc.sec + utc.sec_fraction
|
156
|
+
).getlocal(utc_offset)
|
157
|
+
end
|
158
|
+
alias_method :getlocal, :localtime
|
159
|
+
|
160
|
+
# Returns a <tt>DateTime</tt> instance of the simultaneous time in the UTC timezone.
|
143
161
|
#
|
144
162
|
# DateTime.civil(2005, 2, 21, 10, 11, 12, Rational(-6, 24)) # => Mon, 21 Feb 2005 10:11:12 -0600
|
145
|
-
# DateTime.civil(2005, 2, 21, 10, 11, 12, Rational(-6, 24)).utc # => Mon, 21 Feb 2005 16:11:12
|
163
|
+
# DateTime.civil(2005, 2, 21, 10, 11, 12, Rational(-6, 24)).utc # => Mon, 21 Feb 2005 16:11:12 UTC
|
146
164
|
def utc
|
147
165
|
new_offset(0)
|
148
166
|
end
|
167
|
+
alias_method :getgm, :utc
|
149
168
|
alias_method :getutc, :utc
|
169
|
+
alias_method :gmtime, :utc
|
150
170
|
|
151
171
|
# Returns +true+ if <tt>offset == 0</tt>.
|
152
172
|
def utc?
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'active_support/core_ext/date_and_time/compatibility'
|
2
|
+
|
3
|
+
class DateTime
|
4
|
+
include DateAndTime::Compatibility
|
5
|
+
|
6
|
+
remove_possible_method :to_time
|
7
|
+
|
8
|
+
# Either return an instance of `Time` with the same UTC offset
|
9
|
+
# as +self+ or an instance of `Time` representing the same time
|
10
|
+
# in the the local system timezone depending on the setting of
|
11
|
+
# on the setting of +ActiveSupport.to_time_preserves_timezone+.
|
12
|
+
def to_time
|
13
|
+
preserve_timezone ? getlocal(utc_offset) : getlocal
|
14
|
+
end
|
15
|
+
end
|
@@ -78,3 +78,19 @@ class Range #:nodoc:
|
|
78
78
|
end
|
79
79
|
end
|
80
80
|
end
|
81
|
+
|
82
|
+
# Array#sum was added in Ruby 2.4 but it only works with Numeric elements.
|
83
|
+
#
|
84
|
+
# We tried shimming it to attempt the fast native method, rescue TypeError,
|
85
|
+
# and fall back to the compatible implementation, but that's much slower than
|
86
|
+
# just calling the compat method in the first place.
|
87
|
+
if Array.instance_methods(false).include?(:sum) && !(%w[a].sum rescue false)
|
88
|
+
class Array
|
89
|
+
remove_method :sum
|
90
|
+
|
91
|
+
def sum(*args) #:nodoc:
|
92
|
+
# Use Enumerable#sum instead.
|
93
|
+
super
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
@@ -1,20 +1,24 @@
|
|
1
1
|
class Hash
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
2
|
+
unless Hash.instance_methods(false).include?(:compact)
|
3
|
+
# Returns a hash with non +nil+ values.
|
4
|
+
#
|
5
|
+
# hash = { a: true, b: false, c: nil}
|
6
|
+
# hash.compact # => { a: true, b: false}
|
7
|
+
# hash # => { a: true, b: false, c: nil}
|
8
|
+
# { c: nil }.compact # => {}
|
9
|
+
def compact
|
10
|
+
self.select { |_, value| !value.nil? }
|
11
|
+
end
|
10
12
|
end
|
11
13
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
14
|
+
unless Hash.instance_methods(false).include?(:compact!)
|
15
|
+
# Replaces current hash with non +nil+ values.
|
16
|
+
#
|
17
|
+
# hash = { a: true, b: false, c: nil}
|
18
|
+
# hash.compact! # => { a: true, b: false}
|
19
|
+
# hash # => { a: true, b: false}
|
20
|
+
def compact!
|
21
|
+
self.reject! { |_, value| value.nil? }
|
22
|
+
end
|
19
23
|
end
|
20
24
|
end
|
@@ -11,7 +11,7 @@ class Hash
|
|
11
11
|
result[key] = yield(value)
|
12
12
|
end
|
13
13
|
result
|
14
|
-
end
|
14
|
+
end unless method_defined? :transform_values
|
15
15
|
|
16
16
|
# Destructive +transform_values+
|
17
17
|
def transform_values!
|
@@ -19,5 +19,5 @@ class Hash
|
|
19
19
|
each do |key, value|
|
20
20
|
self[key] = yield(value)
|
21
21
|
end
|
22
|
-
end
|
22
|
+
end unless method_defined? :transform_values!
|
23
23
|
end
|
@@ -2,13 +2,16 @@ require 'active_support/core_ext/module/aliasing'
|
|
2
2
|
|
3
3
|
module Marshal
|
4
4
|
class << self
|
5
|
-
def load_with_autoloading(source)
|
6
|
-
load_without_autoloading(source)
|
5
|
+
def load_with_autoloading(source, proc = nil)
|
6
|
+
load_without_autoloading(source, proc)
|
7
7
|
rescue ArgumentError, NameError => exc
|
8
|
-
if exc.message.match(%r|undefined class/module (
|
8
|
+
if exc.message.match(%r|undefined class/module (.+?)(::)?\z|)
|
9
9
|
# try loading the class/module
|
10
|
-
$1.constantize
|
11
|
-
|
10
|
+
loaded = $1.constantize
|
11
|
+
|
12
|
+
raise unless $1 == loaded.name
|
13
|
+
|
14
|
+
# if it is an IO we need to go back to read the object
|
12
15
|
source.rewind if source.respond_to?(:rewind)
|
13
16
|
retry
|
14
17
|
else
|
@@ -118,7 +118,15 @@ class Numeric
|
|
118
118
|
end
|
119
119
|
end
|
120
120
|
|
121
|
-
[Float,
|
121
|
+
klasses = [Float, BigDecimal]
|
122
|
+
# Ruby 2.4+ unifies Fixnum & Bignum into Integer.
|
123
|
+
if 0.class == Integer
|
124
|
+
klasses << Integer
|
125
|
+
else
|
126
|
+
klasses << Fixnum << Bignum
|
127
|
+
end
|
128
|
+
|
129
|
+
klasses.each do |klass|
|
122
130
|
klass.send(:alias_method, :to_default_s, :to_s)
|
123
131
|
|
124
132
|
klass.send(:define_method, :to_s) do |*args|
|