aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib
diff options
context:
space:
mode:
Diffstat (limited to 'activesupport/lib')
-rw-r--r--activesupport/lib/active_support/cache/mem_cache_store.rb2
-rw-r--r--activesupport/lib/active_support/core_ext/hash/keys.rb2
-rw-r--r--activesupport/lib/active_support/core_ext/time/marshal.rb56
-rw-r--r--activesupport/lib/active_support/core_ext/time/marshal_with_utc_flag.rb26
-rw-r--r--activesupport/lib/active_support/dependencies/autoload.rb4
-rw-r--r--activesupport/lib/active_support/i18n.rb2
-rw-r--r--activesupport/lib/active_support/lazy_load_hooks.rb30
-rw-r--r--activesupport/lib/active_support/railtie.rb2
-rw-r--r--activesupport/lib/active_support/testing/assertions.rb15
-rw-r--r--activesupport/lib/active_support/time.rb2
-rw-r--r--activesupport/lib/active_support/values/time_zone.rb7
-rw-r--r--activesupport/lib/active_support/xml_mini/libxmlsax.rb1
-rw-r--r--activesupport/lib/active_support/xml_mini/nokogirisax.rb1
-rw-r--r--activesupport/lib/active_support/xml_mini/rexml.rb8
14 files changed, 101 insertions, 57 deletions
diff --git a/activesupport/lib/active_support/cache/mem_cache_store.rb b/activesupport/lib/active_support/cache/mem_cache_store.rb
index d584c9e254..d84a62ca2d 100644
--- a/activesupport/lib/active_support/cache/mem_cache_store.rb
+++ b/activesupport/lib/active_support/cache/mem_cache_store.rb
@@ -91,7 +91,7 @@ module ActiveSupport
def delete(key, options = nil) # :nodoc:
super do
- response = @data.delete(key, expires_in(options))
+ response = @data.delete(key)
response == Response::DELETED
end
rescue MemCache::MemCacheError => e
diff --git a/activesupport/lib/active_support/core_ext/hash/keys.rb b/activesupport/lib/active_support/core_ext/hash/keys.rb
index e4d429fc2b..045a6944fa 100644
--- a/activesupport/lib/active_support/core_ext/hash/keys.rb
+++ b/activesupport/lib/active_support/core_ext/hash/keys.rb
@@ -22,7 +22,7 @@ class Hash
# to +to_sym+.
def symbolize_keys!
keys.each do |key|
- self[(key.to_sym rescue key)] = delete(key) if key.respond_to?(:to_sym) && !key.is_a?(Fixnum)
+ self[(key.to_sym rescue key) || key] = delete(key)
end
self
end
diff --git a/activesupport/lib/active_support/core_ext/time/marshal.rb b/activesupport/lib/active_support/core_ext/time/marshal.rb
new file mode 100644
index 0000000000..1a4d918ce7
--- /dev/null
+++ b/activesupport/lib/active_support/core_ext/time/marshal.rb
@@ -0,0 +1,56 @@
+# Pre-1.9 versions of Ruby have a bug with marshaling Time instances, where utc instances are
+# unmarshalled in the local zone, instead of utc. We're layering behavior on the _dump and _load
+# methods so that utc instances can be flagged on dump, and coerced back to utc on load.
+if !Marshal.load(Marshal.dump(Time.now.utc)).utc?
+ class Time
+ class << self
+ alias_method :_load_without_utc_flag, :_load
+ def _load(marshaled_time)
+ time = _load_without_utc_flag(marshaled_time)
+ time.instance_eval do
+ if defined?(@marshal_with_utc_coercion)
+ val = remove_instance_variable("@marshal_with_utc_coercion")
+ end
+ val ? utc : self
+ end
+ end
+ end
+
+ alias_method :_dump_without_utc_flag, :_dump
+ def _dump(*args)
+ obj = dup
+ obj.instance_variable_set('@marshal_with_utc_coercion', utc?)
+ obj._dump_without_utc_flag(*args)
+ end
+ end
+end
+
+# Ruby 1.9.2 adds utc_offset and zone to Time, but marshaling only
+# preserves utc_offset. Preserve zone also, even though it may not
+# work in some edge cases.
+if Time.local(2010).zone != Marshal.load(Marshal.dump(Time.local(2010))).zone
+ class Time
+ class << self
+ alias_method :_load_without_zone, :_load
+ def _load(marshaled_time)
+ time = _load_without_zone(marshaled_time)
+ time.instance_eval do
+ if zone = defined?(@_zone) && remove_instance_variable('@_zone')
+ ary = to_a
+ ary[-1] = zone
+ utc? ? Time.utc(*ary) : Time.local(*ary)
+ else
+ self
+ end
+ end
+ end
+ end
+
+ alias_method :_dump_without_zone, :_dump
+ def _dump(*args)
+ obj = dup
+ obj.instance_variable_set('@_zone', zone)
+ obj._dump_without_zone(*args)
+ end
+ end
+end
diff --git a/activesupport/lib/active_support/core_ext/time/marshal_with_utc_flag.rb b/activesupport/lib/active_support/core_ext/time/marshal_with_utc_flag.rb
deleted file mode 100644
index 8d46d80251..0000000000
--- a/activesupport/lib/active_support/core_ext/time/marshal_with_utc_flag.rb
+++ /dev/null
@@ -1,26 +0,0 @@
-# Pre-1.9 versions of Ruby have a bug with marshaling Time instances, where utc instances are
-# unmarshalled in the local zone, instead of utc. We're layering behavior on the _dump and _load
-# methods so that utc instances can be flagged on dump, and coerced back to utc on load.
-if RUBY_VERSION < '1.9'
- class Time
- class << self
- alias_method :_original_load, :_load
- def _load(marshaled_time)
- time = _original_load(marshaled_time)
- time.instance_eval do
- if defined?(@marshal_with_utc_coercion)
- val = remove_instance_variable("@marshal_with_utc_coercion")
- end
- val ? utc : self
- end
- end
- end
-
- alias_method :_original_dump, :_dump
- def _dump(*args)
- obj = dup
- obj.instance_variable_set('@marshal_with_utc_coercion', utc?)
- obj._original_dump(*args)
- end
- end
-end
diff --git a/activesupport/lib/active_support/dependencies/autoload.rb b/activesupport/lib/active_support/dependencies/autoload.rb
index f669f4a77e..4c771da096 100644
--- a/activesupport/lib/active_support/dependencies/autoload.rb
+++ b/activesupport/lib/active_support/dependencies/autoload.rb
@@ -3,10 +3,6 @@ require "active_support/lazy_load_hooks"
module ActiveSupport
module Autoload
- def self.extended(base)
- base.extend(LazyLoadHooks)
- end
-
@@autoloads = {}
@@under_path = nil
@@at_path = nil
diff --git a/activesupport/lib/active_support/i18n.rb b/activesupport/lib/active_support/i18n.rb
index 034d7d8ddc..11af48d67e 100644
--- a/activesupport/lib/active_support/i18n.rb
+++ b/activesupport/lib/active_support/i18n.rb
@@ -1,3 +1,3 @@
require 'i18n'
I18n.load_path << "#{File.dirname(__FILE__)}/locale/en.yml"
-ActiveSupport.run_base_hooks(:i18n) \ No newline at end of file
+ActiveSupport.run_load_hooks(:i18n) \ No newline at end of file
diff --git a/activesupport/lib/active_support/lazy_load_hooks.rb b/activesupport/lib/active_support/lazy_load_hooks.rb
index 36acfda524..642a4c105c 100644
--- a/activesupport/lib/active_support/lazy_load_hooks.rb
+++ b/activesupport/lib/active_support/lazy_load_hooks.rb
@@ -1,25 +1,17 @@
module ActiveSupport
- module LazyLoadHooks
- def _setup_base_hooks
- @base_hooks ||= Hash.new {|h,k| h[k] = [] }
- @base ||= {}
- end
-
- def base_hook(name = nil, &block)
- _setup_base_hooks
+ @load_hooks = Hash.new {|h,k| h[k] = [] }
+ @loaded = {}
- if base = @base[name]
- base.instance_eval(&block)
- else
- @base_hooks[name] << block
- end
+ def self.on_load(name, &block)
+ if base = @loaded[name]
+ base.instance_eval(&block)
+ else
+ @load_hooks[name] << block
end
+ end
- def run_base_hooks(base, name = nil)
- _setup_base_hooks
-
- @base_hooks[name].each { |hook| base.instance_eval(&hook) } if @base_hooks
- @base[name] = base
- end
+ def self.run_load_hooks(name, base = Object)
+ @load_hooks[name].each { |hook| base.instance_eval(&hook) }
+ @loaded[name] = base
end
end \ No newline at end of file
diff --git a/activesupport/lib/active_support/railtie.rb b/activesupport/lib/active_support/railtie.rb
index e45d16ee96..b8d54ff839 100644
--- a/activesupport/lib/active_support/railtie.rb
+++ b/activesupport/lib/active_support/railtie.rb
@@ -35,7 +35,7 @@ module I18n
config.i18n.load_path = []
initializer "i18n.initialize" do
- ActiveSupport.base_hook(:i18n) do
+ ActiveSupport.on_load(:i18n) do
I18n.reload!
ActionDispatch::Callbacks.to_prepare do
diff --git a/activesupport/lib/active_support/testing/assertions.rb b/activesupport/lib/active_support/testing/assertions.rb
index c529b92240..33793f0688 100644
--- a/activesupport/lib/active_support/testing/assertions.rb
+++ b/activesupport/lib/active_support/testing/assertions.rb
@@ -1,4 +1,5 @@
require 'active_support/core_ext/array/wrap'
+require 'active_support/core_ext/object/blank'
module ActiveSupport
module Testing
@@ -62,6 +63,20 @@ module ActiveSupport
def assert_no_difference(expression, message = nil, &block)
assert_difference expression, 0, message, &block
end
+
+ # Test if an expression is blank. Passes if object.blank? is true.
+ #
+ # assert_blank [] # => true
+ def assert_blank(object)
+ assert object.blank?, "#{object.inspect} is not blank"
+ end
+
+ # Test if an expression is not blank. Passes if object.present? is true.
+ #
+ # assert_present {:data => 'x' } # => true
+ def assert_present(object)
+ assert object.present?, "#{object.inspect} is blank"
+ end
end
end
end
diff --git a/activesupport/lib/active_support/time.rb b/activesupport/lib/active_support/time.rb
index 0f421421d0..784c7173a9 100644
--- a/activesupport/lib/active_support/time.rb
+++ b/activesupport/lib/active_support/time.rb
@@ -14,7 +14,7 @@ require 'date'
require 'time'
require 'active_support/core_ext/time/publicize_conversion_methods'
-require 'active_support/core_ext/time/marshal_with_utc_flag'
+require 'active_support/core_ext/time/marshal'
require 'active_support/core_ext/time/acts_like'
require 'active_support/core_ext/time/calculations'
require 'active_support/core_ext/time/conversions'
diff --git a/activesupport/lib/active_support/values/time_zone.rb b/activesupport/lib/active_support/values/time_zone.rb
index 3cb4d89e02..945cdd5278 100644
--- a/activesupport/lib/active_support/values/time_zone.rb
+++ b/activesupport/lib/active_support/values/time_zone.rb
@@ -198,10 +198,12 @@ module ActiveSupport
@name = name
@utc_offset = utc_offset
@tzinfo = tzinfo
+ @current_period = nil
end
def utc_offset
- @utc_offset ||= tzinfo.current_period.utc_offset
+ @current_period ||= tzinfo.current_period
+ @current_period.utc_offset
end
# Returns the offset of this time zone as a formatted string, of the
@@ -362,13 +364,14 @@ module ActiveSupport
"Wellington" ],
[ 46_800, "Nuku'alofa" ]].
each do |offset, *places|
- places.sort.each do |place|
+ places.each do |place|
place.freeze
zone = new(place, offset)
ZONES << zone
ZONES_MAP[place] = zone
end
end
+ ZONES.sort!
ZONES.freeze
ZONES_MAP.freeze
diff --git a/activesupport/lib/active_support/xml_mini/libxmlsax.rb b/activesupport/lib/active_support/xml_mini/libxmlsax.rb
index d7b2f4c5be..fe2c1b9349 100644
--- a/activesupport/lib/active_support/xml_mini/libxmlsax.rb
+++ b/activesupport/lib/active_support/xml_mini/libxmlsax.rb
@@ -1,4 +1,5 @@
require 'libxml'
+require 'active_support/core_ext/object/blank'
# = XmlMini LibXML implementation using a SAX-based parser
module ActiveSupport
diff --git a/activesupport/lib/active_support/xml_mini/nokogirisax.rb b/activesupport/lib/active_support/xml_mini/nokogirisax.rb
index d538a9110f..8af7b5e565 100644
--- a/activesupport/lib/active_support/xml_mini/nokogirisax.rb
+++ b/activesupport/lib/active_support/xml_mini/nokogirisax.rb
@@ -1,4 +1,5 @@
require 'nokogiri'
+require 'active_support/core_ext/object/blank'
# = XmlMini Nokogiri implementation using a SAX-based parser
module ActiveSupport
diff --git a/activesupport/lib/active_support/xml_mini/rexml.rb b/activesupport/lib/active_support/xml_mini/rexml.rb
index 3db48ce5a3..863d66a91d 100644
--- a/activesupport/lib/active_support/xml_mini/rexml.rb
+++ b/activesupport/lib/active_support/xml_mini/rexml.rb
@@ -27,7 +27,13 @@ module ActiveSupport
data.ungetc(char)
silence_warnings { require 'rexml/document' } unless defined?(REXML::Document)
doc = REXML::Document.new(data)
- merge_element!({}, doc.root)
+
+ if doc.root
+ merge_element!({}, doc.root)
+ else
+ raise REXML::ParseException,
+ "The document #{doc.to_s.inspect} does not have a valid root"
+ end
end
end