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
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'active_support/values/time_zone'
|
2
2
|
require 'active_support/core_ext/object/acts_like'
|
3
|
+
require 'active_support/core_ext/date_and_time/compatibility'
|
3
4
|
|
4
5
|
module ActiveSupport
|
5
6
|
# A Time-like class that can represent a time in any time zone. Necessary
|
@@ -40,20 +41,21 @@ module ActiveSupport
|
|
40
41
|
'Time'
|
41
42
|
end
|
42
43
|
|
43
|
-
include Comparable
|
44
|
+
include Comparable, DateAndTime::Compatibility
|
44
45
|
attr_reader :time_zone
|
45
46
|
|
46
47
|
def initialize(utc_time, time_zone, local_time = nil, period = nil)
|
47
|
-
@utc
|
48
|
+
@utc = utc_time ? transfer_time_values_to_utc_constructor(utc_time) : nil
|
49
|
+
@time_zone, @time = time_zone, local_time
|
48
50
|
@period = @utc ? period : get_period_and_ensure_valid_local_time(period)
|
49
51
|
end
|
50
52
|
|
51
|
-
# Returns a Time
|
53
|
+
# Returns a <tt>Time</tt> instance that represents the time in +time_zone+.
|
52
54
|
def time
|
53
55
|
@time ||= period.to_local(@utc)
|
54
56
|
end
|
55
57
|
|
56
|
-
# Returns a Time
|
58
|
+
# Returns a <tt>Time</tt> instance of the simultaneous time in the UTC timezone.
|
57
59
|
def utc
|
58
60
|
@utc ||= period.to_utc(@time)
|
59
61
|
end
|
@@ -73,10 +75,9 @@ module ActiveSupport
|
|
73
75
|
utc.in_time_zone(new_zone)
|
74
76
|
end
|
75
77
|
|
76
|
-
# Returns a <tt>Time
|
77
|
-
# system's <tt>ENV['TZ']</tt> zone.
|
78
|
+
# Returns a <tt>Time</tt> instance of the simultaneous time in the system timezone.
|
78
79
|
def localtime(utc_offset = nil)
|
79
|
-
utc.
|
80
|
+
utc.getlocal(utc_offset)
|
80
81
|
end
|
81
82
|
alias_method :getlocal, :localtime
|
82
83
|
|
@@ -160,7 +161,11 @@ module ActiveSupport
|
|
160
161
|
end
|
161
162
|
end
|
162
163
|
|
163
|
-
def
|
164
|
+
def init_with(coder) #:nodoc:
|
165
|
+
initialize(coder['utc'], coder['zone'], coder['time'])
|
166
|
+
end
|
167
|
+
|
168
|
+
def encode_with(coder) #:nodoc:
|
164
169
|
if coder.respond_to?(:represent_object)
|
165
170
|
coder.represent_object(nil, utc)
|
166
171
|
else
|
@@ -236,7 +241,7 @@ module ActiveSupport
|
|
236
241
|
end
|
237
242
|
|
238
243
|
def eql?(other)
|
239
|
-
|
244
|
+
other.eql?(utc)
|
240
245
|
end
|
241
246
|
|
242
247
|
def hash
|
@@ -276,6 +281,7 @@ module ActiveSupport
|
|
276
281
|
utc.since(other).in_time_zone(time_zone)
|
277
282
|
end
|
278
283
|
end
|
284
|
+
alias_method :in, :since
|
279
285
|
|
280
286
|
def ago(other)
|
281
287
|
since(-other)
|
@@ -316,13 +322,19 @@ module ActiveSupport
|
|
316
322
|
utc.to_r
|
317
323
|
end
|
318
324
|
|
319
|
-
|
320
|
-
|
321
|
-
utc.to_time
|
325
|
+
def to_datetime
|
326
|
+
@to_datetime ||= utc.to_datetime.new_offset(Rational(utc_offset, 86_400))
|
322
327
|
end
|
323
328
|
|
324
|
-
|
325
|
-
|
329
|
+
# Returns an instance of +Time+, either with the same UTC offset
|
330
|
+
# as +self+ or in the local system timezone depending on the setting
|
331
|
+
# of +ActiveSupport.to_time_preserves_timezone+.
|
332
|
+
def to_time
|
333
|
+
if preserve_timezone
|
334
|
+
@to_time_with_instance_offset ||= getlocal(utc_offset)
|
335
|
+
else
|
336
|
+
@to_time_with_system_offset ||= getlocal
|
337
|
+
end
|
326
338
|
end
|
327
339
|
|
328
340
|
# So that +self+ <tt>acts_like?(:time)</tt>.
|
@@ -337,7 +349,8 @@ module ActiveSupport
|
|
337
349
|
alias_method :kind_of?, :is_a?
|
338
350
|
|
339
351
|
def freeze
|
340
|
-
|
352
|
+
# preload instance variables before freezing
|
353
|
+
period; utc; time; to_datetime; to_time
|
341
354
|
super
|
342
355
|
end
|
343
356
|
|
@@ -360,7 +373,6 @@ module ActiveSupport
|
|
360
373
|
# Ensure proxy class responds to all methods that underlying time instance
|
361
374
|
# responds to.
|
362
375
|
def respond_to_missing?(sym, include_priv)
|
363
|
-
# consistently respond false to acts_like?(:date), regardless of whether #time is a Time or DateTime
|
364
376
|
return false if sym.to_sym == :acts_like_date?
|
365
377
|
time.respond_to?(sym, include_priv)
|
366
378
|
end
|
@@ -388,7 +400,7 @@ module ActiveSupport
|
|
388
400
|
end
|
389
401
|
|
390
402
|
def transfer_time_values_to_utc_constructor(time)
|
391
|
-
::Time.utc(time.year, time.month, time.day, time.hour, time.min, time.sec
|
403
|
+
::Time.utc(time.year, time.month, time.day, time.hour, time.min, time.sec + time.subsec)
|
392
404
|
end
|
393
405
|
|
394
406
|
def duration_of_variable_length?(obj)
|
@@ -271,7 +271,10 @@ module ActiveSupport
|
|
271
271
|
@name = name
|
272
272
|
@utc_offset = utc_offset
|
273
273
|
@tzinfo = tzinfo || TimeZone.find_tzinfo(name)
|
274
|
-
|
274
|
+
end
|
275
|
+
|
276
|
+
def init_with(coder) #:nodoc:
|
277
|
+
initialize(coder['name'])
|
275
278
|
end
|
276
279
|
|
277
280
|
# Returns the offset of this time zone from UTC in seconds.
|
@@ -279,8 +282,7 @@ module ActiveSupport
|
|
279
282
|
if @utc_offset
|
280
283
|
@utc_offset
|
281
284
|
else
|
282
|
-
|
283
|
-
@current_period.utc_offset if @current_period
|
285
|
+
tzinfo.current_period.utc_offset if tzinfo && tzinfo.current_period
|
284
286
|
end
|
285
287
|
end
|
286
288
|
|
@@ -66,12 +66,9 @@ module ActiveSupport
|
|
66
66
|
data = StringIO.new(data || '')
|
67
67
|
end
|
68
68
|
|
69
|
-
|
70
|
-
if char.nil?
|
69
|
+
if data.eof?
|
71
70
|
{}
|
72
71
|
else
|
73
|
-
data.ungetc(char)
|
74
|
-
|
75
72
|
LibXML::XML::Error.set_handler(&LibXML::XML::Error::QUIET_HANDLER)
|
76
73
|
parser = LibXML::XML::SaxParser.io(data)
|
77
74
|
document = self.document_class.new
|
@@ -72,11 +72,9 @@ module ActiveSupport
|
|
72
72
|
data = StringIO.new(data || '')
|
73
73
|
end
|
74
74
|
|
75
|
-
|
76
|
-
if char.nil?
|
75
|
+
if data.eof?
|
77
76
|
{}
|
78
77
|
else
|
79
|
-
data.ungetc(char)
|
80
78
|
document = self.document_class.new
|
81
79
|
parser = Nokogiri::XML::SAX::Parser.new(document)
|
82
80
|
parser.parse(data)
|
@@ -20,11 +20,9 @@ module ActiveSupport
|
|
20
20
|
data = StringIO.new(data || '')
|
21
21
|
end
|
22
22
|
|
23
|
-
|
24
|
-
if char.nil?
|
23
|
+
if data.eof?
|
25
24
|
{}
|
26
25
|
else
|
27
|
-
data.ungetc(char)
|
28
26
|
silence_warnings { require 'rexml/document' } unless defined?(REXML::Document)
|
29
27
|
doc = REXML::Document.new(data)
|
30
28
|
|
@@ -32,20 +32,25 @@ module ActiveSupport
|
|
32
32
|
"binary" => "base64"
|
33
33
|
} unless defined?(DEFAULT_ENCODINGS)
|
34
34
|
|
35
|
-
TYPE_NAMES
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
35
|
+
unless defined?(TYPE_NAMES)
|
36
|
+
TYPE_NAMES = {
|
37
|
+
"Symbol" => "symbol",
|
38
|
+
"Integer" => "integer",
|
39
|
+
"BigDecimal" => "decimal",
|
40
|
+
"Float" => "float",
|
41
|
+
"TrueClass" => "boolean",
|
42
|
+
"FalseClass" => "boolean",
|
43
|
+
"Date" => "date",
|
44
|
+
"DateTime" => "dateTime",
|
45
|
+
"Time" => "dateTime",
|
46
|
+
"Array" => "array",
|
47
|
+
"Hash" => "hash"
|
48
|
+
}
|
49
|
+
|
50
|
+
# No need to map these on Ruby 2.4+
|
51
|
+
TYPE_NAMES["Fixnum"] = "integer" unless 0.class == Integer
|
52
|
+
TYPE_NAMES["Bignum"] = "integer" unless 0.class == Integer
|
53
|
+
end
|
49
54
|
|
50
55
|
FORMATTING = {
|
51
56
|
"symbol" => Proc.new { |symbol| symbol.to_s },
|
@@ -63,7 +68,17 @@ module ActiveSupport
|
|
63
68
|
"datetime" => Proc.new { |time| Time.xmlschema(time).utc rescue ::DateTime.parse(time).utc },
|
64
69
|
"integer" => Proc.new { |integer| integer.to_i },
|
65
70
|
"float" => Proc.new { |float| float.to_f },
|
66
|
-
"decimal" => Proc.new
|
71
|
+
"decimal" => Proc.new do |number|
|
72
|
+
if String === number
|
73
|
+
begin
|
74
|
+
BigDecimal(number)
|
75
|
+
rescue ArgumentError
|
76
|
+
BigDecimal('0')
|
77
|
+
end
|
78
|
+
else
|
79
|
+
BigDecimal(number)
|
80
|
+
end
|
81
|
+
end,
|
67
82
|
"boolean" => Proc.new { |boolean| %w(1 true).include?(boolean.to_s.strip) },
|
68
83
|
"string" => Proc.new { |string| string.to_s },
|
69
84
|
"yaml" => Proc.new { |yaml| YAML::load(yaml) rescue yaml },
|
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"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activesupport
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.2.
|
4
|
+
version: 4.2.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Heinemeier Hansson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-11-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: i18n
|
@@ -24,26 +24,6 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0.7'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: json
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - "~>"
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '1.7'
|
34
|
-
- - ">="
|
35
|
-
- !ruby/object:Gem::Version
|
36
|
-
version: 1.7.7
|
37
|
-
type: :runtime
|
38
|
-
prerelease: false
|
39
|
-
version_requirements: !ruby/object:Gem::Requirement
|
40
|
-
requirements:
|
41
|
-
- - "~>"
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
version: '1.7'
|
44
|
-
- - ">="
|
45
|
-
- !ruby/object:Gem::Version
|
46
|
-
version: 1.7.7
|
47
27
|
- !ruby/object:Gem::Dependency
|
48
28
|
name: tzinfo
|
49
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -142,10 +122,12 @@ files:
|
|
142
122
|
- lib/active_support/core_ext/date/conversions.rb
|
143
123
|
- lib/active_support/core_ext/date/zones.rb
|
144
124
|
- lib/active_support/core_ext/date_and_time/calculations.rb
|
125
|
+
- lib/active_support/core_ext/date_and_time/compatibility.rb
|
145
126
|
- lib/active_support/core_ext/date_and_time/zones.rb
|
146
127
|
- lib/active_support/core_ext/date_time.rb
|
147
128
|
- lib/active_support/core_ext/date_time/acts_like.rb
|
148
129
|
- lib/active_support/core_ext/date_time/calculations.rb
|
130
|
+
- lib/active_support/core_ext/date_time/compatibility.rb
|
149
131
|
- lib/active_support/core_ext/date_time/conversions.rb
|
150
132
|
- lib/active_support/core_ext/date_time/zones.rb
|
151
133
|
- lib/active_support/core_ext/digest/uuid.rb
|
@@ -231,6 +213,7 @@ files:
|
|
231
213
|
- lib/active_support/core_ext/time.rb
|
232
214
|
- lib/active_support/core_ext/time/acts_like.rb
|
233
215
|
- lib/active_support/core_ext/time/calculations.rb
|
216
|
+
- lib/active_support/core_ext/time/compatibility.rb
|
234
217
|
- lib/active_support/core_ext/time/conversions.rb
|
235
218
|
- lib/active_support/core_ext/time/marshal.rb
|
236
219
|
- lib/active_support/core_ext/time/zones.rb
|
@@ -266,6 +249,7 @@ files:
|
|
266
249
|
- lib/active_support/log_subscriber/test_helper.rb
|
267
250
|
- lib/active_support/logger.rb
|
268
251
|
- lib/active_support/logger_silence.rb
|
252
|
+
- lib/active_support/logger_thread_safe_level.rb
|
269
253
|
- lib/active_support/message_encryptor.rb
|
270
254
|
- lib/active_support/message_verifier.rb
|
271
255
|
- lib/active_support/multibyte.rb
|
@@ -339,7 +323,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
339
323
|
version: '0'
|
340
324
|
requirements: []
|
341
325
|
rubyforge_project:
|
342
|
-
rubygems_version: 2.
|
326
|
+
rubygems_version: 2.7.6
|
343
327
|
signing_key:
|
344
328
|
specification_version: 4
|
345
329
|
summary: A toolkit of support libraries and Ruby core extensions extracted from the
|