activesupport 5.0.0.beta3 → 5.0.0.beta4

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 (53) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +171 -4
  3. data/lib/active_support.rb +12 -0
  4. data/lib/active_support/cache.rb +32 -23
  5. data/lib/active_support/cache/strategy/local_cache.rb +1 -1
  6. data/lib/active_support/callbacks.rb +4 -4
  7. data/lib/active_support/concurrency/share_lock.rb +2 -2
  8. data/lib/active_support/core_ext/array/grouping.rb +6 -10
  9. data/lib/active_support/core_ext/date/conversions.rb +1 -0
  10. data/lib/active_support/core_ext/date_and_time/calculations.rb +2 -0
  11. data/lib/active_support/core_ext/date_and_time/compatibility.rb +18 -0
  12. data/lib/active_support/core_ext/date_time.rb +1 -1
  13. data/lib/active_support/core_ext/date_time/calculations.rb +30 -8
  14. data/lib/active_support/core_ext/date_time/compatibility.rb +5 -0
  15. data/lib/active_support/core_ext/enumerable.rb +16 -0
  16. data/lib/active_support/core_ext/hash/conversions.rb +1 -1
  17. data/lib/active_support/core_ext/hash/keys.rb +1 -1
  18. data/lib/active_support/core_ext/marshal.rb +5 -2
  19. data/lib/active_support/core_ext/module/attribute_accessors.rb +2 -2
  20. data/lib/active_support/core_ext/module/attribute_accessors_per_thread.rb +2 -2
  21. data/lib/active_support/core_ext/module/delegation.rb +2 -5
  22. data/lib/active_support/core_ext/module/introspection.rb +4 -0
  23. data/lib/active_support/core_ext/object/blank.rb +7 -3
  24. data/lib/active_support/core_ext/object/json.rb +6 -0
  25. data/lib/active_support/core_ext/string/conversions.rb +3 -2
  26. data/lib/active_support/core_ext/string/inflections.rb +9 -0
  27. data/lib/active_support/core_ext/string/output_safety.rb +1 -1
  28. data/lib/active_support/core_ext/time.rb +1 -0
  29. data/lib/active_support/core_ext/time/calculations.rb +7 -0
  30. data/lib/active_support/core_ext/time/compatibility.rb +5 -0
  31. data/lib/active_support/dependencies.rb +9 -52
  32. data/lib/active_support/dependencies/interlock.rb +6 -8
  33. data/lib/active_support/deprecation/reporting.rb +0 -1
  34. data/lib/active_support/duration.rb +20 -0
  35. data/lib/active_support/duration/iso8601_parser.rb +122 -0
  36. data/lib/active_support/duration/iso8601_serializer.rb +51 -0
  37. data/lib/active_support/evented_file_update_checker.rb +18 -13
  38. data/lib/active_support/execution_wrapper.rb +117 -0
  39. data/lib/active_support/executor.rb +6 -0
  40. data/lib/active_support/file_update_checker.rb +22 -2
  41. data/lib/active_support/gem_version.rb +1 -1
  42. data/lib/active_support/i18n_railtie.rb +2 -2
  43. data/lib/active_support/inflector/methods.rb +9 -0
  44. data/lib/active_support/number_helper.rb +8 -1
  45. data/lib/active_support/number_helper/number_to_delimited_converter.rb +1 -1
  46. data/lib/active_support/number_helper/number_to_phone_converter.rb +11 -2
  47. data/lib/active_support/number_helper/number_to_rounded_converter.rb +5 -3
  48. data/lib/active_support/reloader.rb +129 -0
  49. data/lib/active_support/rescuable.rb +10 -0
  50. data/lib/active_support/time_with_zone.rb +9 -14
  51. data/lib/active_support/values/time_zone.rb +14 -5
  52. metadata +12 -5
  53. data/lib/active_support/core_ext/date_time/zones.rb +0 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4a5dea5a1bb0a9929afd19a9a16bf8c82cdc97a3
4
- data.tar.gz: fd271c0c13149c6029f3b876f70b4463959cd5a5
3
+ metadata.gz: 8995c0f44dc006471b68548dc53dc51fbf52ea55
4
+ data.tar.gz: 75a84a6b054b348460ac48e3d8cb50e289b7c14f
5
5
  SHA512:
6
- metadata.gz: b97891236c826598c8b68c32104e7f39e08004cbd365c75fd3fce1214c535193a13bfb6a836788b7959ca7960838abc306b5220e0b36fdfe45aef163ff4c4ae7
7
- data.tar.gz: d2d0aa34eb7dcdb0845735b6961a5d132ebe1f5d382de5c503b551dc040272fd35a00ca456ba9a5c103c992632277bf1874f8e3ccded9f11688decd1693f48f3
6
+ metadata.gz: 734344387c65492c8f1773bf2b08587f006b9e02d6bc30622bb66b1258a453ba96a7d36d5c4cf89f459f1ffcced68f9c315e72cbbf643e8723fea2327e602597
7
+ data.tar.gz: b0798910b73a354f74c6b96f86d962910de002ef13116b1423c9a4435c1327c1cdc5846af2fb1a30065cd0531f397069dcc90e7bd33fd6a86a158692776b9759
@@ -1,3 +1,168 @@
1
+ ## Rails 5.0.0.beta4 (April 27, 2016) ##
2
+
3
+ * Time zones: Ensure that the UTC offset reflects DST changes that occurred
4
+ since the app started. Removes UTC offset caching, reducing performance,
5
+ but this is still relatively quick and isn't in any hot paths.
6
+
7
+ *Alexey Shein*
8
+
9
+ * Make `getlocal` and `getutc` always return instances of `Time` for
10
+ `ActiveSupport::TimeWithZone` and `DateTime`. This eliminates a possible
11
+ stack level too deep error in `to_time` where `ActiveSupport::TimeWithZone`
12
+ was wrapping a `DateTime` instance. As a consequence of this the internal
13
+ time value in `ActiveSupport::TimeWithZone` is now always an instance of
14
+ `Time` in the UTC timezone, whether that's as the UTC time directly or
15
+ a representation of the local time in the timezone. There should be no
16
+ consequences of this internal change and if there are it's a bug due to
17
+ leaky abstractions.
18
+
19
+ *Andrew White*
20
+
21
+ * Add `DateTime#subsec` to return the fraction of a second as a `Rational`.
22
+
23
+ *Andrew White*
24
+
25
+ * Add additional aliases for `DateTime#utc` to mirror the ones on
26
+ `ActiveSupport::TimeWithZone` and `Time`.
27
+
28
+ *Andrew White*
29
+
30
+ * Add `DateTime#localtime` to return an instance of `Time` in the system's
31
+ local timezone. Also aliased to `getlocal`.
32
+
33
+ *Andrew White*, *Yuichiro Kaneko*
34
+
35
+ * Add `Time#sec_fraction` to return the fraction of a second as a `Rational`.
36
+
37
+ *Andrew White*
38
+
39
+ * Add `ActiveSupport.to_time_preserves_timezone` config option to control
40
+ how `to_time` handles timezones. In Ruby 2.4+ the behavior will change
41
+ from converting to the local system timezone, to preserving the timezone
42
+ of the receiver. This config option defaults to false so that apps made
43
+ with earlier versions of Rails are not affected when upgrading, e.g:
44
+
45
+ >> ENV['TZ'] = 'US/Eastern'
46
+
47
+ >> "2016-04-23T10:23:12.000Z".to_time
48
+ => "2016-04-23T06:23:12.000-04:00"
49
+
50
+ >> ActiveSupport.to_time_preserves_timezone = true
51
+
52
+ >> "2016-04-23T10:23:12.000Z".to_time
53
+ => "2016-04-23T10:23:12.000Z"
54
+
55
+ Fixes #24617.
56
+
57
+ *Andrew White*
58
+
59
+ * `ActiveSupport::TimeZone.country_zones(country_code)` looks up the
60
+ country's time zones by its two-letter ISO3166 country code, e.g.
61
+
62
+ >> ActiveSupport::TimeZone.country_zones(:jp).map(&:to_s)
63
+ => ["(GMT+09:00) Osaka"]
64
+
65
+ >> ActiveSupport::TimeZone.country_zones(:uy).map(&:to_s)
66
+ => ["(GMT-03:00) Montevideo"]
67
+
68
+ *Andrey Novikov*
69
+
70
+ * `Array#sum` compat with Ruby 2.4's native method.
71
+
72
+ Ruby 2.4 introduces `Array#sum`, but it only supports numeric elements,
73
+ breaking our `Enumerable#sum` which supports arbitrary `Object#+`.
74
+ To fix, override `Array#sum` with our compatible implementation.
75
+
76
+ Native Ruby 2.4:
77
+
78
+ %w[ a b ].sum
79
+ # => TypeError: String can't be coerced into Fixnum
80
+
81
+ With `Enumerable#sum` shim:
82
+
83
+ %w[ a b ].sum
84
+ # => 'ab'
85
+
86
+ We tried shimming the fast path and falling back to the compatible path
87
+ if it fails, but that ends up slower even in simple cases due to the cost
88
+ of exception handling. Our only choice is to override the native `Array#sum`
89
+ with our `Enumerable#sum`.
90
+
91
+ *Jeremy Daer*
92
+
93
+ * `ActiveSupport::Duration` supports ISO8601 formatting and parsing.
94
+
95
+ ActiveSupport::Duration.parse('P3Y6M4DT12H30M5S')
96
+ # => 3 years, 6 months, 4 days, 12 hours, 30 minutes, and 5 seconds
97
+
98
+ (3.years + 3.days).iso8601
99
+ # => "P3Y3D"
100
+
101
+ Inspired by Arnau Siches' [ISO8601 gem](https://github.com/arnau/ISO8601/)
102
+ and rewritten by Andrey Novikov with suggestions from Andrew White. Test
103
+ data from the ISO8601 gem redistributed under MIT license.
104
+
105
+ (Will be used to support the PostgreSQL interval data type.)
106
+
107
+ *Andrey Novikov*, *Arnau Siches*, *Andrew White*
108
+
109
+ * `Cache#fetch(key, force: true)` forces a cache miss, so it must be called
110
+ with a block to provide a new value to cache. Fetching with `force: true`
111
+ but without a block now raises ArgumentError.
112
+
113
+ cache.fetch('key', force: true) # => ArgumentError
114
+
115
+ *Santosh Wadghule*
116
+
117
+ * Fix behavior of JSON encoding for `Exception`.
118
+
119
+ *namusyaka*
120
+
121
+ * Make `number_to_phone` format number with regexp pattern.
122
+
123
+ number_to_phone(18812345678, pattern: /(\d{3})(\d{4})(\d{4})/)
124
+ # => 188-1234-5678
125
+
126
+ *Pan Gaoyong*
127
+
128
+ * Match `String#to_time`'s behaviour to that of ruby's implementation for edge cases.
129
+
130
+ `nil` is now returned instead of the current date if the string provided does
131
+ contain time information, but none that is used to build the `Time` object.
132
+
133
+ Fixes #22958.
134
+
135
+ *Siim Liiser*
136
+
137
+ * Rely on the native DateTime#<=> implementation to handle non-datetime like
138
+ objects instead of returning `nil` ourselves. This restores the ability
139
+ of `DateTime` instances to be compared with a `Numeric` that represents an
140
+ astronomical julian day number.
141
+
142
+ Fixes #24228.
143
+
144
+ *Andrew White*
145
+
146
+ * Add `String#upcase_first` method.
147
+
148
+ *Glauco Custódio*, *bogdanvlviv*
149
+
150
+ * Prevent `Marshal.load` from looping infinitely when trying to autoload a constant
151
+ which resolves to a different name.
152
+
153
+ *Olek Janiszewski*
154
+
155
+ * Deprecate `Module.local_constants`. Please use `Module.constants(false)` instead.
156
+
157
+ *Yuichiro Kaneko*
158
+
159
+ * Publish `ActiveSupport::Executor` and `ActiveSupport::Reloader` APIs to allow
160
+ components and libraries to manage, and participate in, the execution of
161
+ application code, and the application reloading process.
162
+
163
+ *Matthew Draper*
164
+
165
+
1
166
  ## Rails 5.0.0.beta3 (February 24, 2016) ##
2
167
 
3
168
  * Deprecate arguments on `assert_nothing_raised`.
@@ -9,7 +174,7 @@
9
174
 
10
175
  *Tara Scherner de la Fuente*
11
176
 
12
- * Make `benchmark('something', silence: true)` actually work
177
+ * Make `benchmark('something', silence: true)` actually work.
13
178
 
14
179
  *DHH*
15
180
 
@@ -24,13 +189,14 @@
24
189
 
25
190
  *Brian Christian*
26
191
 
27
- * Fix regression in `Hash#dig` for HashWithIndifferentAccess.
192
+ * Fix regression in `Hash#dig` for HashWithIndifferentAccess.
193
+
194
+ *Jon Moss*
28
195
 
29
- *Jon Moss*
30
196
 
31
197
  ## Rails 5.0.0.beta2 (February 01, 2016) ##
32
198
 
33
- * Change number_to_currency behavior for checking negativity.
199
+ * Change `number_to_currency` behavior for checking negativity.
34
200
 
35
201
  Used `to_f.negative` instead of using `to_f.phase` for checking negativity
36
202
  of a number in number_to_currency helper.
@@ -65,6 +231,7 @@
65
231
 
66
232
  *Akshay Vishnoi*
67
233
 
234
+
68
235
  ## Rails 5.0.0.beta1 (December 18, 2015) ##
69
236
 
70
237
  * Add thread_m/cattr_accessor/reader/writer suite of methods for declaring class and module variables that live per-thread.
@@ -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
@@ -33,10 +34,13 @@ module ActiveSupport
33
34
  autoload :Concern
34
35
  autoload :Dependencies
35
36
  autoload :DescendantsTracker
37
+ autoload :ExecutionWrapper
38
+ autoload :Executor
36
39
  autoload :FileUpdateChecker
37
40
  autoload :EventedFileUpdateChecker
38
41
  autoload :LogSubscriber
39
42
  autoload :Notifications
43
+ autoload :Reloader
40
44
 
41
45
  eager_autoload do
42
46
  autoload :BacktraceCleaner
@@ -82,6 +86,14 @@ module ActiveSupport
82
86
  def self.halt_callback_chains_on_return_false=(value)
83
87
  Callbacks.halt_and_display_warning_on_return_false = value
84
88
  end
89
+
90
+ def self.to_time_preserves_timezone
91
+ DateAndTime::Compatibility.preserve_timezone
92
+ end
93
+
94
+ def self.to_time_preserves_timezone=(value)
95
+ DateAndTime::Compatibility.preserve_timezone = value
96
+ end
85
97
  end
86
98
 
87
99
  autoload :I18n, "active_support/i18n"
@@ -158,20 +158,20 @@ module ActiveSupport
158
158
  attr_reader :silence, :options
159
159
  alias :silence? :silence
160
160
 
161
- # Create a new cache. The options will be passed to any write method calls
161
+ # Creates a new cache. The options will be passed to any write method calls
162
162
  # except for <tt>:namespace</tt> which can be used to set the global
163
163
  # namespace for the cache.
164
164
  def initialize(options = nil)
165
165
  @options = options ? options.dup : {}
166
166
  end
167
167
 
168
- # Silence the logger.
168
+ # Silences the logger.
169
169
  def silence!
170
170
  @silence = true
171
171
  self
172
172
  end
173
173
 
174
- # Silence the logger within a block.
174
+ # Silences the logger within a block.
175
175
  def mute
176
176
  previous_silence, @silence = defined?(@silence) && @silence, true
177
177
  yield
@@ -198,10 +198,17 @@ module ActiveSupport
198
198
  # cache.fetch('city') # => "Duckburgh"
199
199
  #
200
200
  # You may also specify additional options via the +options+ argument.
201
- # Setting <tt>force: true</tt> will force a cache miss:
201
+ # Setting <tt>force: true</tt> forces a cache "miss," meaning we treat
202
+ # the cache value as missing even if it's present. Passing a block is
203
+ # required when `force` is true so this always results in a cache write.
202
204
  #
203
205
  # cache.write('today', 'Monday')
204
- # cache.fetch('today', force: true) # => nil
206
+ # cache.fetch('today', force: true) { 'Tuesday' } # => 'Tuesday'
207
+ # cache.fetch('today', force: true) # => ArgumentError
208
+ #
209
+ # The `:force` option is useful when you're calling some other method to
210
+ # ask whether you should force a cache write. Otherwise, it's clearer to
211
+ # just call `Cache#write`.
205
212
  #
206
213
  # Setting <tt>:compress</tt> will store a large cache entry set by the call
207
214
  # in a compressed format.
@@ -292,6 +299,8 @@ module ActiveSupport
292
299
  else
293
300
  save_block_result_to_cache(name, options) { |_name| yield _name }
294
301
  end
302
+ elsif options && options[:force]
303
+ raise ArgumentError, 'Missing block: Calling `Cache#fetch` with `force: true` requires a block.'
295
304
  else
296
305
  read(name, options)
297
306
  end
@@ -323,7 +332,7 @@ module ActiveSupport
323
332
  end
324
333
  end
325
334
 
326
- # Read multiple values at once from the cache. Options can be passed
335
+ # Reads multiple values at once from the cache. Options can be passed
327
336
  # in the last argument.
328
337
  #
329
338
  # Some cache implementation may optimize this method.
@@ -413,7 +422,7 @@ module ActiveSupport
413
422
  end
414
423
  end
415
424
 
416
- # Delete all entries with keys matching the pattern.
425
+ # Deletes all entries with keys matching the pattern.
417
426
  #
418
427
  # Options are passed to the underlying cache implementation.
419
428
  #
@@ -422,7 +431,7 @@ module ActiveSupport
422
431
  raise NotImplementedError.new("#{self.class.name} does not support delete_matched")
423
432
  end
424
433
 
425
- # Increment an integer value in the cache.
434
+ # Increments an integer value in the cache.
426
435
  #
427
436
  # Options are passed to the underlying cache implementation.
428
437
  #
@@ -431,7 +440,7 @@ module ActiveSupport
431
440
  raise NotImplementedError.new("#{self.class.name} does not support increment")
432
441
  end
433
442
 
434
- # Decrement an integer value in the cache.
443
+ # Decrements an integer value in the cache.
435
444
  #
436
445
  # Options are passed to the underlying cache implementation.
437
446
  #
@@ -440,7 +449,7 @@ module ActiveSupport
440
449
  raise NotImplementedError.new("#{self.class.name} does not support decrement")
441
450
  end
442
451
 
443
- # Cleanup the cache by removing expired entries.
452
+ # Cleanups the cache by removing expired entries.
444
453
  #
445
454
  # Options are passed to the underlying cache implementation.
446
455
  #
@@ -449,7 +458,7 @@ module ActiveSupport
449
458
  raise NotImplementedError.new("#{self.class.name} does not support cleanup")
450
459
  end
451
460
 
452
- # Clear the entire cache. Be careful with this method since it could
461
+ # Clears the entire cache. Be careful with this method since it could
453
462
  # affect other processes if shared cache is being used.
454
463
  #
455
464
  # The options hash is passed to the underlying cache implementation.
@@ -460,7 +469,7 @@ module ActiveSupport
460
469
  end
461
470
 
462
471
  protected
463
- # Add the namespace defined in the options to a pattern designed to
472
+ # Adds the namespace defined in the options to a pattern designed to
464
473
  # match keys. Implementations that support delete_matched should call
465
474
  # this method to translate a pattern that matches names into one that
466
475
  # matches namespaced keys.
@@ -479,26 +488,26 @@ module ActiveSupport
479
488
  end
480
489
  end
481
490
 
482
- # Read an entry from the cache implementation. Subclasses must implement
491
+ # Reads an entry from the cache implementation. Subclasses must implement
483
492
  # this method.
484
493
  def read_entry(key, options) # :nodoc:
485
494
  raise NotImplementedError.new
486
495
  end
487
496
 
488
- # Write an entry to the cache implementation. Subclasses must implement
497
+ # Writes an entry to the cache implementation. Subclasses must implement
489
498
  # this method.
490
499
  def write_entry(key, entry, options) # :nodoc:
491
500
  raise NotImplementedError.new
492
501
  end
493
502
 
494
- # Delete an entry from the cache implementation. Subclasses must
503
+ # Deletes an entry from the cache implementation. Subclasses must
495
504
  # implement this method.
496
505
  def delete_entry(key, options) # :nodoc:
497
506
  raise NotImplementedError.new
498
507
  end
499
508
 
500
509
  private
501
- # Merge the default options with ones specific to a method call.
510
+ # Merges the default options with ones specific to a method call.
502
511
  def merged_options(call_options) # :nodoc:
503
512
  if call_options
504
513
  options.merge(call_options)
@@ -507,7 +516,7 @@ module ActiveSupport
507
516
  end
508
517
  end
509
518
 
510
- # Expand key to be a consistent string value. Invoke +cache_key+ if
519
+ # Expands key to be a consistent string value. Invokes +cache_key+ if
511
520
  # object responds to +cache_key+. Otherwise, +to_param+ method will be
512
521
  # called. If the key is a Hash, then keys will be sorted alphabetically.
513
522
  def expanded_key(key) # :nodoc:
@@ -527,7 +536,7 @@ module ActiveSupport
527
536
  key.to_param
528
537
  end
529
538
 
530
- # Prefix a key with the namespace. Namespace and key will be delimited
539
+ # Prefixes a key with the namespace. Namespace and key will be delimited
531
540
  # with a colon.
532
541
  def normalize_key(key, options)
533
542
  key = expanded_key(key)
@@ -575,12 +584,12 @@ module ActiveSupport
575
584
  end
576
585
 
577
586
  def get_entry_value(entry, name, options)
578
- instrument(:fetch_hit, name, options) { |payload| }
587
+ instrument(:fetch_hit, name, options) { }
579
588
  entry.value
580
589
  end
581
590
 
582
591
  def save_block_result_to_cache(name, options)
583
- result = instrument(:generate, name, options) do |payload|
592
+ result = instrument(:generate, name, options) do
584
593
  yield(name)
585
594
  end
586
595
 
@@ -598,7 +607,7 @@ module ActiveSupport
598
607
  class Entry # :nodoc:
599
608
  DEFAULT_COMPRESS_LIMIT = 16.kilobytes
600
609
 
601
- # Create a new cache entry for the specified value. Options supported are
610
+ # Creates a new cache entry for the specified value. Options supported are
602
611
  # +:compress+, +:compress_threshold+, and +:expires_in+.
603
612
  def initialize(value, options = {})
604
613
  if should_compress?(value, options)
@@ -617,7 +626,7 @@ module ActiveSupport
617
626
  compressed? ? uncompress(@value) : @value
618
627
  end
619
628
 
620
- # Check if the entry is expired. The +expires_in+ parameter can override
629
+ # Checks if the entry is expired. The +expires_in+ parameter can override
621
630
  # the value set when the entry was created.
622
631
  def expired?
623
632
  @expires_in && @created_at + @expires_in <= Time.now.to_f
@@ -652,7 +661,7 @@ module ActiveSupport
652
661
  end
653
662
  end
654
663
 
655
- # Duplicate the value in a class. This is used by cache implementations that don't natively
664
+ # Duplicates the value in a class. This is used by cache implementations that don't natively
656
665
  # serialize entries to protect against accidental cache modifications.
657
666
  def dup_value!
658
667
  if @value && !compressed? && !(@value.is_a?(Numeric) || @value == true || @value == false)