activesupport 4.0.0 → 4.0.1.rc1

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: f245ce1f4a2b4ef8b365844871de9379d23117b0
4
- data.tar.gz: f107b6936aa6763ba2274bd98fd92e573fc49e84
3
+ metadata.gz: 265c86601dacd7587bafdf8326eb8b75c9fba093
4
+ data.tar.gz: 2fd091baed9280aa6a6d373b822ab04576a1a386
5
5
  SHA512:
6
- metadata.gz: 39ba79acc5ca41a56c59b54359fdbaa8123301d2812b39285f8b99614d94998d43a0436d5fba6e4002bf172019e2eeb38eb2baa73e803cb987294eb599891b2e
7
- data.tar.gz: 73dd55afe205d557d98a6d07488ac5cb393a2c6892205416a9dbff867cdc0923b193f334be3d126c39d933cea8a90f4e7a693b90037ea5538d552e3dd4f04965
6
+ metadata.gz: 90be8ce9b649b02606385af6d00a24682bd46e1a1d63a20598dff5a19cbb9146ea14c5473e9ee2e15501def086ffa35a365640e5ac23721f95ed31a1e50fa357
7
+ data.tar.gz: 9b3f8a27d3b08ad0fafbe607a9a016c3f9aaf0bb96374ead886aa9f1d7bc3467a553e5558b275440d9b94ca63d78b4f03d5be692affe68d3952c1c40a176c7d2
@@ -1,3 +1,76 @@
1
+ ## Rails 4.0.1.rc1 (October 17, 2013) ##
2
+
3
+ * Disable the ability to iterate over Range of AS::TimeWithZone
4
+ due to significant performance issues.
5
+
6
+ *Bogdan Gusiev*
7
+
8
+ * Fix `ActiveSupport::Cache::FileStore#cleanup` to no longer rely on missing `each_key` method.
9
+
10
+ *Murray Steele*
11
+
12
+ * Ensure that autoloaded constants in all-caps nestings are marked as
13
+ autoloaded.
14
+
15
+ *Simon Coffey*
16
+
17
+ * Adds a new deprecation behaviour that raises an exception. Throwing this
18
+ line into `config/environments/development.rb`:
19
+
20
+ ActiveSupport::Deprecation.behavior = :raise
21
+
22
+ will cause the application to raise an `ActiveSupport::DeprecationException`
23
+ on deprecations.
24
+
25
+ Use this for aggressive deprecation cleanups.
26
+
27
+ *Xavier Noria*
28
+
29
+ * Improve `ActiveSupport::Cache::MemoryStore` cache size calculation.
30
+ The memory used by a key/entry pair is calculated via `#cached_size`:
31
+
32
+ def cached_size(key, entry)
33
+ key.to_s.bytesize + entry.size + PER_ENTRY_OVERHEAD
34
+ end
35
+
36
+ The value of `PER_ENTRY_OVERHEAD` is 240 bytes based on an [empirical
37
+ estimation](https://gist.github.com/ssimeonov/6047200) for 64-bit MRI on
38
+ 1.9.3 and 2.0.
39
+
40
+ Fixes #11512.
41
+
42
+ *Simeon Simeonov*
43
+
44
+ * Only raise `Module::DelegationError` if it's the source of the exception.
45
+
46
+ Fixes #10559.
47
+
48
+ * Add `DateTime#usec` and `DateTime#nsec` so that `ActiveSupport::TimeWithZone` keeps
49
+ sub-second resolution when wrapping a `DateTime` value.
50
+
51
+ Fixes #10855.
52
+
53
+ *Andrew White*
54
+
55
+ * Make `Time.at_with_coercion` retain the second fraction and return local time.
56
+
57
+ Fixes #11350.
58
+
59
+ *Neer Friedman*, *Andrew White*
60
+
61
+ * Fix return value from `BacktraceCleaner#noise` when the cleaner is configured
62
+ with multiple silencers.
63
+
64
+ Fixes #11030.
65
+
66
+ *Mark J. Titorenko*
67
+
68
+ * Fix `ActiveSupport::Dependencies::Loadable#load_dependency` calling
69
+ `#blame_file!` on Exceptions that do not have the Blamable mixin
70
+
71
+ *Andrew Kreiling*
72
+
73
+
1
74
  ## Rails 4.0.0 (June 25, 2013) ##
2
75
 
3
76
  * Override `Time.at` to support the passing of Time-like values when called with a single argument.
@@ -14,7 +14,7 @@ The latest version of Active Support can be installed with RubyGems:
14
14
 
15
15
  Source code can be downloaded as part of the Rails project on GitHub:
16
16
 
17
- * https://github.com/rails/rails/tree/master/activesupport
17
+ * https://github.com/rails/rails/tree/4-0-stable/activesupport
18
18
 
19
19
 
20
20
  == License
@@ -97,11 +97,7 @@ module ActiveSupport
97
97
  end
98
98
 
99
99
  def noise(backtrace)
100
- @silencers.each do |s|
101
- backtrace = backtrace.select { |line| s.call(line) }
102
- end
103
-
104
- backtrace
100
+ backtrace - silence(backtrace)
105
101
  end
106
102
  end
107
103
  end
@@ -234,7 +234,7 @@ module ActiveSupport
234
234
  # bump the cache expiration time by the value set in <tt>:race_condition_ttl</tt>.
235
235
  # Yes, this process is extending the time for a stale value by another few
236
236
  # seconds. Because of extended life of the previous cache, other processes
237
- # will continue to use slightly stale data for a just a big longer. In the
237
+ # will continue to use slightly stale data for a just a bit longer. In the
238
238
  # meantime that first process will go ahead and will write into cache the
239
239
  # new value. After that all the processes will start getting new value.
240
240
  # The key is to keep <tt>:race_condition_ttl</tt> small.
@@ -29,7 +29,8 @@ module ActiveSupport
29
29
 
30
30
  def cleanup(options = nil)
31
31
  options = merged_options(options)
32
- each_key(options) do |key|
32
+ search_dir(cache_path) do |fname|
33
+ key = file_path_key(fname)
33
34
  entry = read_entry(key, options)
34
35
  delete_entry(key, options) if entry && entry.expired?
35
36
  end
@@ -122,6 +122,13 @@ module ActiveSupport
122
122
  end
123
123
 
124
124
  protected
125
+
126
+ PER_ENTRY_OVERHEAD = 240
127
+
128
+ def cached_size(key, entry)
129
+ key.to_s.bytesize + entry.size + PER_ENTRY_OVERHEAD
130
+ end
131
+
125
132
  def read_entry(key, options) # :nodoc:
126
133
  entry = @data[key]
127
134
  synchronize do
@@ -139,8 +146,11 @@ module ActiveSupport
139
146
  synchronize do
140
147
  old_entry = @data[key]
141
148
  return false if @data.key?(key) && options[:unless_exist]
142
- @cache_size -= old_entry.size if old_entry
143
- @cache_size += entry.size
149
+ if old_entry
150
+ @cache_size -= (old_entry.size - entry.size)
151
+ else
152
+ @cache_size += cached_size(key, entry)
153
+ end
144
154
  @key_access[key] = Time.now.to_f
145
155
  @data[key] = entry
146
156
  prune(@max_size * 0.75, @max_prune_time) if @cache_size > @max_size
@@ -152,7 +162,7 @@ module ActiveSupport
152
162
  synchronize do
153
163
  @key_access.delete(key)
154
164
  entry = @data.delete(key)
155
- @cache_size -= entry.size if entry
165
+ @cache_size -= cached_size(key, entry) if entry
156
166
  !!entry
157
167
  end
158
168
  end
@@ -418,7 +418,7 @@ module ActiveSupport
418
418
  #
419
419
  # set_callback :save, :before_meth
420
420
  #
421
- # The callback can specified as a symbol naming an instance method; as a
421
+ # The callback can be specified as a symbol naming an instance method; as a
422
422
  # proc, lambda, or block; as a string to be instance evaluated; or as an
423
423
  # object that responds to a certain method determined by the <tt>:scope</tt>
424
424
  # argument to +define_callback+.
@@ -1,3 +1,4 @@
1
+ require 'date'
1
2
  require 'active_support/core_ext/object/acts_like'
2
3
 
3
4
  class DateTime
@@ -79,6 +79,16 @@ class DateTime
79
79
  seconds_since_unix_epoch.to_i
80
80
  end
81
81
 
82
+ # Returns the fraction of a second as microseconds
83
+ def usec
84
+ (sec_fraction * 1_000_000).to_i
85
+ end
86
+
87
+ # Returns the fraction of a second as nanoseconds
88
+ def nsec
89
+ (sec_fraction * 1_000_000_000).to_i
90
+ end
91
+
82
92
  private
83
93
 
84
94
  def offset_in_seconds
@@ -179,16 +179,17 @@ class Module
179
179
  exception = %(raise "#{self}##{method_prefix}#{method} delegated to #{to}.#{method}, but #{to} is nil: \#{self.inspect}")
180
180
 
181
181
  module_eval(<<-EOS, file, line - 2)
182
- def #{method_prefix}#{method}(#{definition}) # def customer_name(*args, &block)
183
- _ = #{to} # _ = client
184
- _.#{method}(#{definition}) # _.name(*args, &block)
185
- rescue NoMethodError # rescue NoMethodError
186
- if _.nil? # if _.nil?
187
- #{exception} # # add helpful message to the exception
188
- else # else
189
- raise # raise
190
- end # end
191
- end # end
182
+ def #{method_prefix}#{method}(#{definition}) # def customer_name(*args, &block)
183
+ _ = #{to} # _ = client
184
+ _.#{method}(#{definition}) # _.name(*args, &block)
185
+ rescue NoMethodError => e # rescue NoMethodError => e
186
+ location = "%s:%d:in `%s'" % [__FILE__, __LINE__ - 2, '#{method_prefix}#{method}'] # location = "%s:%d:in `%s'" % [__FILE__, __LINE__ - 2, 'customer_name']
187
+ if _.nil? && e.backtrace.first == location # if _.nil? && e.backtrace.first == location
188
+ #{exception} # # add helpful message to the exception
189
+ else # else
190
+ raise # raise
191
+ end # end
192
+ end # end
192
193
  EOS
193
194
  end
194
195
  end
@@ -1,3 +1,4 @@
1
1
  require 'active_support/core_ext/range/conversions'
2
2
  require 'active_support/core_ext/range/include_range'
3
3
  require 'active_support/core_ext/range/overlaps'
4
+ require 'active_support/core_ext/range/each'
@@ -0,0 +1,24 @@
1
+ require 'active_support/core_ext/module/aliasing'
2
+ require 'active_support/core_ext/object/acts_like'
3
+
4
+ class Range #:nodoc:
5
+
6
+ def each_with_time_with_zone(&block)
7
+ ensure_iteration_allowed
8
+ each_without_time_with_zone(&block)
9
+ end
10
+ alias_method_chain :each, :time_with_zone
11
+
12
+ def step_with_time_with_zone(n = 1, &block)
13
+ ensure_iteration_allowed
14
+ step_without_time_with_zone(n, &block)
15
+ end
16
+ alias_method_chain :step, :time_with_zone
17
+
18
+ private
19
+ def ensure_iteration_allowed
20
+ if first.acts_like?(:time)
21
+ raise TypeError, "can't iterate from #{first.class}"
22
+ end
23
+ end
24
+ end
@@ -23,14 +23,14 @@ class Thread
23
23
  # for the fiber local. The fiber is executed in the same thread, so the
24
24
  # thread local values are available.
25
25
  def thread_variable_get(key)
26
- locals[key.to_sym]
26
+ _locals[key.to_sym]
27
27
  end
28
28
 
29
29
  # Sets a thread local with +key+ to +value+. Note that these are local to
30
30
  # threads, and not to fibers. Please see Thread#thread_variable_get for
31
31
  # more information.
32
32
  def thread_variable_set(key, value)
33
- locals[key.to_sym] = value
33
+ _locals[key.to_sym] = value
34
34
  end
35
35
 
36
36
  # Returns an an array of the names of the thread-local variables (as Symbols).
@@ -45,7 +45,7 @@ class Thread
45
45
  # Note that these are not fiber local variables. Please see Thread#thread_variable_get
46
46
  # for more details.
47
47
  def thread_variables
48
- locals.keys
48
+ _locals.keys
49
49
  end
50
50
 
51
51
  # Returns <tt>true</tt> if the given string (or symbol) exists as a
@@ -59,16 +59,21 @@ class Thread
59
59
  # Note that these are not fiber local variables. Please see Thread#thread_variable_get
60
60
  # for more details.
61
61
  def thread_variable?(key)
62
- locals.has_key?(key.to_sym)
62
+ _locals.has_key?(key.to_sym)
63
+ end
64
+
65
+ def freeze
66
+ _locals.freeze
67
+ super
63
68
  end
64
69
 
65
70
  private
66
71
 
67
- def locals
68
- if defined?(@locals)
69
- @locals
72
+ def _locals
73
+ if defined?(@_locals)
74
+ @_locals
70
75
  else
71
- LOCK.synchronize { @locals ||= {} }
76
+ LOCK.synchronize { @_locals ||= {} }
72
77
  end
73
78
  end
74
79
  end unless Thread.instance_methods.include?(:thread_variable_set)
@@ -69,10 +69,15 @@ class Time
69
69
  # Layers additional behavior on Time.at so that ActiveSupport::TimeWithZone and DateTime
70
70
  # instances can be used when called with a single argument
71
71
  def at_with_coercion(*args)
72
- if args.size == 1 && args.first.acts_like?(:time)
73
- at_without_coercion(args.first.to_i)
72
+ return at_without_coercion(*args) if args.size != 1
73
+
74
+ # Time.at can be called with a time or numerical value
75
+ time_or_number = args.first
76
+
77
+ if time_or_number.is_a?(ActiveSupport::TimeWithZone) || time_or_number.is_a?(DateTime)
78
+ at_without_coercion(time_or_number.to_f).getlocal
74
79
  else
75
- at_without_coercion(*args)
80
+ at_without_coercion(time_or_number)
76
81
  end
77
82
  end
78
83
  alias_method :at_without_coercion, :at
@@ -8,6 +8,7 @@ require 'active_support/core_ext/module/introspection'
8
8
  require 'active_support/core_ext/module/anonymous'
9
9
  require 'active_support/core_ext/module/qualified_const'
10
10
  require 'active_support/core_ext/object/blank'
11
+ require 'active_support/core_ext/kernel/reporting'
11
12
  require 'active_support/core_ext/load_error'
12
13
  require 'active_support/core_ext/name_error'
13
14
  require 'active_support/core_ext/string/starts_ends_with'
@@ -213,7 +214,7 @@ module ActiveSupport #:nodoc:
213
214
  yield
214
215
  end
215
216
  rescue Exception => exception # errors from loading file
216
- exception.blame_file! file
217
+ exception.blame_file! file if exception.respond_to? :blame_file!
217
218
  raise
218
219
  end
219
220
 
@@ -459,7 +460,7 @@ module ActiveSupport #:nodoc:
459
460
  if loaded.include?(expanded)
460
461
  raise "Circular dependency detected while autoloading constant #{qualified_name}"
461
462
  else
462
- require_or_load(expanded)
463
+ require_or_load(expanded, qualified_name)
463
464
  raise LoadError, "Unable to autoload constant #{qualified_name}, expected #{file_path} to define it" unless from_mod.const_defined?(const_name, false)
464
465
  return from_mod.const_get(const_name)
465
466
  end
@@ -1,14 +1,24 @@
1
1
  require "active_support/notifications"
2
2
 
3
3
  module ActiveSupport
4
+ class DeprecationException < StandardError
5
+ end
6
+
4
7
  class Deprecation
5
8
  # Default warning behaviors per Rails.env.
6
9
  DEFAULT_BEHAVIORS = {
7
- :stderr => Proc.new { |message, callstack|
10
+ raise: ->(message, callstack) {
11
+ e = DeprecationException.new(message)
12
+ e.set_backtrace(callstack)
13
+ raise e
14
+ },
15
+
16
+ stderr: ->(message, callstack) {
8
17
  $stderr.puts(message)
9
18
  $stderr.puts callstack.join("\n ") if debug
10
19
  },
11
- :log => Proc.new { |message, callstack|
20
+
21
+ log: ->(message, callstack) {
12
22
  logger =
13
23
  if defined?(Rails) && Rails.logger
14
24
  Rails.logger
@@ -19,11 +29,13 @@ module ActiveSupport
19
29
  logger.warn message
20
30
  logger.debug callstack.join("\n ") if debug
21
31
  },
22
- :notify => Proc.new { |message, callstack|
32
+
33
+ notify: ->(message, callstack) {
23
34
  ActiveSupport::Notifications.instrument("deprecation.rails",
24
35
  :message => message, :callstack => callstack)
25
36
  },
26
- :silence => Proc.new { |message, callstack| }
37
+
38
+ silence: ->(message, callstack) {},
27
39
  }
28
40
 
29
41
  module Behavior
@@ -40,6 +52,7 @@ module ActiveSupport
40
52
  #
41
53
  # Available behaviors:
42
54
  #
55
+ # [+raise+] Raise <tt>ActiveSupport::DeprecationException</tt>.
43
56
  # [+stderr+] Log all deprecation warnings to +$stderr+.
44
57
  # [+log+] Log all deprecation warnings to +Rails.logger+.
45
58
  # [+notify+] Use +ActiveSupport::Notifications+ to notify +deprecation.rails+.
@@ -52,7 +65,7 @@ module ActiveSupport
52
65
  # ActiveSupport::Deprecation.behavior = :stderr
53
66
  # ActiveSupport::Deprecation.behavior = [:stderr, :log]
54
67
  # ActiveSupport::Deprecation.behavior = MyCustomHandler
55
- # ActiveSupport::Deprecation.behavior = proc { |message, callstack|
68
+ # ActiveSupport::Deprecation.behavior = ->(message, callstack) {
56
69
  # # custom stuff
57
70
  # }
58
71
  def behavior=(behavior)
@@ -145,7 +145,7 @@ module ActiveSupport
145
145
  ncp << (HANGUL_TBASE + tindex) unless tindex == 0
146
146
  decomposed.concat ncp
147
147
  # if the codepoint is decomposable in with the current decomposition type
148
- elsif (ncp = database.codepoints[cp].decomp_mapping) and (!database.codepoints[cp].decomp_type || type == :compatability)
148
+ elsif (ncp = database.codepoints[cp].decomp_mapping) and (!database.codepoints[cp].decomp_type || type == :compatibility)
149
149
  decomposed.concat decompose(type, ncp.dup)
150
150
  else
151
151
  decomposed << cp
@@ -283,9 +283,9 @@ module ActiveSupport
283
283
  when :c
284
284
  compose(reorder_characters(decompose(:canonical, codepoints)))
285
285
  when :kd
286
- reorder_characters(decompose(:compatability, codepoints))
286
+ reorder_characters(decompose(:compatibility, codepoints))
287
287
  when :kc
288
- compose(reorder_characters(decompose(:compatability, codepoints)))
288
+ compose(reorder_characters(decompose(:compatibility, codepoints)))
289
289
  else
290
290
  raise ArgumentError, "#{form} is not a valid normalization variant", caller
291
291
  end.pack('U*')
@@ -244,14 +244,14 @@ module ActiveSupport
244
244
  #
245
245
  # ==== Examples
246
246
  #
247
- # number_to_percentage(100) # => 100.000%
248
- # number_to_percentage('98') # => 98.000%
249
- # number_to_percentage(100, precision: 0) # => 100%
250
- # number_to_percentage(1000, delimiter: '.', separator: ,') # => 1.000,000%
251
- # number_to_percentage(302.24398923423, precision: 5) # => 302.24399%
252
- # number_to_percentage(1000, locale: :fr) # => 1 000,000%
253
- # number_to_percentage('98a') # => 98a%
254
- # number_to_percentage(100, format: '%n %') # => 100 %
247
+ # number_to_percentage(100) # => 100.000%
248
+ # number_to_percentage('98') # => 98.000%
249
+ # number_to_percentage(100, precision: 0) # => 100%
250
+ # number_to_percentage(1000, delimiter: '.', separator: ',') # => 1.000,000%
251
+ # number_to_percentage(302.24398923423, precision: 5) # => 302.24399%
252
+ # number_to_percentage(1000, locale: :fr) # => 1 000,000%
253
+ # number_to_percentage('98a') # => 98a%
254
+ # number_to_percentage(100, format: '%n %') # => 100 %
255
255
  def number_to_percentage(number, options = {})
256
256
  return unless number
257
257
  options = options.symbolize_keys
@@ -460,7 +460,7 @@ module ActiveSupport
460
460
  # See <tt>number_to_human_size</tt> if you want to print a file
461
461
  # size.
462
462
  #
463
- # You can also define you own unit-quantifier names if you want
463
+ # You can also define your own unit-quantifier names if you want
464
464
  # to use other decimal units (eg.: 1500 becomes "1.5
465
465
  # kilometers", 0.150 becomes "150 milliliters", etc). You may
466
466
  # define a wide range of unit quantifiers, even fractional ones
@@ -1,6 +1,5 @@
1
1
  require 'active_support/concern'
2
2
  require 'active_support/core_ext/class/attribute'
3
- require 'active_support/core_ext/proc'
4
3
  require 'active_support/core_ext/string/inflections'
5
4
  require 'active_support/core_ext/array/extract_options'
6
5
 
@@ -292,7 +292,7 @@ module ActiveSupport
292
292
  end
293
293
  end
294
294
 
295
- %w(year mon month day mday wday yday hour min sec to_date).each do |method_name|
295
+ %w(year mon month day mday wday yday hour min sec usec nsec to_date).each do |method_name|
296
296
  class_eval <<-EOV, __FILE__, __LINE__ + 1
297
297
  def #{method_name} # def month
298
298
  time.#{method_name} # time.month
@@ -300,10 +300,6 @@ module ActiveSupport
300
300
  EOV
301
301
  end
302
302
 
303
- def usec
304
- time.respond_to?(:usec) ? time.usec : 0
305
- end
306
-
307
303
  def to_a
308
304
  [time.sec, time.min, time.hour, time.day, time.mon, time.year, time.wday, time.yday, dst?, zone]
309
305
  end
@@ -1,7 +1,7 @@
1
1
  module ActiveSupport
2
2
  # Returns the version of the currently loaded ActiveSupport as a Gem::Version
3
3
  def self.version
4
- Gem::Version.new "4.0.0"
4
+ Gem::Version.new "4.0.1.rc1"
5
5
  end
6
6
 
7
7
  module VERSION #:nodoc:
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.0.0
4
+ version: 4.0.1.rc1
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: 2013-06-25 00:00:00.000000000 Z
11
+ date: 2013-10-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: i18n
@@ -195,6 +195,7 @@ files:
195
195
  - lib/active_support/core_ext/object.rb
196
196
  - lib/active_support/core_ext/proc.rb
197
197
  - lib/active_support/core_ext/range/conversions.rb
198
+ - lib/active_support/core_ext/range/each.rb
198
199
  - lib/active_support/core_ext/range/include_range.rb
199
200
  - lib/active_support/core_ext/range/overlaps.rb
200
201
  - lib/active_support/core_ext/range.rb
@@ -316,12 +317,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
316
317
  version: 1.9.3
317
318
  required_rubygems_version: !ruby/object:Gem::Requirement
318
319
  requirements:
319
- - - '>='
320
+ - - '>'
320
321
  - !ruby/object:Gem::Version
321
- version: '0'
322
+ version: 1.3.1
322
323
  requirements: []
323
324
  rubyforge_project:
324
- rubygems_version: 2.0.2
325
+ rubygems_version: 2.0.6
325
326
  signing_key:
326
327
  specification_version: 4
327
328
  summary: A toolkit of support libraries and Ruby core extensions extracted from the