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.

Files changed (48) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +219 -0
  3. data/lib/active_support/cache/mem_cache_store.rb +1 -1
  4. data/lib/active_support/cache.rb +1 -1
  5. data/lib/active_support/callbacks.rb +12 -4
  6. data/lib/active_support/core_ext/class/subclasses.rb +0 -2
  7. data/lib/active_support/core_ext/date_and_time/compatibility.rb +15 -0
  8. data/lib/active_support/core_ext/date_time/calculations.rb +22 -2
  9. data/lib/active_support/core_ext/date_time/compatibility.rb +16 -0
  10. data/lib/active_support/core_ext/date_time.rb +1 -0
  11. data/lib/active_support/core_ext/enumerable.rb +16 -0
  12. data/lib/active_support/core_ext/hash/compact.rb +19 -15
  13. data/lib/active_support/core_ext/hash/conversions.rb +1 -2
  14. data/lib/active_support/core_ext/hash/transform_values.rb +2 -2
  15. data/lib/active_support/core_ext/marshal.rb +8 -5
  16. data/lib/active_support/core_ext/module/method_transplanting.rb +3 -1
  17. data/lib/active_support/core_ext/numeric/conversions.rb +11 -3
  18. data/lib/active_support/core_ext/object/blank.rb +2 -2
  19. data/lib/active_support/core_ext/object/duplicable.rb +58 -32
  20. data/lib/active_support/core_ext/object/json.rb +1 -1
  21. data/lib/active_support/core_ext/object/try.rb +2 -2
  22. data/lib/active_support/core_ext/string/access.rb +1 -1
  23. data/lib/active_support/core_ext/string/conversions.rb +1 -1
  24. data/lib/active_support/core_ext/time/calculations.rb +17 -1
  25. data/lib/active_support/core_ext/time/compatibility.rb +14 -0
  26. data/lib/active_support/core_ext/time.rb +1 -0
  27. data/lib/active_support/gem_version.rb +1 -1
  28. data/lib/active_support/hash_with_indifferent_access.rb +22 -3
  29. data/lib/active_support/inflector/methods.rb +1 -1
  30. data/lib/active_support/logger.rb +50 -0
  31. data/lib/active_support/logger_silence.rb +7 -4
  32. data/lib/active_support/logger_thread_safe_level.rb +32 -0
  33. data/lib/active_support/message_encryptor.rb +8 -1
  34. data/lib/active_support/message_verifier.rb +1 -1
  35. data/lib/active_support/notifications/fanout.rb +1 -1
  36. data/lib/active_support/per_thread_registry.rb +5 -3
  37. data/lib/active_support/security_utils.rb +7 -0
  38. data/lib/active_support/testing/time_helpers.rb +16 -13
  39. data/lib/active_support/time_with_zone.rb +29 -17
  40. data/lib/active_support/values/time_zone.rb +5 -3
  41. data/lib/active_support/xml_mini/libxml.rb +1 -3
  42. data/lib/active_support/xml_mini/libxmlsax.rb +1 -4
  43. data/lib/active_support/xml_mini/nokogiri.rb +1 -3
  44. data/lib/active_support/xml_mini/nokogirisax.rb +1 -3
  45. data/lib/active_support/xml_mini/rexml.rb +1 -3
  46. data/lib/active_support/xml_mini.rb +30 -15
  47. data/lib/active_support.rb +9 -0
  48. 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, @time_zone, @time = utc_time, time_zone, local_time
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 or DateTime instance that represents the time in +time_zone+.
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 or DateTime instance that represents the time in UTC.
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.local()</tt> instance of the simultaneous time in your
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.respond_to?(:getlocal) ? utc.getlocal(utc_offset) : utc.to_time.getlocal(utc_offset)
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 encode_with(coder)
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
- utc.eql?(other)
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
- # Return an instance of Time in the system timezone.
320
- def to_time
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
- def to_datetime
325
- utc.to_datetime.new_offset(Rational(utc_offset, 86_400))
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
- period; utc; time # preload instance variables before freezing
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, Rational(time.nsec, 1000))
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
- @current_period = nil
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
- @current_period ||= tzinfo.current_period if tzinfo
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
 
@@ -14,11 +14,9 @@ module ActiveSupport
14
14
  data = StringIO.new(data || '')
15
15
  end
16
16
 
17
- char = data.getc
18
- if char.nil?
17
+ if data.eof?
19
18
  {}
20
19
  else
21
- data.ungetc(char)
22
20
  LibXML::XML::Parser.io(data).parse.to_hash
23
21
  end
24
22
  end
@@ -66,12 +66,9 @@ module ActiveSupport
66
66
  data = StringIO.new(data || '')
67
67
  end
68
68
 
69
- char = data.getc
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
@@ -19,11 +19,9 @@ module ActiveSupport
19
19
  data = StringIO.new(data || '')
20
20
  end
21
21
 
22
- char = data.getc
23
- if char.nil?
22
+ if data.eof?
24
23
  {}
25
24
  else
26
- data.ungetc(char)
27
25
  doc = Nokogiri::XML(data)
28
26
  raise doc.errors.first if doc.errors.length > 0
29
27
  doc.to_hash
@@ -72,11 +72,9 @@ module ActiveSupport
72
72
  data = StringIO.new(data || '')
73
73
  end
74
74
 
75
- char = data.getc
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
- char = data.getc
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
- "Symbol" => "symbol",
37
- "Fixnum" => "integer",
38
- "Bignum" => "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
- } unless defined?(TYPE_NAMES)
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 { |number| BigDecimal(number) },
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 },
@@ -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.3
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: 2015-06-25 00:00:00.000000000 Z
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.4.5
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