activesupport 5.0.2 → 5.0.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 38c7585e44c8fcebcb942e32922c3abca85eac17
4
- data.tar.gz: e6bcbaaf95381dd7e20633bc9a885115c8672e0b
3
+ metadata.gz: b73696bd08ebaa4e3109235c45930b63f259a6e6
4
+ data.tar.gz: e5292e62983a63ecd47a646614b703df110a4c0e
5
5
  SHA512:
6
- metadata.gz: 1c61507eb6e27ab8de540a19212b3a093a24779433ddfccb05940fc3c8386f48ac47b2167317713f2ea3c7c494e69fc3d4b64ff8b990d5ab9065ceecd580da2c
7
- data.tar.gz: a47a19457d46646a50f64cf0a67d0dab3d026889b2a3bac06121e6a84e6d9c312be648789a5bf34721a4d679aca4daf86b066c69df15e29ee168623fddc1f29c
6
+ metadata.gz: a4f4e401ac2a420190adbdbbc29253ea48c9aecd81a681d8cf6278c1f1e6ac6143d25a63f2b1469cb3acf236b2bc50f910a840f0674318b353530dce7db331d0
7
+ data.tar.gz: c2054174052b34a286a269f24576fa4b99e30985e7ef2218fef2ea90dc49c78c6df9ecc251e270ad5f420a89173dee87f90c9aaefa7391559aa08815e210ed84
@@ -1,7 +1,42 @@
1
+ * `ActiveSupport::EventedFileUpdateChecker` no longer listens to
2
+ directories outside of the application directory.
3
+
4
+ *radiospiel*
5
+
6
+ * Return unmapped timezones from `country_zones`
7
+
8
+ If a country doesn't exist in the MAPPINGS hash then create a new
9
+ `ActiveSupport::Timezone` instance using the supplied timezone id.
10
+
11
+ Fixes #28431.
12
+
13
+ *Andrew White*
14
+
15
+ * Fixed bug in `DateAndTime::Compatibility#to_time` that caused it to
16
+ raise `RuntimeError: can't modify frozen Time` when called on any frozen `Time`.
17
+ Properly pass through the frozen `Time` or `ActiveSupport::TimeWithZone` object
18
+ when calling `#to_time`.
19
+
20
+ *Kevin McPhillips* & *Andrew White*
21
+
22
+ * Fix inconsistent results when parsing large durations and constructing durations from code
23
+
24
+ ActiveSupport::Duration.parse('P3Y') == 3.years # It should be true
25
+
26
+ Duration parsing made independent from any moment of time:
27
+ Fixed length in seconds is assigned to each duration part during parsing.
28
+
29
+ Methods on `Numeric` like `2.days` now use these predefined durations
30
+ to avoid duplicating of duration constants through the codebase and
31
+ eliminate creation of intermediate durations.
32
+
33
+ *Andrey Novikov, Andrew White*
34
+
35
+
1
36
  ## Rails 5.0.2 (March 01, 2017) ##
2
37
 
3
38
  * In Core Extensions, make `MarshalWithAutoloading#load` pass through the second, optional
4
- argument for `Marshal#load( source [, proc] )`. This way we don't have to do
39
+ argument for `Marshal#load( source [, proc] )`. This way we don't have to do
5
40
  `Marshal.method(:load).super_method.call(sourse, proc)` just to be able to pass a proc.
6
41
 
7
42
  *Jeff Latz*
@@ -29,13 +29,13 @@ module ActiveSupport
29
29
  response[2] = ::Rack::BodyProxy.new(response[2]) do
30
30
  LocalCacheRegistry.set_cache_for(local_cache_key, nil)
31
31
  end
32
+ cleanup_on_body_close = true
32
33
  response
33
34
  rescue Rack::Utils::InvalidParameterError
34
- LocalCacheRegistry.set_cache_for(local_cache_key, nil)
35
35
  [400, {}, []]
36
- rescue Exception
37
- LocalCacheRegistry.set_cache_for(local_cache_key, nil)
38
- raise
36
+ ensure
37
+ LocalCacheRegistry.set_cache_for(local_cache_key, nil) unless
38
+ cleanup_on_body_close
39
39
  end
40
40
  end
41
41
  end
@@ -10,13 +10,5 @@ module DateAndTime
10
10
  # this behavior, but new apps will have an initializer that sets
11
11
  # this to true, because the new behavior is preferred.
12
12
  mattr_accessor(:preserve_timezone, instance_writer: false) { false }
13
-
14
- def to_time
15
- if preserve_timezone
16
- @_to_time_with_instance_offset ||= getlocal(utc_offset)
17
- else
18
- @_to_time_with_system_offset ||= getlocal
19
- end
20
- end
21
13
  end
22
14
  end
@@ -1,5 +1,15 @@
1
1
  require 'active_support/core_ext/date_and_time/compatibility'
2
2
 
3
3
  class DateTime
4
- prepend DateAndTime::Compatibility
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
5
15
  end
@@ -1,28 +1,50 @@
1
1
  module Enumerable
2
- # Calculates a sum from the elements.
2
+ # Enumerable#sum was added in Ruby 2.4 but it only works with Numeric elements
3
+ # when we omit an identity.
3
4
  #
4
- # payments.sum { |p| p.price * p.tax_rate }
5
- # payments.sum(&:price)
6
- #
7
- # The latter is a shortcut for:
8
- #
9
- # payments.inject(0) { |sum, p| sum + p.price }
10
- #
11
- # It can also calculate the sum without the use of a block.
12
- #
13
- # [5, 15, 10].sum # => 30
14
- # ['foo', 'bar'].sum # => "foobar"
15
- # [[1, 2], [3, 1, 5]].sum => [1, 2, 3, 1, 5]
16
- #
17
- # The default sum of an empty list is zero. You can override this default:
18
- #
19
- # [].sum(Payment.new(0)) { |i| i.amount } # => Payment.new(0)
20
- def sum(identity = nil, &block)
21
- if block_given?
22
- map(&block).sum(identity)
23
- else
24
- sum = identity ? inject(identity, :+) : inject(:+)
25
- sum || identity || 0
5
+ # We tried shimming it to attempt the fast native method, rescue TypeError,
6
+ # and fall back to the compatible implementation, but that's much slower than
7
+ # just calling the compat method in the first place.
8
+ if Enumerable.instance_methods(false).include?(:sum) && !((?a..?b).sum rescue false)
9
+ # We can't use Refinements here because Refinements with Module which will be prepended
10
+ # doesn't work well https://bugs.ruby-lang.org/issues/13446
11
+ alias :_original_sum_with_required_identity :sum
12
+ private :_original_sum_with_required_identity
13
+ # Calculates a sum from the elements.
14
+ #
15
+ # payments.sum { |p| p.price * p.tax_rate }
16
+ # payments.sum(&:price)
17
+ #
18
+ # The latter is a shortcut for:
19
+ #
20
+ # payments.inject(0) { |sum, p| sum + p.price }
21
+ #
22
+ # It can also calculate the sum without the use of a block.
23
+ #
24
+ # [5, 15, 10].sum # => 30
25
+ # ['foo', 'bar'].sum # => "foobar"
26
+ # [[1, 2], [3, 1, 5]].sum # => [1, 2, 3, 1, 5]
27
+ #
28
+ # The default sum of an empty list is zero. You can override this default:
29
+ #
30
+ # [].sum(Payment.new(0)) { |i| i.amount } # => Payment.new(0)
31
+ def sum(identity = nil, &block)
32
+ if identity
33
+ _original_sum_with_required_identity(identity, &block)
34
+ elsif block_given?
35
+ map(&block).sum(identity)
36
+ else
37
+ inject(:+) || 0
38
+ end
39
+ end
40
+ else
41
+ def sum(identity = nil, &block)
42
+ if block_given?
43
+ map(&block).sum(identity)
44
+ else
45
+ sum = identity ? inject(identity, :+) : inject(:+)
46
+ sum || identity || 0
47
+ end
26
48
  end
27
49
  end
28
50
 
@@ -18,12 +18,12 @@ class Integer
18
18
  # # equivalent to Time.now.advance(months: 4, years: 5)
19
19
  # (4.months + 5.years).from_now
20
20
  def months
21
- ActiveSupport::Duration.new(self * 30.days, [[:months, self]])
21
+ ActiveSupport::Duration.months(self)
22
22
  end
23
23
  alias :month :months
24
24
 
25
25
  def years
26
- ActiveSupport::Duration.new(self * 365.25.days.to_i, [[:years, self]])
26
+ ActiveSupport::Duration.years(self)
27
27
  end
28
28
  alias :year :years
29
29
  end
@@ -19,7 +19,7 @@ class Numeric
19
19
  # # equivalent to Time.current.advance(months: 4, years: 5)
20
20
  # (4.months + 5.years).from_now
21
21
  def seconds
22
- ActiveSupport::Duration.new(self, [[:seconds, self]])
22
+ ActiveSupport::Duration.seconds(self)
23
23
  end
24
24
  alias :second :seconds
25
25
 
@@ -27,7 +27,7 @@ class Numeric
27
27
  #
28
28
  # 2.minutes # => 2 minutes
29
29
  def minutes
30
- ActiveSupport::Duration.new(self * 60, [[:minutes, self]])
30
+ ActiveSupport::Duration.minutes(self)
31
31
  end
32
32
  alias :minute :minutes
33
33
 
@@ -35,7 +35,7 @@ class Numeric
35
35
  #
36
36
  # 2.hours # => 2 hours
37
37
  def hours
38
- ActiveSupport::Duration.new(self * 3600, [[:hours, self]])
38
+ ActiveSupport::Duration.hours(self)
39
39
  end
40
40
  alias :hour :hours
41
41
 
@@ -43,7 +43,7 @@ class Numeric
43
43
  #
44
44
  # 2.days # => 2 days
45
45
  def days
46
- ActiveSupport::Duration.new(self * 24.hours, [[:days, self]])
46
+ ActiveSupport::Duration.days(self)
47
47
  end
48
48
  alias :day :days
49
49
 
@@ -51,7 +51,7 @@ class Numeric
51
51
  #
52
52
  # 2.weeks # => 2 weeks
53
53
  def weeks
54
- ActiveSupport::Duration.new(self * 7.days, [[:weeks, self]])
54
+ ActiveSupport::Duration.weeks(self)
55
55
  end
56
56
  alias :week :weeks
57
57
 
@@ -59,7 +59,7 @@ class Numeric
59
59
  #
60
60
  # 2.fortnights # => 4 weeks
61
61
  def fortnights
62
- ActiveSupport::Duration.new(self * 2.weeks, [[:weeks, self * 2]])
62
+ ActiveSupport::Duration.weeks(self * 2)
63
63
  end
64
64
  alias :fortnight :fortnights
65
65
 
@@ -1,5 +1,14 @@
1
- require 'active_support/core_ext/date_and_time/compatibility'
1
+ require "active_support/core_ext/date_and_time/compatibility"
2
+ require "active_support/core_ext/module/remove_method"
2
3
 
3
4
  class Time
4
- prepend DateAndTime::Compatibility
5
+ include DateAndTime::Compatibility
6
+
7
+ remove_possible_method :to_time
8
+
9
+ # Either return +self+ or the time in the local system timezone depending
10
+ # on the setting of +ActiveSupport.to_time_preserves_timezone+.
11
+ def to_time
12
+ preserve_timezone ? self : getlocal
13
+ end
5
14
  end
@@ -7,13 +7,82 @@ module ActiveSupport
7
7
  #
8
8
  # 1.month.ago # equivalent to Time.now.advance(months: -1)
9
9
  class Duration
10
- EPOCH = ::Time.utc(2000)
10
+ SECONDS_PER_MINUTE = 60
11
+ SECONDS_PER_HOUR = 3600
12
+ SECONDS_PER_DAY = 86400
13
+ SECONDS_PER_WEEK = 604800
14
+ SECONDS_PER_MONTH = 2592000 # 30 days
15
+ SECONDS_PER_YEAR = 31557600 # length of a julian year (365.2425 days)
16
+
17
+ PARTS_IN_SECONDS = {
18
+ seconds: 1,
19
+ minutes: SECONDS_PER_MINUTE,
20
+ hours: SECONDS_PER_HOUR,
21
+ days: SECONDS_PER_DAY,
22
+ weeks: SECONDS_PER_WEEK,
23
+ months: SECONDS_PER_MONTH,
24
+ years: SECONDS_PER_YEAR
25
+ }.freeze
11
26
 
12
27
  attr_accessor :value, :parts
13
28
 
14
29
  autoload :ISO8601Parser, 'active_support/duration/iso8601_parser'
15
30
  autoload :ISO8601Serializer, 'active_support/duration/iso8601_serializer'
16
31
 
32
+ class << self
33
+ # Creates a new Duration from string formatted according to ISO 8601 Duration.
34
+ #
35
+ # See {ISO 8601}[http://en.wikipedia.org/wiki/ISO_8601#Durations] for more information.
36
+ # This method allows negative parts to be present in pattern.
37
+ # If invalid string is provided, it will raise +ActiveSupport::Duration::ISO8601Parser::ParsingError+.
38
+ def parse(iso8601duration)
39
+ parts = ISO8601Parser.new(iso8601duration).parse!
40
+ new(calculate_total_seconds(parts), parts)
41
+ end
42
+
43
+ def ===(other) #:nodoc:
44
+ other.is_a?(Duration)
45
+ rescue ::NoMethodError
46
+ false
47
+ end
48
+
49
+ def seconds(value) #:nodoc:
50
+ new(value, [[:seconds, value]])
51
+ end
52
+
53
+ def minutes(value) #:nodoc:
54
+ new(value * SECONDS_PER_MINUTE, [[:minutes, value]])
55
+ end
56
+
57
+ def hours(value) #:nodoc:
58
+ new(value * SECONDS_PER_HOUR, [[:hours, value]])
59
+ end
60
+
61
+ def days(value) #:nodoc:
62
+ new(value * SECONDS_PER_DAY, [[:days, value]])
63
+ end
64
+
65
+ def weeks(value) #:nodoc:
66
+ new(value * SECONDS_PER_WEEK, [[:weeks, value]])
67
+ end
68
+
69
+ def months(value) #:nodoc:
70
+ new(value * SECONDS_PER_MONTH, [[:months, value]])
71
+ end
72
+
73
+ def years(value) #:nodoc:
74
+ new(value * SECONDS_PER_YEAR, [[:years, value]])
75
+ end
76
+
77
+ private
78
+
79
+ def calculate_total_seconds(parts)
80
+ parts.inject(0) do |total, (part, value)|
81
+ total + value * PARTS_IN_SECONDS[part]
82
+ end
83
+ end
84
+ end
85
+
17
86
  def initialize(value, parts) #:nodoc:
18
87
  @value, @parts = value, parts
19
88
  end
@@ -99,12 +168,6 @@ module ActiveSupport
99
168
  @value.hash
100
169
  end
101
170
 
102
- def self.===(other) #:nodoc:
103
- other.is_a?(Duration)
104
- rescue ::NoMethodError
105
- false
106
- end
107
-
108
171
  # Calculates a new Time or Date that is as far in the future
109
172
  # as this Duration represents.
110
173
  def since(time = ::Time.current)
@@ -135,16 +198,6 @@ module ActiveSupport
135
198
  @value.respond_to?(method, include_private)
136
199
  end
137
200
 
138
- # Creates a new Duration from string formatted according to ISO 8601 Duration.
139
- #
140
- # See {ISO 8601}[http://en.wikipedia.org/wiki/ISO_8601#Durations] for more information.
141
- # This method allows negative parts to be present in pattern.
142
- # If invalid string is provided, it will raise +ActiveSupport::Duration::ISO8601Parser::ParsingError+.
143
- def self.parse(iso8601duration)
144
- parts = ISO8601Parser.new(iso8601duration).parse!
145
- new(EPOCH.advance(parts) - EPOCH, parts)
146
- end
147
-
148
201
  # Build ISO 8601 Duration string for this duration.
149
202
  # The +precision+ parameter can be used to limit seconds' precision of duration.
150
203
  def iso8601(precision: nil)
@@ -121,6 +121,11 @@ module ActiveSupport
121
121
  dtw.compact!
122
122
  dtw.uniq!
123
123
 
124
+ normalized_gem_paths = Gem.path.map { |path| File.join path, "" }
125
+ dtw = dtw.reject do |path|
126
+ normalized_gem_paths.any? { |gem_path| path.to_s.start_with?(gem_path) }
127
+ end
128
+
124
129
  @ph.filter_out_descendants(dtw)
125
130
  end
126
131
 
@@ -7,7 +7,7 @@ module ActiveSupport
7
7
  module VERSION
8
8
  MAJOR = 5
9
9
  MINOR = 0
10
- TINY = 2
10
+ TINY = 3
11
11
  PRE = nil
12
12
 
13
13
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
@@ -83,13 +83,19 @@ module ActiveSupport
83
83
  # rescue_with_handler(exception) || raise
84
84
  # end
85
85
  #
86
- # Returns the exception if it was handled and nil if it was not.
87
- def rescue_with_handler(exception, object: self)
86
+ # Returns the exception if it was handled and +nil+ if it was not.
87
+ def rescue_with_handler(exception, object: self, visited_exceptions: [])
88
+ visited_exceptions << exception
89
+
88
90
  if handler = handler_for_rescue(exception, object: object)
89
91
  handler.call exception
90
92
  exception
91
93
  elsif exception
92
- rescue_with_handler(exception.cause, object: object)
94
+ if visited_exceptions.include?(exception.cause)
95
+ nil
96
+ else
97
+ rescue_with_handler(exception.cause, object: object, visited_exceptions: visited_exceptions)
98
+ end
93
99
  end
94
100
  end
95
101
 
@@ -1,3 +1,5 @@
1
+ require "active_support/core_ext/time/calculations"
2
+
1
3
  module ActiveSupport
2
4
  module Testing
3
5
  class SimpleStubs # :nodoc:
@@ -411,6 +411,17 @@ module ActiveSupport
411
411
  utc.to_datetime.new_offset(Rational(utc_offset, 86_400))
412
412
  end
413
413
 
414
+ # Returns an instance of +Time+, either with the same UTC offset
415
+ # as +self+ or in the local system timezone depending on the setting
416
+ # of +ActiveSupport.to_time_preserves_timezone+.
417
+ def to_time
418
+ if preserve_timezone
419
+ @to_time_with_instance_offset ||= getlocal(utc_offset)
420
+ else
421
+ @to_time_with_system_offset ||= getlocal
422
+ end
423
+ end
424
+
414
425
  # So that +self+ <tt>acts_like?(:time)</tt>.
415
426
  def acts_like_time?
416
427
  true
@@ -429,7 +440,7 @@ module ActiveSupport
429
440
 
430
441
  def freeze
431
442
  # preload instance variables before freezing
432
- period; utc; time; to_datetime
443
+ period; utc; time; to_datetime; to_time
433
444
  super
434
445
  end
435
446
 
@@ -250,14 +250,21 @@ module ActiveSupport
250
250
  # for time zones in the country specified by its ISO 3166-1 Alpha2 code.
251
251
  def country_zones(country_code)
252
252
  code = country_code.to_s.upcase
253
- @country_zones[code] ||=
254
- TZInfo::Country.get(code).zone_identifiers.map do |tz_id|
255
- name = MAPPING.key(tz_id)
256
- name && self[name]
257
- end.compact.sort!
253
+ @country_zones[code] ||= load_country_zones(code)
258
254
  end
259
255
 
260
256
  private
257
+ def load_country_zones(code)
258
+ country = TZInfo::Country.get(code)
259
+ country.zone_identifiers.map do |tz_id|
260
+ if MAPPING.value?(tz_id)
261
+ self[MAPPING.key(tz_id)]
262
+ else
263
+ create(tz_id, nil, TZInfo::Timezone.new(tz_id))
264
+ end
265
+ end.sort!
266
+ end
267
+
261
268
  def zones_map
262
269
  @zones_map ||= begin
263
270
  MAPPING.each_key {|place| self[place]} # load all the zones
@@ -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)
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: 5.0.2
4
+ version: 5.0.3
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: 2017-03-01 00:00:00.000000000 Z
11
+ date: 2017-05-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: i18n
@@ -342,3 +342,4 @@ specification_version: 4
342
342
  summary: A toolkit of support libraries and Ruby core extensions extracted from the
343
343
  Rails framework.
344
344
  test_files: []
345
+ has_rdoc: