activesupport 2.3.4 → 2.3.5

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,3 +1,11 @@
1
+ *2.3.5 (November 25, 2009)*
2
+
3
+ * Minor Bug Fixes and deprecation warnings
4
+
5
+ * Fixes for the Nokogiri backend for XmlMini
6
+
7
+ * Ruby 1.9 Compatibility
8
+
1
9
  *2.3.4 (September 4, 2009)*
2
10
 
3
11
  * Introduce ActiveSupport::Multibyte.clean to clean invalid multibyte strings.
@@ -101,6 +101,13 @@ module ActiveSupport
101
101
  alias silence? silence
102
102
  alias logger_off? logger_off
103
103
 
104
+ def mute
105
+ previous_silence, @silence = defined?(@silence) && @silence, true
106
+ yield
107
+ ensure
108
+ @silence = previous_silence
109
+ end
110
+
104
111
  # Fetches data from the cache, using the given key. If there is data in
105
112
  # the cache with the given key, then that data is returned.
106
113
  #
@@ -38,6 +38,11 @@ module ActiveSupport
38
38
  #
39
39
  # If no addresses are specified, then MemCacheStore will connect to
40
40
  # localhost port 11211 (the default memcached port).
41
+ #
42
+ # Instead of addresses one can pass in a MemCache-like object. For example:
43
+ #
44
+ # require 'memcached' # gem install memcached; uses C bindings to libmemcached
45
+ # ActiveSupport::Cache::MemCacheStore.new(Memcached::Rails.new("localhost:11211"))
41
46
  def initialize(*addresses)
42
47
  if addresses.first.respond_to?(:get)
43
48
  @data = addresses.first
@@ -37,7 +37,7 @@ module ActiveSupport
37
37
  nil
38
38
  elsif value.nil?
39
39
  value = super
40
- local_cache.write(key, value || NULL) if local_cache
40
+ local_cache.mute { local_cache.write(key, value || NULL) } if local_cache
41
41
  value.duplicable? ? value.dup : value
42
42
  else
43
43
  # forcing the value to be immutable
@@ -47,12 +47,12 @@ module ActiveSupport
47
47
 
48
48
  def write(key, value, options = nil)
49
49
  value = value.to_s if respond_to?(:raw?) && raw?(options)
50
- local_cache.write(key, value || NULL) if local_cache
50
+ local_cache.mute { local_cache.write(key, value || NULL) } if local_cache
51
51
  super
52
52
  end
53
53
 
54
54
  def delete(key, options = nil)
55
- local_cache.write(key, NULL) if local_cache
55
+ local_cache.mute { local_cache.write(key, NULL) } if local_cache
56
56
  super
57
57
  end
58
58
 
@@ -69,7 +69,7 @@ module ActiveSupport
69
69
 
70
70
  def increment(key, amount = 1)
71
71
  if value = super
72
- local_cache.write(key, value.to_s) if local_cache
72
+ local_cache.mute { local_cache.write(key, value.to_s) } if local_cache
73
73
  value
74
74
  else
75
75
  nil
@@ -78,7 +78,7 @@ module ActiveSupport
78
78
 
79
79
  def decrement(key, amount = 1)
80
80
  if value = super
81
- local_cache.write(key, value.to_s) if local_cache
81
+ local_cache.mute { local_cache.write(key, value.to_s) } if local_cache
82
82
  value
83
83
  else
84
84
  nil
@@ -1,4 +1,8 @@
1
- Dir[File.dirname(__FILE__) + "/core_ext/*.rb"].sort.each do |path|
2
- filename = File.basename(path, '.rb')
3
- require "active_support/core_ext/#{filename}"
1
+ filenames = Dir["#{File.dirname(__FILE__)}/core_ext/*.rb"].sort.map do |path|
2
+ File.basename(path, '.rb')
4
3
  end
4
+
5
+ # deprecated
6
+ filenames -= %w(blank)
7
+
8
+ filenames.each { |filename| require "active_support/core_ext/#{filename}" }
@@ -1,58 +1,2 @@
1
- class Object
2
- # An object is blank if it's false, empty, or a whitespace string.
3
- # For example, "", " ", +nil+, [], and {} are blank.
4
- #
5
- # This simplifies
6
- #
7
- # if !address.nil? && !address.empty?
8
- #
9
- # to
10
- #
11
- # if !address.blank?
12
- def blank?
13
- respond_to?(:empty?) ? empty? : !self
14
- end
15
-
16
- # An object is present if it's not blank.
17
- def present?
18
- !blank?
19
- end
20
- end
21
-
22
- class NilClass #:nodoc:
23
- def blank?
24
- true
25
- end
26
- end
27
-
28
- class FalseClass #:nodoc:
29
- def blank?
30
- true
31
- end
32
- end
33
-
34
- class TrueClass #:nodoc:
35
- def blank?
36
- false
37
- end
38
- end
39
-
40
- class Array #:nodoc:
41
- alias_method :blank?, :empty?
42
- end
43
-
44
- class Hash #:nodoc:
45
- alias_method :blank?, :empty?
46
- end
47
-
48
- class String #:nodoc:
49
- def blank?
50
- self !~ /\S/
51
- end
52
- end
53
-
54
- class Numeric #:nodoc:
55
- def blank?
56
- false
57
- end
58
- end
1
+ require 'active_support/core_ext/object/blank'
2
+ ActiveSupport::Deprecation.warn 'require "active_support/core_ext/blank" is deprecated and will be removed in Rails 3. Use require "active_support/core_ext/object/blank" instead.'
@@ -7,6 +7,7 @@ module Kernel
7
7
  end
8
8
  end
9
9
 
10
+ undef :breakpoint if respond_to?(:breakpoint)
10
11
  def breakpoint
11
12
  message = "\n***** The 'breakpoint' command has been renamed 'debugger' -- please change *****\n"
12
13
  defined?(Rails) ? Rails.logger.info(message) : $stderr.puts(message)
@@ -2,7 +2,9 @@
2
2
  class NameError #:nodoc:
3
3
  # Add a method to obtain the missing name from a NameError.
4
4
  def missing_name
5
- $1 if /((::)?([A-Z]\w*)(::[A-Z]\w*)*)$/ =~ message
5
+ if /undefined local variable or method/ !~ message
6
+ $1 if /((::)?([A-Z]\w*)(::[A-Z]\w*)*)$/ =~ message
7
+ end
6
8
  end
7
9
 
8
10
  # Was this exception raised because the given name was missing?
@@ -1,3 +1,4 @@
1
+ require 'active_support/core_ext/object/blank'
1
2
  require 'active_support/core_ext/object/conversions'
2
3
  require 'active_support/core_ext/object/extending'
3
4
  require 'active_support/core_ext/object/instance_variables'
@@ -0,0 +1,58 @@
1
+ class Object
2
+ # An object is blank if it's false, empty, or a whitespace string.
3
+ # For example, "", " ", +nil+, [], and {} are blank.
4
+ #
5
+ # This simplifies
6
+ #
7
+ # if !address.nil? && !address.empty?
8
+ #
9
+ # to
10
+ #
11
+ # if !address.blank?
12
+ def blank?
13
+ respond_to?(:empty?) ? empty? : !self
14
+ end
15
+
16
+ # An object is present if it's not blank.
17
+ def present?
18
+ !blank?
19
+ end
20
+ end
21
+
22
+ class NilClass #:nodoc:
23
+ def blank?
24
+ true
25
+ end
26
+ end
27
+
28
+ class FalseClass #:nodoc:
29
+ def blank?
30
+ true
31
+ end
32
+ end
33
+
34
+ class TrueClass #:nodoc:
35
+ def blank?
36
+ false
37
+ end
38
+ end
39
+
40
+ class Array #:nodoc:
41
+ alias_method :blank?, :empty?
42
+ end
43
+
44
+ class Hash #:nodoc:
45
+ alias_method :blank?, :empty?
46
+ end
47
+
48
+ class String #:nodoc:
49
+ def blank?
50
+ self !~ /\S/
51
+ end
52
+ end
53
+
54
+ class Numeric #:nodoc:
55
+ def blank?
56
+ false
57
+ end
58
+ end
@@ -10,6 +10,7 @@ require 'active_support/core_ext/string/multibyte'
10
10
  require 'active_support/core_ext/string/xchar'
11
11
  require 'active_support/core_ext/string/filters'
12
12
  require 'active_support/core_ext/string/behavior'
13
+ require 'active_support/core_ext/string/output_safety'
13
14
 
14
15
  class String #:nodoc:
15
16
  include ActiveSupport::CoreExtensions::String::Access
@@ -20,4 +21,5 @@ class String #:nodoc:
20
21
  include ActiveSupport::CoreExtensions::String::Iterators
21
22
  include ActiveSupport::CoreExtensions::String::Behavior
22
23
  include ActiveSupport::CoreExtensions::String::Multibyte
24
+ include ActiveSupport::CoreExtensions::String::OutputSafety
23
25
  end
@@ -0,0 +1,48 @@
1
+ module ActiveSupport #:nodoc:
2
+ module CoreExtensions #:nodoc:
3
+ module String #:nodoc:
4
+ module OutputSafety
5
+ def self.included(base)
6
+ base.class_eval do
7
+ alias_method :add_without_safety, :+
8
+ alias_method :+, :add_with_safety
9
+ alias_method_chain :concat, :safety
10
+ undef_method :<<
11
+ alias_method :<<, :concat_with_safety
12
+ end
13
+ end
14
+
15
+ def html_safe?
16
+ defined?(@_rails_html_safe) && @_rails_html_safe
17
+ end
18
+
19
+ def html_safe!
20
+ @_rails_html_safe = true
21
+ self
22
+ end
23
+
24
+ def add_with_safety(other)
25
+ result = add_without_safety(other)
26
+ if html_safe? && also_html_safe?(other)
27
+ result.html_safe!
28
+ else
29
+ result
30
+ end
31
+ end
32
+
33
+ def concat_with_safety(other_or_fixnum)
34
+ result = concat_without_safety(other_or_fixnum)
35
+ unless html_safe? && also_html_safe?(other_or_fixnum)
36
+ @_rails_html_safe = false
37
+ end
38
+ result
39
+ end
40
+
41
+ private
42
+ def also_html_safe?(other)
43
+ other.respond_to?(:html_safe?) && other.html_safe?
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -201,7 +201,8 @@ module ActiveSupport #:nodoc:
201
201
 
202
202
  # Returns a new Time representing the start of the day (0:00)
203
203
  def beginning_of_day
204
- (self - self.seconds_since_midnight).change(:usec => 0)
204
+ #(self - seconds_since_midnight).change(:usec => 0)
205
+ change(:hour => 0, :min => 0, :sec => 0, :usec => 0)
205
206
  end
206
207
  alias :midnight :beginning_of_day
207
208
  alias :at_midnight :beginning_of_day
@@ -13,7 +13,7 @@ module ActiveSupport
13
13
  $stderr.puts callstack.join("\n ") if debug
14
14
  },
15
15
  'development' => Proc.new { |message, callstack|
16
- logger = defined?(Rails) ? Rails.logger : Logger.new($stderr)
16
+ logger = (defined?(Rails) && Rails.logger) ? Rails.logger : Logger.new($stderr)
17
17
  logger.warn message
18
18
  logger.debug callstack.join("\n ") if debug
19
19
  }
@@ -2,10 +2,9 @@ require 'json' unless defined?(JSON)
2
2
 
3
3
  module ActiveSupport
4
4
  module JSON
5
- ParseError = ::JSON::ParserError unless const_defined?(:ParseError)
6
-
7
5
  module Backends
8
6
  module JSONGem
7
+ ParseError = ::JSON::ParserError
9
8
  extend self
10
9
 
11
10
  # Converts a JSON string into a Ruby object.
@@ -35,4 +34,4 @@ module ActiveSupport
35
34
  end
36
35
  end
37
36
  end
38
- end
37
+ end
@@ -2,13 +2,9 @@ require 'active_support/core_ext/string/starts_ends_with'
2
2
 
3
3
  module ActiveSupport
4
4
  module JSON
5
- unless const_defined?(:ParseError)
6
- class ParseError < StandardError
7
- end
8
- end
9
-
10
5
  module Backends
11
6
  module Yaml
7
+ ParseError = ::StandardError
12
8
  extend self
13
9
 
14
10
  # Converts a JSON string into a Ruby object.
@@ -6,6 +6,7 @@ module ActiveSupport
6
6
 
7
7
  module JSON
8
8
  class << self
9
+ attr_reader :parse_error
9
10
  delegate :decode, :to => :backend
10
11
 
11
12
  def backend
@@ -20,6 +21,7 @@ module ActiveSupport
20
21
  require "active_support/json/backends/#{name.to_s.downcase}.rb"
21
22
  @backend = ActiveSupport::JSON::Backends::const_get(name)
22
23
  end
24
+ @parse_error = @backend::ParseError
23
25
  end
24
26
 
25
27
  def with_backend(name)
@@ -24,8 +24,10 @@ module ActiveSupport
24
24
  end
25
25
 
26
26
  def verify(signed_message)
27
+ raise InvalidSignature if signed_message.blank?
28
+
27
29
  data, digest = signed_message.split("--")
28
- if secure_compare(digest, generate_digest(data))
30
+ if data.present? && digest.present? && secure_compare(digest, generate_digest(data))
29
31
  Marshal.load(ActiveSupport::Base64.decode64(data))
30
32
  else
31
33
  raise InvalidSignature
@@ -38,16 +40,34 @@ module ActiveSupport
38
40
  end
39
41
 
40
42
  private
41
- # constant-time comparison algorithm to prevent timing attacks
42
- def secure_compare(a, b)
43
- if a.length == b.length
44
- result = 0
45
- for i in 0..(a.length - 1)
46
- result |= a[i] ^ b[i]
43
+ if "foo".respond_to?(:force_encoding)
44
+ # constant-time comparison algorithm to prevent timing attacks
45
+ def secure_compare(a, b)
46
+ a = a.dup.force_encoding(Encoding::BINARY)
47
+ b = b.dup.force_encoding(Encoding::BINARY)
48
+
49
+ if a.length == b.length
50
+ result = 0
51
+ for i in 0..(a.length - 1)
52
+ result |= a[i].ord ^ b[i].ord
53
+ end
54
+ result == 0
55
+ else
56
+ false
57
+ end
58
+ end
59
+ else
60
+ # For <= 1.8.6
61
+ def secure_compare(a, b)
62
+ if a.length == b.length
63
+ result = 0
64
+ for i in 0..(a.length - 1)
65
+ result |= a[i] ^ b[i]
66
+ end
67
+ result == 0
68
+ else
69
+ false
47
70
  end
48
- result == 0
49
- else
50
- false
51
71
  end
52
72
  end
53
73
 
@@ -320,7 +320,7 @@ module ActiveSupport #:nodoc:
320
320
  # Example:
321
321
  # 'Café'.mb_chars.reverse.to_s #=> 'éfaC'
322
322
  def reverse
323
- chars(self.class.u_unpack(@wrapped_string).reverse.pack('U*'))
323
+ chars(self.class.g_unpack(@wrapped_string).reverse.flatten.pack('U*'))
324
324
  end
325
325
 
326
326
  # Implements Unicode-aware slice with codepoints. Slicing on one point returns the codepoints for that
@@ -5,7 +5,7 @@ module ActiveSupport #:nodoc:
5
5
  if Kernel.const_defined?(:Encoding)
6
6
  # Returns a regular expression that matches valid characters in the current encoding
7
7
  def self.valid_character
8
- VALID_CHARACTER[Encoding.default_internal.to_s]
8
+ VALID_CHARACTER[Encoding.default_external.to_s]
9
9
  end
10
10
  else
11
11
  def self.valid_character
@@ -27,7 +27,7 @@ module ActiveSupport #:nodoc:
27
27
  def self.verify(string)
28
28
  if expression = valid_character
29
29
  for c in string.split(//)
30
- return false unless valid_character.match(c)
30
+ return false unless expression.match(c)
31
31
  end
32
32
  end
33
33
  true
@@ -50,7 +50,7 @@ module ActiveSupport #:nodoc:
50
50
  def self.clean(string)
51
51
  if expression = valid_character
52
52
  stripped = []; for c in string.split(//)
53
- stripped << c if valid_character.match(c)
53
+ stripped << c if expression.match(c)
54
54
  end; stripped.join
55
55
  else
56
56
  string
@@ -58,4 +58,4 @@ module ActiveSupport #:nodoc:
58
58
  end
59
59
  end
60
60
  end
61
- end
61
+ end
@@ -120,6 +120,13 @@ module ActiveSupport
120
120
  dup.merge!(other_hash)
121
121
  end
122
122
 
123
+ # When replacing with another hash, the initial order of our keys must come from the other hash -ordered or not.
124
+ def replace(other)
125
+ super
126
+ @keys = other.keys
127
+ self
128
+ end
129
+
123
130
  def inspect
124
131
  "#<OrderedHash #{super}>"
125
132
  end
@@ -21,8 +21,8 @@ rescue Gem::LoadError
21
21
  end
22
22
 
23
23
  begin
24
- gem 'i18n', '~> 0.1.3'
24
+ gem 'i18n', '>= 0.1.3'
25
25
  rescue Gem::LoadError
26
26
  $:.unshift "#{File.dirname(__FILE__)}/vendor/i18n-0.1.3/lib"
27
- require 'i18n'
28
27
  end
28
+ require 'i18n'
@@ -2,7 +2,7 @@ module ActiveSupport
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 2
4
4
  MINOR = 3
5
- TINY = 4
5
+ TINY = 5
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -43,7 +43,14 @@ class NilClass
43
43
 
44
44
  private
45
45
  def method_missing(method, *args, &block)
46
- raise_nil_warning_for METHOD_CLASS_MAP[method], method, caller
46
+ # Ruby 1.9.2: disallow explicit coercion via method_missing.
47
+ if method == :to_ary || method == :to_str
48
+ super
49
+ elsif klass = METHOD_CLASS_MAP[method]
50
+ raise_nil_warning_for klass, method, caller
51
+ else
52
+ super
53
+ end
47
54
  end
48
55
 
49
56
  # Raises a NoMethodError when you attempt to call a method on +nil+.
@@ -55,4 +62,3 @@ class NilClass
55
62
  raise NoMethodError, message, with_caller || caller
56
63
  end
57
64
  end
58
-
@@ -12,7 +12,7 @@ module ActiveSupport
12
12
  if string.blank?
13
13
  {}
14
14
  else
15
- doc = Nokogiri::XML(string)
15
+ doc = Nokogiri::XML(string) { |cfg| cfg.noblanks }
16
16
  raise doc.errors.first if doc.errors.length > 0
17
17
  doc.to_hash
18
18
  end
@@ -33,33 +33,25 @@ module ActiveSupport
33
33
  # hash::
34
34
  # Hash to merge the converted element into.
35
35
  def to_hash(hash = {})
36
- hash[name] ||= attributes_as_hash
36
+ attributes = attributes_as_hash
37
+ if hash[name]
38
+ hash[name] = [hash[name]].flatten
39
+ hash[name] << attributes
40
+ else
41
+ hash[name] ||= attributes
42
+ end
37
43
 
38
- walker = lambda { |memo, parent, child, callback|
39
- next if child.blank? && 'file' != parent['type']
44
+ children.each { |child|
45
+ next if child.blank? && 'file' != self['type']
40
46
 
41
- if child.text?
42
- (memo[CONTENT_ROOT] ||= '') << child.content
47
+ if child.text? || child.cdata?
48
+ (attributes[CONTENT_ROOT] ||= '') << child.content
43
49
  next
44
50
  end
45
51
 
46
- name = child.name
47
-
48
- child_hash = child.attributes_as_hash
49
- if memo[name]
50
- memo[name] = [memo[name]].flatten
51
- memo[name] << child_hash
52
- else
53
- memo[name] = child_hash
54
- end
55
-
56
- # Recusively walk children
57
- child.children.each { |c|
58
- callback.call(child_hash, child, c, callback)
59
- }
52
+ child.to_hash attributes
60
53
  }
61
54
 
62
- children.each { |c| walker.call(hash[name], self, c, walker) }
63
55
  hash
64
56
  end
65
57
 
@@ -1 +1,2 @@
1
1
  require 'active_support'
2
+ ActiveSupport::Deprecation.warn 'require "activesupport" is deprecated and will be removed in Rails 3. Use require "active_support" instead.'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activesupport
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.4
4
+ version: 2.3.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Heinemeier Hansson
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-09-04 00:00:00 +12:00
12
+ date: 2009-11-27 00:00:00 +13:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -110,6 +110,7 @@ files:
110
110
  - lib/active_support/core_ext/numeric/conversions.rb
111
111
  - lib/active_support/core_ext/numeric/time.rb
112
112
  - lib/active_support/core_ext/numeric.rb
113
+ - lib/active_support/core_ext/object/blank.rb
113
114
  - lib/active_support/core_ext/object/conversions.rb
114
115
  - lib/active_support/core_ext/object/extending.rb
115
116
  - lib/active_support/core_ext/object/instance_variables.rb
@@ -135,6 +136,7 @@ files:
135
136
  - lib/active_support/core_ext/string/inflections.rb
136
137
  - lib/active_support/core_ext/string/iterators.rb
137
138
  - lib/active_support/core_ext/string/multibyte.rb
139
+ - lib/active_support/core_ext/string/output_safety.rb
138
140
  - lib/active_support/core_ext/string/starts_ends_with.rb
139
141
  - lib/active_support/core_ext/string/xchar.rb
140
142
  - lib/active_support/core_ext/string.rb
@@ -391,7 +393,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
391
393
  requirements: []
392
394
 
393
395
  rubyforge_project: activesupport
394
- rubygems_version: 1.3.2
396
+ rubygems_version: 1.3.5
395
397
  signing_key:
396
398
  specification_version: 3
397
399
  summary: Support and utility classes used by the Rails framework.