activesupport 3.2.0.rc1 → 3.2.0.rc2

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.

@@ -1,6 +1,6 @@
1
1
  ## Rails 3.2.0 (unreleased) ##
2
2
 
3
- * Added Enumerable#pluck to wrap the common pattern of collect(&:method) *DHH*
3
+ * ActiveSupport::Base64 is deprecated in favor of ::Base64. *Sergey Nartimov*
4
4
 
5
5
  * Module#synchronize is deprecated with no replacement. Please use `monitor`
6
6
  from ruby's standard library.
@@ -1,42 +1,52 @@
1
1
  begin
2
2
  require 'base64'
3
3
  rescue LoadError
4
+ # The Base64 module isn't available in ealier versions of Ruby 1.9.
5
+ module Base64
6
+ # Encodes a string to its base 64 representation. Each 60 characters of
7
+ # output is separated by a newline character.
8
+ #
9
+ # ActiveSupport::Base64.encode64("Original unencoded string")
10
+ # # => "T3JpZ2luYWwgdW5lbmNvZGVkIHN0cmluZw==\n"
11
+ def self.encode64(data)
12
+ [data].pack("m")
13
+ end
14
+
15
+ # Decodes a base 64 encoded string to its original representation.
16
+ #
17
+ # ActiveSupport::Base64.decode64("T3JpZ2luYWwgdW5lbmNvZGVkIHN0cmluZw==")
18
+ # # => "Original unencoded string"
19
+ def self.decode64(data)
20
+ data.unpack("m").first
21
+ end
22
+ end
23
+ end
24
+
25
+ unless Base64.respond_to?(:strict_encode64)
26
+ # Included in Ruby 1.9
27
+ def Base64.strict_encode64(value)
28
+ encode64(value).gsub(/\n/, '')
29
+ end
4
30
  end
5
31
 
6
32
  module ActiveSupport
7
- if defined? ::Base64
8
- Base64 = ::Base64
9
- else
10
- # Base64 provides utility methods for encoding and de-coding binary data
11
- # using a base 64 representation. A base 64 representation of binary data
12
- # consists entirely of printable US-ASCII characters. The Base64 module
13
- # is included in Ruby 1.8, but has been removed in Ruby 1.9.
14
- module Base64
15
- # Encodes a string to its base 64 representation. Each 60 characters of
16
- # output is separated by a newline character.
17
- #
18
- # ActiveSupport::Base64.encode64("Original unencoded string")
19
- # # => "T3JpZ2luYWwgdW5lbmNvZGVkIHN0cmluZw==\n"
20
- def self.encode64(data)
21
- [data].pack("m")
22
- end
33
+ module Base64
34
+ def self.encode64(value)
35
+ ActiveSupport::Deprecation.warn "ActiveSupport::Base64.encode64 " \
36
+ "is deprecated. Use Base64.encode64 instead", caller
37
+ ::Base64.encode64(value)
38
+ end
23
39
 
24
- # Decodes a base 64 encoded string to its original representation.
25
- #
26
- # ActiveSupport::Base64.decode64("T3JpZ2luYWwgdW5lbmNvZGVkIHN0cmluZw==")
27
- # # => "Original unencoded string"
28
- def self.decode64(data)
29
- data.unpack("m").first
30
- end
40
+ def self.decode64(value)
41
+ ActiveSupport::Deprecation.warn "ActiveSupport::Base64.decode64 " \
42
+ "is deprecated. Use Base64.decode64 instead", caller
43
+ ::Base64.encode64(value)
31
44
  end
32
- end
33
45
 
34
- # Encodes the value as base64 without the newline breaks. This makes the base64 encoding readily usable as URL parameters
35
- # or memcache keys without further processing.
36
- #
37
- # ActiveSupport::Base64.encode64s("Original unencoded string")
38
- # # => "T3JpZ2luYWwgdW5lbmNvZGVkIHN0cmluZw=="
39
- def Base64.encode64s(value)
40
- encode64(value).gsub(/\n/, '')
46
+ def self.encode64s(value)
47
+ ActiveSupport::Deprecation.warn "ActiveSupport::Base64.encode64s " \
48
+ "is deprecated. Use Base64.strict_encode64 instead", caller
49
+ ::Base64.strict_encode64(value)
50
+ end
41
51
  end
42
52
  end
@@ -578,7 +578,17 @@ module ActiveSupport
578
578
  # it is marshalled and eventually compressed. Both operations yield
579
579
  # strings.
580
580
  if @value
581
- Marshal.load(compressed? ? Zlib::Inflate.inflate(@value) : @value)
581
+ # In rails 3.1 and earlier values in entries did not marshaled without
582
+ # options[:compress] and if it's Numeric.
583
+ # But after commit a263f377978fc07515b42808ebc1f7894fafaa3a
584
+ # all values in entries are marshalled. And after that code below expects
585
+ # that all values in entries will be marshaled (and will be strings).
586
+ # So here we need a check for old ones.
587
+ begin
588
+ Marshal.load(compressed? ? Zlib::Inflate.inflate(@value) : @value)
589
+ rescue TypeError
590
+ compressed? ? Zlib::Inflate.inflate(@value) : @value
591
+ end
582
592
  end
583
593
  end
584
594
 
@@ -378,18 +378,11 @@ module ActiveSupport
378
378
  module ClassMethods
379
379
  # Generate the internal runner method called by +run_callbacks+.
380
380
  def __define_runner(symbol) #:nodoc:
381
- body = send("_#{symbol}_callbacks").compile
382
381
  runner_method = "_run_#{symbol}_callbacks"
383
-
384
- silence_warnings do
385
- undef_method runner_method if method_defined?(runner_method)
382
+ unless private_method_defined?(runner_method)
386
383
  class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
387
384
  def #{runner_method}(key = nil, &blk)
388
- if key
389
- self.class.__run_keyed_callback(key, :#{symbol}, self, &blk)
390
- else
391
- #{body}
392
- end
385
+ self.class.__run_callback(key, :#{symbol}, self, &blk)
393
386
  end
394
387
  private :#{runner_method}
395
388
  RUBY_EVAL
@@ -400,10 +393,10 @@ module ActiveSupport
400
393
  # If this called first time it creates a new callback method for the key,
401
394
  # calculating which callbacks can be omitted because of per_key conditions.
402
395
  #
403
- def __run_keyed_callback(key, kind, object, &blk) #:nodoc:
404
- name = "_run__#{self.name.hash.abs}__#{kind}__#{key.hash.abs}__callbacks"
396
+ def __run_callback(key, kind, object, &blk) #:nodoc:
397
+ name = __callback_runner_name(key, kind)
405
398
  unless object.respond_to?(name)
406
- str = send("_#{kind}_callbacks").compile(name, object)
399
+ str = send("_#{kind}_callbacks").compile(key, object)
407
400
  class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
408
401
  def #{name}() #{str} end
409
402
  protected :#{name}
@@ -412,6 +405,15 @@ module ActiveSupport
412
405
  object.send(name, &blk)
413
406
  end
414
407
 
408
+ def __reset_runner(symbol)
409
+ name = __callback_runner_name(nil, symbol)
410
+ undef_method(name) if method_defined?(name)
411
+ end
412
+
413
+ def __callback_runner_name(key, kind)
414
+ "_run__#{self.name.hash.abs}__#{kind}__#{key.hash.abs}__callbacks"
415
+ end
416
+
415
417
  # This is used internally to append, prepend and skip callbacks to the
416
418
  # CallbackChain.
417
419
  #
@@ -423,7 +425,7 @@ module ActiveSupport
423
425
  ([self] + ActiveSupport::DescendantsTracker.descendants(self)).reverse.each do |target|
424
426
  chain = target.send("_#{name}_callbacks")
425
427
  yield target, chain.dup, type, filters, options
426
- target.__define_runner(name)
428
+ target.__reset_runner(name)
427
429
  end
428
430
  end
429
431
 
@@ -537,12 +539,12 @@ module ActiveSupport
537
539
  chain = target.send("_#{symbol}_callbacks").dup
538
540
  callbacks.each { |c| chain.delete(c) }
539
541
  target.send("_#{symbol}_callbacks=", chain)
540
- target.__define_runner(symbol)
542
+ target.__reset_runner(symbol)
541
543
  end
542
544
 
543
545
  self.send("_#{symbol}_callbacks=", callbacks.dup.clear)
544
546
 
545
- __define_runner(symbol)
547
+ __reset_runner(symbol)
546
548
  end
547
549
 
548
550
  # Define sets of events in the object lifecycle that support callbacks.
@@ -110,6 +110,6 @@ class Class
110
110
 
111
111
  private
112
112
  def singleton_class?
113
- !name || '' == name
113
+ ancestors.first != self
114
114
  end
115
115
  end
@@ -63,13 +63,6 @@ module Enumerable
63
63
  end
64
64
  end
65
65
 
66
- # Plucks the value of the passed method for each element and returns the result as an array. Example:
67
- #
68
- # people.pluck(:name) # => [ "David Heinemeier Hansson", "Jamie Heinemeier Hansson" ]
69
- def pluck(method)
70
- collect { |element| element.send(method) }
71
- end
72
-
73
66
  # Iterates over a collection, passing the current element *and* the
74
67
  # +memo+ to the block. Handy for building up hashes or
75
68
  # reducing collections down to one object. Examples:
@@ -1,4 +1,5 @@
1
1
  require 'active_support/core_ext/class/attribute_accessors'
2
+ require 'active_support/deprecation'
2
3
 
3
4
  # Adds the 'around_level' method to Logger.
4
5
  class Logger #:nodoc:
@@ -49,6 +50,7 @@ class Logger
49
50
  yield self
50
51
  end
51
52
  end
53
+ deprecate :silence
52
54
 
53
55
  alias :old_datetime_format= :datetime_format=
54
56
  # Logging date-time format (string passed to +strftime+). Ignored if the formatter
@@ -9,9 +9,9 @@ class Range
9
9
  # (5..9).include?(11) # => false
10
10
  def include_with_range?(value)
11
11
  if value.is_a?(::Range)
12
- operator = exclude_end? ? :< : :<=
13
- end_value = value.exclude_end? ? last.succ : last
14
- include_without_range?(value.first) && (value.last <=> end_value).send(operator, 0)
12
+ # 1...10 includes 1..9 but it does not include 1..10.
13
+ operator = exclude_end? && !value.exclude_end? ? :< : :<=
14
+ include_without_range?(value.first) && value.last.send(operator, last)
15
15
  else
16
16
  include_without_range?(value)
17
17
  end
@@ -73,12 +73,12 @@ module ActiveSupport
73
73
  encrypted_data = cipher.update(@serializer.dump(value))
74
74
  encrypted_data << cipher.final
75
75
 
76
- [encrypted_data, iv].map {|v| ActiveSupport::Base64.encode64s(v)}.join("--")
76
+ [encrypted_data, iv].map {|v| ::Base64.strict_encode64(v)}.join("--")
77
77
  end
78
78
 
79
79
  def _decrypt(encrypted_message)
80
80
  cipher = new_cipher
81
- encrypted_data, iv = encrypted_message.split("--").map {|v| ActiveSupport::Base64.decode64(v)}
81
+ encrypted_data, iv = encrypted_message.split("--").map {|v| ::Base64.decode64(v)}
82
82
 
83
83
  cipher.decrypt
84
84
  cipher.key = @secret
@@ -42,14 +42,14 @@ module ActiveSupport
42
42
 
43
43
  data, digest = signed_message.split("--")
44
44
  if data.present? && digest.present? && secure_compare(digest, generate_digest(data))
45
- @serializer.load(ActiveSupport::Base64.decode64(data))
45
+ @serializer.load(::Base64.decode64(data))
46
46
  else
47
47
  raise InvalidSignature
48
48
  end
49
49
  end
50
50
 
51
51
  def generate(value)
52
- data = ActiveSupport::Base64.encode64s(@serializer.dump(value))
52
+ data = ::Base64.strict_encode64(@serializer.dump(value))
53
53
  "#{data}--#{generate_digest(data)}"
54
54
  end
55
55
 
@@ -1,4 +1,5 @@
1
1
  require 'active_support/core_ext/object/blank'
2
+ require 'active_support/deprecation'
2
3
  require 'logger'
3
4
 
4
5
  module ActiveSupport
@@ -26,6 +27,11 @@ module ActiveSupport
26
27
  new_tags.size.times { tags.pop }
27
28
  end
28
29
 
30
+ def silence(temporary_level = ERROR, &block)
31
+ @logger.silence(temporary_level, &block)
32
+ end
33
+ deprecate :silence
34
+
29
35
  def add(severity, message = nil, progname = nil, &block)
30
36
  @logger.add(severity, "#{tags_text}#{message}", progname, &block)
31
37
  end
@@ -3,7 +3,7 @@ module ActiveSupport
3
3
  MAJOR = 3
4
4
  MINOR = 2
5
5
  TINY = 0
6
- PRE = "rc1"
6
+ PRE = "rc2"
7
7
 
8
8
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
9
9
  end
@@ -1,4 +1,5 @@
1
1
  require 'time'
2
+ require 'active_support/base64'
2
3
  require 'active_support/core_ext/module/delegation'
3
4
  require 'active_support/core_ext/string/inflections'
4
5
 
@@ -48,7 +49,7 @@ module ActiveSupport
48
49
  "symbol" => Proc.new { |symbol| symbol.to_s },
49
50
  "date" => Proc.new { |date| date.to_s(:db) },
50
51
  "datetime" => Proc.new { |time| time.xmlschema },
51
- "binary" => Proc.new { |binary| ActiveSupport::Base64.encode64(binary) },
52
+ "binary" => Proc.new { |binary| ::Base64.encode64(binary) },
52
53
  "yaml" => Proc.new { |yaml| yaml.to_yaml }
53
54
  } unless defined?(FORMATTING)
54
55
 
@@ -64,7 +65,7 @@ module ActiveSupport
64
65
  "boolean" => Proc.new { |boolean| %w(1 true).include?(boolean.strip) },
65
66
  "string" => Proc.new { |string| string.to_s },
66
67
  "yaml" => Proc.new { |yaml| YAML::load(yaml) rescue yaml },
67
- "base64Binary" => Proc.new { |bin| ActiveSupport::Base64.decode64(bin) },
68
+ "base64Binary" => Proc.new { |bin| ::Base64.decode64(bin) },
68
69
  "binary" => Proc.new { |bin, entity| _parse_binary(bin, entity) },
69
70
  "file" => Proc.new { |file, entity| _parse_file(file, entity) }
70
71
  }
@@ -148,14 +149,14 @@ module ActiveSupport
148
149
  def _parse_binary(bin, entity) #:nodoc:
149
150
  case entity['encoding']
150
151
  when 'base64'
151
- ActiveSupport::Base64.decode64(bin)
152
+ ::Base64.decode64(bin)
152
153
  else
153
154
  bin
154
155
  end
155
156
  end
156
157
 
157
158
  def _parse_file(file, entity)
158
- f = StringIO.new(ActiveSupport::Base64.decode64(file))
159
+ f = StringIO.new(::Base64.decode64(file))
159
160
  f.extend(FileLike)
160
161
  f.original_filename = entity['name']
161
162
  f.content_type = entity['content_type']
metadata CHANGED
@@ -1,46 +1,63 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: activesupport
3
- version: !ruby/object:Gem::Version
4
- version: 3.2.0.rc1
5
- prerelease: 6
3
+ version: !ruby/object:Gem::Version
4
+ hash: 977940591
5
+ prerelease: true
6
+ segments:
7
+ - 3
8
+ - 2
9
+ - 0
10
+ - rc2
11
+ version: 3.2.0.rc2
6
12
  platform: ruby
7
- authors:
13
+ authors:
8
14
  - David Heinemeier Hansson
9
15
  autorequire:
10
16
  bindir: bin
11
17
  cert_chain: []
12
- date: 2011-12-20 00:00:00.000000000 Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
18
+
19
+ date: 2012-01-04 00:00:00 -02:00
20
+ default_executable:
21
+ dependencies:
22
+ - !ruby/object:Gem::Dependency
15
23
  name: i18n
16
- requirement: &2156027620 !ruby/object:Gem::Requirement
24
+ prerelease: false
25
+ requirement: &id001 !ruby/object:Gem::Requirement
17
26
  none: false
18
- requirements:
27
+ requirements:
19
28
  - - ~>
20
- - !ruby/object:Gem::Version
21
- version: '0.6'
29
+ - !ruby/object:Gem::Version
30
+ hash: 7
31
+ segments:
32
+ - 0
33
+ - 6
34
+ version: "0.6"
22
35
  type: :runtime
23
- prerelease: false
24
- version_requirements: *2156027620
25
- - !ruby/object:Gem::Dependency
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
26
38
  name: multi_json
27
- requirement: &2156024920 !ruby/object:Gem::Requirement
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
28
41
  none: false
29
- requirements:
42
+ requirements:
30
43
  - - ~>
31
- - !ruby/object:Gem::Version
32
- version: '1.0'
44
+ - !ruby/object:Gem::Version
45
+ hash: 15
46
+ segments:
47
+ - 1
48
+ - 0
49
+ version: "1.0"
33
50
  type: :runtime
34
- prerelease: false
35
- version_requirements: *2156024920
36
- description: A toolkit of support libraries and Ruby core extensions extracted from
37
- the Rails framework. Rich support for multibyte strings, internationalization, time
38
- zones, and testing.
51
+ version_requirements: *id002
52
+ description: A toolkit of support libraries and Ruby core extensions extracted from the Rails framework. Rich support for multibyte strings, internationalization, time zones, and testing.
39
53
  email: david@loudthinking.com
40
54
  executables: []
55
+
41
56
  extensions: []
57
+
42
58
  extra_rdoc_files: []
43
- files:
59
+
60
+ files:
44
61
  - CHANGELOG.md
45
62
  - MIT-LICENSE
46
63
  - README.rdoc
@@ -254,29 +271,43 @@ files:
254
271
  - lib/active_support/xml_mini/rexml.rb
255
272
  - lib/active_support/xml_mini.rb
256
273
  - lib/active_support.rb
274
+ has_rdoc: true
257
275
  homepage: http://www.rubyonrails.org
258
276
  licenses: []
277
+
259
278
  post_install_message:
260
279
  rdoc_options: []
261
- require_paths:
280
+
281
+ require_paths:
262
282
  - lib
263
- required_ruby_version: !ruby/object:Gem::Requirement
283
+ required_ruby_version: !ruby/object:Gem::Requirement
264
284
  none: false
265
- requirements:
266
- - - ! '>='
267
- - !ruby/object:Gem::Version
285
+ requirements:
286
+ - - ">="
287
+ - !ruby/object:Gem::Version
288
+ hash: 57
289
+ segments:
290
+ - 1
291
+ - 8
292
+ - 7
268
293
  version: 1.8.7
269
- required_rubygems_version: !ruby/object:Gem::Requirement
294
+ required_rubygems_version: !ruby/object:Gem::Requirement
270
295
  none: false
271
- requirements:
272
- - - ! '>'
273
- - !ruby/object:Gem::Version
296
+ requirements:
297
+ - - ">"
298
+ - !ruby/object:Gem::Version
299
+ hash: 25
300
+ segments:
301
+ - 1
302
+ - 3
303
+ - 1
274
304
  version: 1.3.1
275
305
  requirements: []
306
+
276
307
  rubyforge_project:
277
- rubygems_version: 1.8.7
308
+ rubygems_version: 1.3.7
278
309
  signing_key:
279
310
  specification_version: 3
280
- summary: A toolkit of support libraries and Ruby core extensions extracted from the
281
- Rails framework.
311
+ summary: A toolkit of support libraries and Ruby core extensions extracted from the Rails framework.
282
312
  test_files: []
313
+