activesupport 4.2.3 → 4.2.11
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 +219 -0
- data/lib/active_support/cache/mem_cache_store.rb +1 -1
- data/lib/active_support/cache.rb +1 -1
- data/lib/active_support/callbacks.rb +12 -4
- 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/calculations.rb +22 -2
- data/lib/active_support/core_ext/date_time/compatibility.rb +16 -0
- data/lib/active_support/core_ext/date_time.rb +1 -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/module/method_transplanting.rb +3 -1
- data/lib/active_support/core_ext/numeric/conversions.rb +11 -3
- data/lib/active_support/core_ext/object/blank.rb +2 -2
- data/lib/active_support/core_ext/object/duplicable.rb +58 -32
- data/lib/active_support/core_ext/object/json.rb +1 -1
- data/lib/active_support/core_ext/object/try.rb +2 -2
- 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/calculations.rb +17 -1
- data/lib/active_support/core_ext/time/compatibility.rb +14 -0
- data/lib/active_support/core_ext/time.rb +1 -0
- data/lib/active_support/gem_version.rb +1 -1
- data/lib/active_support/hash_with_indifferent_access.rb +22 -3
- 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/message_verifier.rb +1 -1
- data/lib/active_support/notifications/fanout.rb +1 -1
- data/lib/active_support/per_thread_registry.rb +5 -3
- 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 +29 -17
- data/lib/active_support/values/time_zone.rb +5 -3
- 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
- data/lib/active_support/xml_mini.rb +30 -15
- data/lib/active_support.rb +9 -0
- metadata +7 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: cbc69ee5fd3790d505b9d0ecbeeaf63189475f08203ddb3547eb381fa7071d08
|
4
|
+
data.tar.gz: cda2de40335c62e94e808823fbe753530e0b208a955a7da4453e0980705fdb57
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 54655398cbc15c76cc08a7e16e9a1a665a9f982255d0296c5ccec583c500e80f3af0be1e987263250af97b370d12d6b60d21241c0d5c0684e60993320923f36d
|
7
|
+
data.tar.gz: f694f7451016b43a85549302e8707af51bd359a61b76cd5c269a9fedc50d0171d03a54594ab412c91bd880f2dfcbcb274dcd50a9f85af3f50a29bfdabb04e454
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,222 @@
|
|
1
|
+
## Rails 4.2.11 (November 27, 2018) ##
|
2
|
+
|
3
|
+
* No changes.
|
4
|
+
|
5
|
+
|
6
|
+
## Rails 4.2.10 (September 27, 2017) ##
|
7
|
+
|
8
|
+
* No changes.
|
9
|
+
|
10
|
+
|
11
|
+
## Rails 4.2.9 (June 26, 2017) ##
|
12
|
+
|
13
|
+
* Fixed bug in `DateAndTime::Compatibility#to_time` that caused it to
|
14
|
+
raise `RuntimeError: can't modify frozen Time` when called on any frozen `Time`.
|
15
|
+
Properly pass through the frozen `Time` or `ActiveSupport::TimeWithZone` object
|
16
|
+
when calling `#to_time`.
|
17
|
+
|
18
|
+
*Kevin McPhillips* & *Andrew White*
|
19
|
+
|
20
|
+
* Restore the return type of `DateTime#utc`
|
21
|
+
|
22
|
+
In Rails 5.0 the return type of `DateTime#utc` was changed to `Time` to be
|
23
|
+
consistent with the new `DateTime#localtime` method. When these changes were
|
24
|
+
backported in #27553 this inadvertently changed the return type in a patcn
|
25
|
+
release. Since `DateTime#localtime` was new in Rails 4.2.8 it's okay to
|
26
|
+
restore the return type of `DateTime#utc` but keep `DateTime#localtime` as
|
27
|
+
returning `Time` without breaking backwards compatibility.
|
28
|
+
|
29
|
+
*Andrew White*
|
30
|
+
|
31
|
+
* In Core Extensions, make `MarshalWithAutoloading#load` pass through the second, optional
|
32
|
+
argument for `Marshal#load( source [, proc] )`. This way we don't have to do
|
33
|
+
`Marshal.method(:load).super_method.call(sourse, proc)` just to be able to pass a proc.
|
34
|
+
|
35
|
+
*Jeff Latz*
|
36
|
+
|
37
|
+
* Cache `ActiveSupport::TimeWithZone#to_datetime` before freezing.
|
38
|
+
|
39
|
+
*Adam Rice*
|
40
|
+
|
41
|
+
* `AS::Testing::TimeHelpers#travel_to` now changes `DateTime.now` as well as
|
42
|
+
`Time.now` and `Date.today`.
|
43
|
+
|
44
|
+
*Yuki Nishijima*
|
45
|
+
|
46
|
+
|
47
|
+
## Rails 4.2.8 (February 21, 2017) ##
|
48
|
+
|
49
|
+
* Make `getlocal` and `getutc` always return instances of `Time` for
|
50
|
+
`ActiveSupport::TimeWithZone` and `DateTime`. This eliminates a possible
|
51
|
+
stack level too deep error in `to_time` where `ActiveSupport::TimeWithZone`
|
52
|
+
was wrapping a `DateTime` instance. As a consequence of this the internal
|
53
|
+
time value in `ActiveSupport::TimeWithZone` is now always an instance of
|
54
|
+
`Time` in the UTC timezone, whether that's as the UTC time directly or
|
55
|
+
a representation of the local time in the timezone. There should be no
|
56
|
+
consequences of this internal change and if there are it's a bug due to
|
57
|
+
leaky abstractions.
|
58
|
+
|
59
|
+
*Andrew White*
|
60
|
+
|
61
|
+
* Add `DateTime#subsec` to return the fraction of a second as a `Rational`.
|
62
|
+
|
63
|
+
*Andrew White*
|
64
|
+
|
65
|
+
* Add additional aliases for `DateTime#utc` to mirror the ones on
|
66
|
+
`ActiveSupport::TimeWithZone` and `Time`.
|
67
|
+
|
68
|
+
*Andrew White*
|
69
|
+
|
70
|
+
* Add `DateTime#localtime` to return an instance of `Time` in the system's
|
71
|
+
local timezone. Also aliased to `getlocal`.
|
72
|
+
|
73
|
+
*Andrew White*, *Yuichiro Kaneko*
|
74
|
+
|
75
|
+
* Add `Time#sec_fraction` to return the fraction of a second as a `Rational`.
|
76
|
+
|
77
|
+
*Andrew White*
|
78
|
+
|
79
|
+
* Add `ActiveSupport.to_time_preserves_timezone` config option to control
|
80
|
+
how `to_time` handles timezones. In Ruby 2.4+ the behavior will change
|
81
|
+
from converting to the local system timezone, to preserving the timezone
|
82
|
+
of the receiver. This config option defaults to false so that apps made
|
83
|
+
with earlier versions of Rails are not affected when upgrading, e.g:
|
84
|
+
|
85
|
+
>> ENV['TZ'] = 'US/Eastern'
|
86
|
+
|
87
|
+
>> "2016-04-23T10:23:12.000Z".to_time
|
88
|
+
=> "2016-04-23T06:23:12.000-04:00"
|
89
|
+
|
90
|
+
>> ActiveSupport.to_time_preserves_timezone = true
|
91
|
+
|
92
|
+
>> "2016-04-23T10:23:12.000Z".to_time
|
93
|
+
=> "2016-04-23T10:23:12.000Z"
|
94
|
+
|
95
|
+
Fixes #24617.
|
96
|
+
|
97
|
+
*Andrew White*
|
98
|
+
|
99
|
+
* Add `init_with` to `ActiveSupport::TimeWithZone` and `ActiveSupport::TimeZone`
|
100
|
+
|
101
|
+
It is helpful to be able to run apps concurrently written in successive
|
102
|
+
versions of Rails to aid migration, e.g. run Rails 4.2 and 5.0 variants
|
103
|
+
of your application at the same time to carry out A/B testing.
|
104
|
+
|
105
|
+
To do this serialization formats need to be cross compatible and the
|
106
|
+
change in 3aa26cf didn't meet this criteria because the Psych loader
|
107
|
+
checks for the existence of `init_with` before setting the instance
|
108
|
+
variables and the wrapping behavior of `ActiveSupport::TimeWithZone`
|
109
|
+
tries to see if the `Time` instance responds to `init_with` before the
|
110
|
+
`@time` variable is set.
|
111
|
+
|
112
|
+
To fix this we backported just the `init_with` behavior from the change
|
113
|
+
in 3aa26cf. If the revived instance is then written out to YAML again
|
114
|
+
it will revert to the default Rails 4.2 behavior of converting it to
|
115
|
+
a UTC timestamp string.
|
116
|
+
|
117
|
+
Fixes #26296.
|
118
|
+
|
119
|
+
*Andrew White*
|
120
|
+
|
121
|
+
* Fix `ActiveSupport::TimeWithZone#in` across DST boundaries.
|
122
|
+
|
123
|
+
Previously calls to `in` were being sent to the non-DST aware
|
124
|
+
method `Time#since` via `method_missing`. It is now aliased to
|
125
|
+
the DST aware `ActiveSupport::TimeWithZone#since` which handles
|
126
|
+
transitions across DST boundaries, e.g:
|
127
|
+
|
128
|
+
Time.zone = "US/Eastern"
|
129
|
+
|
130
|
+
t = Time.zone.local(2016,11,6,1)
|
131
|
+
# => Sun, 06 Nov 2016 01:00:00 EDT -05:00
|
132
|
+
|
133
|
+
t.in(1.hour)
|
134
|
+
# => Sun, 06 Nov 2016 01:00:00 EST -05:00
|
135
|
+
|
136
|
+
Fixes #26580.
|
137
|
+
|
138
|
+
*Thomas Balthazar*
|
139
|
+
|
140
|
+
|
141
|
+
## Rails 4.2.7 (July 12, 2016) ##
|
142
|
+
|
143
|
+
* Fixed `ActiveSupport::Logger.broadcast` so that calls to `#silence` now
|
144
|
+
properly delegate to all loggers. Silencing now properly suppresses logging
|
145
|
+
to both the log and the console.
|
146
|
+
|
147
|
+
*Kevin McPhillips*
|
148
|
+
|
149
|
+
* Backported `ActiveSupport::LoggerThreadSafeLevel`. Assigning the
|
150
|
+
`Rails.logger.level` is now thread safe.
|
151
|
+
|
152
|
+
*Kevin McPhillips*
|
153
|
+
|
154
|
+
* Fixed a problem with ActiveSupport::SafeBuffer.titleize calling capitalize
|
155
|
+
on nil.
|
156
|
+
|
157
|
+
*Brian McManus*
|
158
|
+
|
159
|
+
* Time zones: Ensure that the UTC offset reflects DST changes that occurred
|
160
|
+
since the app started. Removes UTC offset caching, reducing performance,
|
161
|
+
but this is still relatively quick and isn't in any hot paths.
|
162
|
+
|
163
|
+
*Alexey Shein*
|
164
|
+
|
165
|
+
* Prevent `Marshal.load` from looping infinitely when trying to autoload a constant
|
166
|
+
which resolves to a different name.
|
167
|
+
|
168
|
+
*Olek Janiszewski*
|
169
|
+
|
170
|
+
|
171
|
+
## Rails 4.2.6 (March 07, 2016) ##
|
172
|
+
|
173
|
+
* No changes.
|
174
|
+
|
175
|
+
|
176
|
+
## Rails 4.2.5.2 (February 26, 2016) ##
|
177
|
+
|
178
|
+
* No changes.
|
179
|
+
|
180
|
+
|
181
|
+
## Rails 4.2.5.1 (January 25, 2015) ##
|
182
|
+
|
183
|
+
* No changes.
|
184
|
+
|
185
|
+
|
186
|
+
## Rails 4.2.5 (November 12, 2015) ##
|
187
|
+
|
188
|
+
* Fix `TimeWithZone#eql?` to properly handle `TimeWithZone` created from `DateTime`:
|
189
|
+
twz = DateTime.now.in_time_zone
|
190
|
+
twz.eql?(twz.dup) => true
|
191
|
+
|
192
|
+
Fixes #14178.
|
193
|
+
|
194
|
+
*Roque Pinel*
|
195
|
+
|
196
|
+
* Handle invalid UTF-8 characters in `MessageVerifier.verify`.
|
197
|
+
|
198
|
+
*Roque Pinel*, *Grey Baker*
|
199
|
+
|
200
|
+
|
201
|
+
## Rails 4.2.4 (August 24, 2015) ##
|
202
|
+
|
203
|
+
* Fix a `SystemStackError` when encoding an `Enumerable` with `json` gem and
|
204
|
+
with the Active Support JSON encoder loaded.
|
205
|
+
|
206
|
+
Fixes #20775.
|
207
|
+
|
208
|
+
*Sammy Larbi*, *Prathamesh Sonpatki*
|
209
|
+
|
210
|
+
* Fix not calling `#default` on `HashWithIndifferentAcess#to_hash` when only
|
211
|
+
`default_proc` is set, which could raise.
|
212
|
+
|
213
|
+
*Simon Eskildsen*
|
214
|
+
|
215
|
+
* Fix setting `default_proc` on `HashWithIndifferentAccess#dup`
|
216
|
+
|
217
|
+
*Simon Eskildsen*
|
218
|
+
|
219
|
+
|
1
220
|
## Rails 4.2.3 (June 25, 2015) ##
|
2
221
|
|
3
222
|
* Fix a range of values for parameters of the Time#change
|
@@ -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)
|
data/lib/active_support/cache.rb
CHANGED
@@ -27,7 +27,7 @@ module ActiveSupport
|
|
27
27
|
end
|
28
28
|
|
29
29
|
class << self
|
30
|
-
# Creates a new
|
30
|
+
# Creates a new Store object according to the given options.
|
31
31
|
#
|
32
32
|
# If no arguments are passed to this method, then a new
|
33
33
|
# ActiveSupport::Cache::MemoryStore object will be returned.
|
@@ -78,8 +78,12 @@ module ActiveSupport
|
|
78
78
|
# save
|
79
79
|
# end
|
80
80
|
def run_callbacks(kind, &block)
|
81
|
-
|
81
|
+
send "_run_#{kind}_callbacks", &block
|
82
|
+
end
|
83
|
+
|
84
|
+
private
|
82
85
|
|
86
|
+
def __run_callbacks__(callbacks, &block)
|
83
87
|
if callbacks.empty?
|
84
88
|
yield if block_given?
|
85
89
|
else
|
@@ -89,8 +93,6 @@ module ActiveSupport
|
|
89
93
|
end
|
90
94
|
end
|
91
95
|
|
92
|
-
private
|
93
|
-
|
94
96
|
# A hook invoked every time a before callback is halted.
|
95
97
|
# This can be overridden in AS::Callback implementors in order
|
96
98
|
# to provide better debugging/logging.
|
@@ -768,8 +770,14 @@ module ActiveSupport
|
|
768
770
|
options = names.extract_options!
|
769
771
|
|
770
772
|
names.each do |name|
|
771
|
-
class_attribute "_#{name}_callbacks"
|
773
|
+
class_attribute "_#{name}_callbacks", instance_writer: false
|
772
774
|
set_callbacks name, CallbackChain.new(name, options)
|
775
|
+
|
776
|
+
module_eval <<-RUBY, __FILE__, __LINE__ + 1
|
777
|
+
def _run_#{name}_callbacks(&block)
|
778
|
+
__run_callbacks__(_#{name}_callbacks, &block)
|
779
|
+
end
|
780
|
+
RUBY
|
773
781
|
end
|
774
782
|
end
|
775
783
|
|
@@ -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
|
@@ -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,16 @@
|
|
1
|
+
require 'active_support/core_ext/date_and_time/compatibility'
|
2
|
+
require 'active_support/core_ext/module/remove_method'
|
3
|
+
|
4
|
+
class DateTime
|
5
|
+
include DateAndTime::Compatibility
|
6
|
+
|
7
|
+
remove_possible_method :to_time
|
8
|
+
|
9
|
+
# Either return an instance of `Time` with the same UTC offset
|
10
|
+
# as +self+ or an instance of `Time` representing the same time
|
11
|
+
# in the the local system timezone depending on the setting of
|
12
|
+
# on the setting of +ActiveSupport.to_time_preserves_timezone+.
|
13
|
+
def to_time
|
14
|
+
preserve_timezone ? getlocal(utc_offset) : getlocal
|
15
|
+
end
|
16
|
+
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'
|
@@ -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
|
@@ -2,7 +2,9 @@ class Module
|
|
2
2
|
###
|
3
3
|
# TODO: remove this after 1.9 support is dropped
|
4
4
|
def methods_transplantable? # :nodoc:
|
5
|
-
x = Module.new {
|
5
|
+
x = Module.new {
|
6
|
+
def foo; end # :nodoc:
|
7
|
+
}
|
6
8
|
Module.new { define_method :bar, x.instance_method(:foo) }
|
7
9
|
true
|
8
10
|
rescue TypeError
|
@@ -41,7 +41,7 @@ class Numeric
|
|
41
41
|
# 1000.to_s(:percentage, delimiter: '.', separator: ',') # => 1.000,000%
|
42
42
|
# 302.24398923423.to_s(:percentage, precision: 5) # => 302.24399%
|
43
43
|
# 1000.to_s(:percentage, locale: :fr) # => 1 000,000%
|
44
|
-
# 100.to_s(:percentage, format: '%n %') # => 100 %
|
44
|
+
# 100.to_s(:percentage, format: '%n %') # => 100.000 %
|
45
45
|
#
|
46
46
|
# Delimited:
|
47
47
|
# 12345678.to_s(:delimited) # => 12,345,678
|
@@ -78,7 +78,7 @@ class Numeric
|
|
78
78
|
# 1234567.to_s(:human_size, precision: 2) # => 1.2 MB
|
79
79
|
# 483989.to_s(:human_size, precision: 2) # => 470 KB
|
80
80
|
# 1234567.to_s(:human_size, precision: 2, separator: ',') # => 1,2 MB
|
81
|
-
# 1234567890123.to_s(:human_size, precision: 5) # => "1.
|
81
|
+
# 1234567890123.to_s(:human_size, precision: 5) # => "1.1228 TB"
|
82
82
|
# 524288000.to_s(:human_size, precision: 5) # => "500 MB"
|
83
83
|
#
|
84
84
|
# Human-friendly format:
|
@@ -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|
|
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
class Object
|
4
4
|
# An object is blank if it's false, empty, or a whitespace string.
|
5
|
-
# For example, '', ' ', +nil+, [], and {} are all blank.
|
5
|
+
# For example, +false+, '', ' ', +nil+, [], and {} are all blank.
|
6
6
|
#
|
7
7
|
# This simplifies
|
8
8
|
#
|
9
|
-
# address
|
9
|
+
# !address || address.empty?
|
10
10
|
#
|
11
11
|
# to
|
12
12
|
#
|