diff options
Diffstat (limited to 'activesupport/lib/active_support')
6 files changed, 24 insertions, 8 deletions
diff --git a/activesupport/lib/active_support/cache/mem_cache_store.rb b/activesupport/lib/active_support/cache/mem_cache_store.rb index 64d2c3bff6..e07294178b 100644 --- a/activesupport/lib/active_support/cache/mem_cache_store.rb +++ b/activesupport/lib/active_support/cache/mem_cache_store.rb @@ -183,6 +183,14 @@ module ActiveSupport # Provide support for raw values in the local cache strategy. module LocalCacheWithRaw # :nodoc: protected + def read_entry(key, options) + entry = super + if options[:raw] && local_cache && entry + entry = deserialize_entry(entry.value) + end + entry + end + def write_entry(key, entry, options) # :nodoc: retval = super if options[:raw] && local_cache && retval diff --git a/activesupport/lib/active_support/core_ext/enumerable.rb b/activesupport/lib/active_support/core_ext/enumerable.rb index 6d7f771b5d..3e05c6eaf2 100644 --- a/activesupport/lib/active_support/core_ext/enumerable.rb +++ b/activesupport/lib/active_support/core_ext/enumerable.rb @@ -96,7 +96,7 @@ module Enumerable # Returns true if the collection has more than 1 element. Functionally equivalent to collection.size > 1. # Can be called with a block too, much like any?, so people.many? { |p| p.age > 26 } returns true if more than 1 person is over 26. def many?(&block) - size = block_given? ? select(&block).size : self.size + size = block_given? ? count(&block) : self.size size > 1 end diff --git a/activesupport/lib/active_support/core_ext/hash/conversions.rb b/activesupport/lib/active_support/core_ext/hash/conversions.rb index 102378a029..5f07bb4f5a 100644 --- a/activesupport/lib/active_support/core_ext/hash/conversions.rb +++ b/activesupport/lib/active_support/core_ext/hash/conversions.rb @@ -95,7 +95,7 @@ class Hash case value.class.to_s when 'Hash' if value['type'] == 'array' - _, entries = Array.wrap(value.detect { |k,v| k != 'type' }) + _, entries = Array.wrap(value.detect { |k,v| not v.is_a?(String) }) if entries.nil? || (c = value['__content__'] && c.blank?) [] else diff --git a/activesupport/lib/active_support/core_ext/module/delegation.rb b/activesupport/lib/active_support/core_ext/module/delegation.rb index 1777a4b32d..41f9a76b13 100644 --- a/activesupport/lib/active_support/core_ext/module/delegation.rb +++ b/activesupport/lib/active_support/core_ext/module/delegation.rb @@ -127,10 +127,6 @@ class Module end module_eval(<<-EOS, file, line - 5) - if instance_methods(false).map(&:to_s).include?("#{prefix}#{method}") - remove_possible_method("#{prefix}#{method}") - end - def #{prefix}#{method}(*args, &block) # def customer_name(*args, &block) #{to}.__send__(#{method.inspect}, *args, &block) # client.__send__(:name, *args, &block) rescue NoMethodError # rescue NoMethodError diff --git a/activesupport/lib/active_support/core_ext/object/blank.rb b/activesupport/lib/active_support/core_ext/object/blank.rb index 8221dc4abe..fe27f45295 100644 --- a/activesupport/lib/active_support/core_ext/object/blank.rb +++ b/activesupport/lib/active_support/core_ext/object/blank.rb @@ -1,3 +1,6 @@ +# encoding: utf-8 +require 'active_support/core_ext/string/encoding' + class Object # An object is blank if it's false, empty, or a whitespace string. # For example, "", " ", +nil+, [], and {} are all blank. @@ -86,14 +89,23 @@ class Hash end class String + # 0x3000: fullwidth whitespace + NON_WHITESPACE_REGEXP = %r![^\s#{[0x3000].pack("U")}]! + # A string is blank if it's empty or contains whitespaces only: # # "".blank? # => true # " ".blank? # => true + # " ".blank? # => true # " something here ".blank? # => false # def blank? - self !~ /\S/ + # 1.8 does not takes [:space:] properly + if encoding_aware? + self !~ /[^[:space:]]/ + else + self !~ NON_WHITESPACE_REGEXP + end end end diff --git a/activesupport/lib/active_support/time_with_zone.rb b/activesupport/lib/active_support/time_with_zone.rb index 3d092529d6..ec2c717942 100644 --- a/activesupport/lib/active_support/time_with_zone.rb +++ b/activesupport/lib/active_support/time_with_zone.rb @@ -109,7 +109,7 @@ module ActiveSupport def xmlschema(fraction_digits = 0) fraction = if fraction_digits > 0 - ".%i" % time.usec.to_s[0, fraction_digits] + (".%06i" % time.usec)[0, fraction_digits + 1] end "#{time.strftime("%Y-%m-%dT%H:%M:%S")}#{fraction}#{formatted_offset(true, 'Z')}" |