activesupport 3.1.0.rc5 → 3.1.0.rc6

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.

data/CHANGELOG CHANGED
@@ -1,5 +1,7 @@
1
1
  *Rails 3.1.0 (unreleased)*
2
2
 
3
+ * Using Module#delegate to delegate to non-public methods is deprecated [Jon Leighton]
4
+
3
5
  * ActiveSupport::Dependencies now raises NameError if it finds an existing constant in load_missing_constant. This better reflects the nature of the error which is usually caused by calling constantize on a nested constant. [Andrew White]
4
6
 
5
7
  * Deprecated ActiveSupport::SecureRandom in favour of SecureRandom from the standard library [Jon Leighton]
@@ -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/master/activesupport
18
18
 
19
19
 
20
20
  == License
@@ -345,7 +345,7 @@ module ActiveSupport
345
345
  entry = read_entry(key, options)
346
346
  if entry
347
347
  if entry.expired?
348
- delete_entry(key)
348
+ delete_entry(key, options)
349
349
  else
350
350
  results[name] = entry.value
351
351
  end
@@ -30,6 +30,8 @@ class Hash
30
30
  omit
31
31
  end
32
32
 
33
+ # Removes and returns the key/value pairs matching the given keys.
34
+ # {:a => 1, :b => 2, :c => 3, :d => 4}.extract!(:a, :b) # => {:a => 1, :b => 2}
33
35
  def extract!(*keys)
34
36
  result = {}
35
37
  keys.each {|key| result[key] = delete(key) }
@@ -1,4 +1,6 @@
1
1
  require "active_support/core_ext/module/remove_method"
2
+ require 'active_support/core_ext/kernel/singleton_class'
3
+ require 'active_support/deprecation'
2
4
 
3
5
  class Module
4
6
  # Provides a delegate class method to easily expose contained objects' methods
@@ -126,16 +128,32 @@ class Module
126
128
  %(raise "#{self}##{prefix}#{method} delegated to #{to}.#{method}, but #{to} is nil: \#{self.inspect}")
127
129
  end
128
130
 
129
- module_eval(<<-EOS, file, line - 5)
130
- def #{prefix}#{method}(*args, &block) # def customer_name(*args, &block)
131
- #{to}.__send__(#{method.inspect}, *args, &block) # client.__send__(:name, *args, &block)
132
- rescue NoMethodError # rescue NoMethodError
133
- if #{to}.nil? # if client.nil?
134
- #{on_nil} # return # depends on :allow_nil
135
- else # else
136
- raise # raise
137
- end # end
138
- end # end
131
+ module_eval(<<-EOS, file, line - 4)
132
+ def #{prefix}#{method}(*args, &block) # def customer_name(*args, &block)
133
+ to = #{to} # to = client
134
+ #
135
+ begin # begin
136
+ result = to.__send__(#{method.inspect}, *args, &block) # result = to.__send__(:name, *args, &block)
137
+ rescue NoMethodError # rescue NoMethodError
138
+ if to.nil? # if to.nil?
139
+ #{on_nil} # return # depends on :allow_nil
140
+ else # else
141
+ raise # raise
142
+ end # end
143
+ end # end
144
+ #
145
+ klass = to.singleton_methods.any? ? to.singleton_class : to.class # klass = to.singleton_methods.any? ? to.singleton_class : to.class
146
+ unless klass.public_method_defined?(#{method.inspect}) # unless klass.public_method_defined?(:name)
147
+ ActiveSupport::Deprecation.warn( # ActiveSupport::Deprecation.warn(
148
+ "Using Module#delegate to delegate to non-public methods is " + # "..." +
149
+ "deprecated. Please declare your methods as public if they " + # "..." +
150
+ "are going to accessed from other classes.", # "...",
151
+ [#{"#{file}:#{line}".inspect}] # ["app/models/firm.rb:16"]
152
+ ) # )
153
+ end # end
154
+ #
155
+ result # result
156
+ end # end
139
157
  EOS
140
158
  end
141
159
  end
@@ -1,11 +1,16 @@
1
1
  class Module
2
2
  def remove_possible_method(method)
3
- remove_method(method)
3
+ if method_defined?(method) || private_method_defined?(method)
4
+ remove_method(method)
5
+ end
4
6
  rescue NameError
7
+ # If the requested method is defined on a superclass or included module,
8
+ # method_defined? returns true but remove_method throws a NameError.
9
+ # Ignore this.
5
10
  end
6
11
 
7
12
  def redefine_method(method, &block)
8
13
  remove_possible_method(method)
9
14
  define_method(method, &block)
10
15
  end
11
- end
16
+ end
@@ -20,7 +20,7 @@ class ERB
20
20
  if s.html_safe?
21
21
  s
22
22
  else
23
- s.gsub(/[&"><]/) { |special| HTML_ESCAPE[special] }.html_safe
23
+ s.to_s.gsub(/&/, "&amp;").gsub(/\"/, "&quot;").gsub(/>/, "&gt;").gsub(/</, "&lt;").html_safe
24
24
  end
25
25
  end
26
26
 
@@ -1,5 +1,6 @@
1
1
  require 'active_support/duration'
2
2
  require 'active_support/core_ext/time/zones'
3
+ require 'active_support/core_ext/time/conversions'
3
4
 
4
5
  class Time
5
6
  COMMON_YEAR_DAYS_IN_MONTH = [nil, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
@@ -479,10 +479,6 @@ module ActiveSupport #:nodoc:
479
479
  qualified_name = qualified_name_for from_mod, const_name
480
480
  path_suffix = qualified_name.underscore
481
481
 
482
- trace = caller.reject {|l| l =~ %r{#{Regexp.escape(__FILE__)}}}
483
- name_error = NameError.new("uninitialized constant #{qualified_name}")
484
- name_error.set_backtrace(trace)
485
-
486
482
  file_path = search_for_file(path_suffix)
487
483
 
488
484
  if file_path && ! loaded.include?(File.expand_path(file_path)) # We found a matching file to load
@@ -501,11 +497,12 @@ module ActiveSupport #:nodoc:
501
497
  return parent.const_missing(const_name)
502
498
  rescue NameError => e
503
499
  raise unless e.missing_name? qualified_name_for(parent, const_name)
504
- raise name_error
505
500
  end
506
- else
507
- raise name_error
508
501
  end
502
+
503
+ raise NameError,
504
+ "uninitialized constant #{qualified_name}",
505
+ caller.reject {|l| l.starts_with? __FILE__ }
509
506
  end
510
507
 
511
508
  # Remove the constants that have been autoloaded, and those that have been
@@ -1,5 +1,6 @@
1
1
  require 'zlib'
2
2
  require 'stringio'
3
+ require 'active_support/core_ext/string/encoding'
3
4
 
4
5
  module ActiveSupport
5
6
  # A convenient wrapper for the zlib standard library that allows compression/decompression of strings with gzip.
@@ -54,6 +54,7 @@ module ActiveSupport
54
54
  inflect.irregular('sex', 'sexes')
55
55
  inflect.irregular('move', 'moves')
56
56
  inflect.irregular('cow', 'kine')
57
+ inflect.irregular('zombie', 'zombies')
57
58
 
58
59
  inflect.uncountable(%w(equipment information rice money species series fish sheep jeans))
59
60
  end
@@ -1,5 +1,3 @@
1
- require 'active_support/core_ext/module/delegation'
2
-
3
1
  module ActiveSupport
4
2
  # Notifications provides an instrumentation API for Ruby. To instrument an
5
3
  # action in Ruby you just need to do:
@@ -45,15 +45,17 @@ module ActiveSupport
45
45
  # post :delete, :id => ...
46
46
  # end
47
47
  def assert_difference(expression, difference = 1, message = nil, &block)
48
- exps = Array.wrap(expression).map { |e|
48
+ expressions = Array.wrap expression
49
+
50
+ exps = expressions.map { |e|
49
51
  e.respond_to?(:call) ? e : lambda { eval(e, block.binding) }
50
52
  }
51
53
  before = exps.map { |e| e.call }
52
54
 
53
55
  yield
54
56
 
55
- exps.each_with_index do |e, i|
56
- error = "#{e.inspect} didn't change by #{difference}"
57
+ expressions.zip(exps).each_with_index do |(code, e), i|
58
+ error = "#{code.inspect} didn't change by #{difference}"
57
59
  error = "#{message}.\n#{error}" if message
58
60
  assert_equal(before[i] + difference, e.call, error)
59
61
  end
@@ -195,12 +195,8 @@ module ActiveSupport
195
195
  # (GMT). Seconds were chosen as the offset unit because that is the unit that
196
196
  # Ruby uses to represent time zone offsets (see Time#utc_offset).
197
197
  def initialize(name, utc_offset = nil, tzinfo = nil)
198
- begin
199
- require 'tzinfo'
200
- rescue LoadError => e
201
- $stderr.puts "You don't have tzinfo installed in your application. Please add it to your Gemfile and run bundle install"
202
- raise e
203
- end
198
+ self.class.send(:require_tzinfo)
199
+
204
200
  @name = name
205
201
  @utc_offset = utc_offset
206
202
  @tzinfo = tzinfo || TimeZone.find_tzinfo(name)
@@ -339,7 +335,12 @@ module ActiveSupport
339
335
  end
340
336
 
341
337
  def zones_map
342
- @zones_map ||= Hash[MAPPING.map { |place, _| [place, create(place)] }]
338
+ @zones_map ||= begin
339
+ new_zones_names = MAPPING.keys - lazy_zones_map.keys
340
+ new_zones = Hash[new_zones_names.map { |place| [place, create(place)] }]
341
+
342
+ lazy_zones_map.merge(new_zones)
343
+ end
343
344
  end
344
345
 
345
346
  # Locate a specific time zone object. If the argument is a string, it
@@ -351,7 +352,7 @@ module ActiveSupport
351
352
  case arg
352
353
  when String
353
354
  begin
354
- zones_map[arg] ||= lookup(arg).tap { |tz| tz.utc_offset }
355
+ lazy_zones_map[arg] ||= lookup(arg).tap { |tz| tz.utc_offset }
355
356
  rescue TZInfo::InvalidTimezoneIdentifier
356
357
  nil
357
358
  end
@@ -369,11 +370,28 @@ module ActiveSupport
369
370
  @us_zones ||= all.find_all { |z| z.name =~ /US|Arizona|Indiana|Hawaii|Alaska/ }
370
371
  end
371
372
 
373
+ protected
374
+
375
+ def require_tzinfo
376
+ require 'tzinfo'
377
+ rescue LoadError
378
+ $stderr.puts "You don't have tzinfo installed in your application. Please add it to your Gemfile and run bundle install"
379
+ raise
380
+ end
381
+
372
382
  private
373
383
 
374
384
  def lookup(name)
375
385
  (tzinfo = find_tzinfo(name)) && create(tzinfo.name.freeze)
376
386
  end
387
+
388
+ def lazy_zones_map
389
+ require_tzinfo
390
+
391
+ @lazy_zones_map ||= Hash.new do |hash, place|
392
+ hash[place] = create(place) if MAPPING.has_key?(place)
393
+ end
394
+ end
377
395
  end
378
396
  end
379
397
  end
@@ -3,7 +3,7 @@ module ActiveSupport
3
3
  MAJOR = 3
4
4
  MINOR = 1
5
5
  TINY = 0
6
- PRE = "rc5"
6
+ PRE = "rc6"
7
7
 
8
8
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
9
9
  end
metadata CHANGED
@@ -1,13 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activesupport
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: true
4
+ hash: 15424105
5
+ prerelease: 6
5
6
  segments:
6
7
  - 3
7
8
  - 1
8
9
  - 0
9
- - rc5
10
- version: 3.1.0.rc5
10
+ - rc
11
+ - 6
12
+ version: 3.1.0.rc6
11
13
  platform: ruby
12
14
  authors:
13
15
  - David Heinemeier Hansson
@@ -15,16 +17,17 @@ autorequire:
15
17
  bindir: bin
16
18
  cert_chain: []
17
19
 
18
- date: 2011-07-25 00:00:00 -07:00
19
- default_executable:
20
+ date: 2011-08-16 00:00:00 Z
20
21
  dependencies:
21
22
  - !ruby/object:Gem::Dependency
22
23
  name: multi_json
23
24
  prerelease: false
24
25
  requirement: &id001 !ruby/object:Gem::Requirement
26
+ none: false
25
27
  requirements:
26
28
  - - ~>
27
29
  - !ruby/object:Gem::Version
30
+ hash: 15
28
31
  segments:
29
32
  - 1
30
33
  - 0
@@ -253,7 +256,6 @@ files:
253
256
  - lib/active_support/xml_mini/rexml.rb
254
257
  - lib/active_support/xml_mini.rb
255
258
  - lib/active_support.rb
256
- has_rdoc: true
257
259
  homepage: http://www.rubyonrails.org
258
260
  licenses: []
259
261
 
@@ -263,18 +265,22 @@ rdoc_options: []
263
265
  require_paths:
264
266
  - lib
265
267
  required_ruby_version: !ruby/object:Gem::Requirement
268
+ none: false
266
269
  requirements:
267
270
  - - ">="
268
271
  - !ruby/object:Gem::Version
272
+ hash: 57
269
273
  segments:
270
274
  - 1
271
275
  - 8
272
276
  - 7
273
277
  version: 1.8.7
274
278
  required_rubygems_version: !ruby/object:Gem::Requirement
279
+ none: false
275
280
  requirements:
276
281
  - - ">"
277
282
  - !ruby/object:Gem::Version
283
+ hash: 25
278
284
  segments:
279
285
  - 1
280
286
  - 3
@@ -283,7 +289,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
283
289
  requirements: []
284
290
 
285
291
  rubyforge_project:
286
- rubygems_version: 1.3.6
292
+ rubygems_version: 1.8.8
287
293
  signing_key:
288
294
  specification_version: 3
289
295
  summary: A toolkit of support libraries and Ruby core extensions extracted from the Rails framework.