From 76f024ac8db82490a99c71d0d8951d677e3bc9bc Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Sun, 28 Mar 2010 14:15:02 +0200 Subject: adds missing requires for Object#blank? and Object#present? --- activesupport/lib/active_support/xml_mini/libxmlsax.rb | 1 + activesupport/lib/active_support/xml_mini/nokogirisax.rb | 1 + 2 files changed, 2 insertions(+) (limited to 'activesupport/lib/active_support') 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 -- cgit v1.2.3 From edaf92f5ab4b44e789e526dfa8b93cb370e595cf Mon Sep 17 00:00:00 2001 From: Vladimir Andrijevik Date: Fri, 8 Jan 2010 13:57:14 -0800 Subject: Drop expires argument from call to @data in MemCacheStore so it works with memcache-client and memcached gems, as advertised [#3672 state:resolved] Signed-off-by: wycats --- activesupport/lib/active_support/cache/mem_cache_store.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activesupport/lib/active_support') 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 -- cgit v1.2.3 From 41e7c68d87903d0596228b6c1ae2c5d87b209280 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Sun, 28 Mar 2010 22:51:48 -0700 Subject: Ruby 1.9.2: marshaling round-trips Time#zone --- .../lib/active_support/core_ext/time/marshal.rb | 56 ++++++++++++++++++++++ .../core_ext/time/marshal_with_utc_flag.rb | 26 ---------- activesupport/lib/active_support/time.rb | 2 +- 3 files changed, 57 insertions(+), 27 deletions(-) create mode 100644 activesupport/lib/active_support/core_ext/time/marshal.rb delete mode 100644 activesupport/lib/active_support/core_ext/time/marshal_with_utc_flag.rb (limited to 'activesupport/lib/active_support') 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/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' -- cgit v1.2.3 From 48c1d8c341e1fe09111424131f7d223ad032b7e1 Mon Sep 17 00:00:00 2001 From: wycats Date: Sun, 28 Mar 2010 23:21:19 -0700 Subject: Provide a better error if the parsed REXML document has no root [#3803 state:resolved] --- activesupport/lib/active_support/xml_mini/rexml.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'activesupport/lib/active_support') 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 -- cgit v1.2.3 From e30363617cea5b51de2bb2e535c70092554514d0 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Mon, 29 Mar 2010 15:48:36 -0700 Subject: Revert "Hash#symbolize_keys(!) optimizations" Was slower in common case. [#3891 state:open] This reverts commit 2060977b767061a42eb8db2d5c3a30d205a94123. --- activesupport/lib/active_support/core_ext/hash/keys.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activesupport/lib/active_support') 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 -- cgit v1.2.3 From 4aded43b73ff94dbf06b4a2d2075651ce454e1d5 Mon Sep 17 00:00:00 2001 From: wycats Date: Mon, 29 Mar 2010 17:08:08 -0700 Subject: Replace the placeholder base_hook API with on_load. To specify some code that should run during framework load do: ActiveSupport.on_load(:action_controller) do # Code run in the context of AC::Base end --- .../lib/active_support/dependencies/autoload.rb | 4 --- activesupport/lib/active_support/i18n.rb | 2 +- .../lib/active_support/lazy_load_hooks.rb | 30 ++++++++-------------- activesupport/lib/active_support/railtie.rb | 2 +- 4 files changed, 13 insertions(+), 25 deletions(-) (limited to 'activesupport/lib/active_support') 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 -- cgit v1.2.3 From 7212c29802e34fe7368d5b484a479c31fad49c5d Mon Sep 17 00:00:00 2001 From: Juanjo Bazan Date: Tue, 30 Mar 2010 23:18:44 +0200 Subject: new assertion: assert_blank Signed-off-by: Xavier Noria --- activesupport/lib/active_support/testing/assertions.rb | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'activesupport/lib/active_support') diff --git a/activesupport/lib/active_support/testing/assertions.rb b/activesupport/lib/active_support/testing/assertions.rb index c529b92240..30a22fcc0e 100644 --- a/activesupport/lib/active_support/testing/assertions.rb +++ b/activesupport/lib/active_support/testing/assertions.rb @@ -62,6 +62,13 @@ 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 end end end -- cgit v1.2.3 From 589deb39c79cac40eec40d4ee3d86fac16c1f31f Mon Sep 17 00:00:00 2001 From: Juanjo Bazan Date: Tue, 30 Mar 2010 23:39:00 +0200 Subject: New assertion: assert_present [#4299 state:committed] Signed-off-by: Xavier Noria --- activesupport/lib/active_support/testing/assertions.rb | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'activesupport/lib/active_support') diff --git a/activesupport/lib/active_support/testing/assertions.rb b/activesupport/lib/active_support/testing/assertions.rb index 30a22fcc0e..e01aa80877 100644 --- a/activesupport/lib/active_support/testing/assertions.rb +++ b/activesupport/lib/active_support/testing/assertions.rb @@ -69,6 +69,13 @@ module ActiveSupport 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 -- cgit v1.2.3 From 7d0eea179b15c888d8e66654ea7922a9d70831e5 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Tue, 30 Mar 2010 20:24:43 -0300 Subject: Don't cache the utc_offset we are already caching the timezone [#4301 state:committed] Signed-off-by: Jeremy Kemper --- activesupport/lib/active_support/values/time_zone.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'activesupport/lib/active_support') 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 -- cgit v1.2.3 From 607f945b1dc42bc7df85063bd6b1118759c0d8a4 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Wed, 31 Mar 2010 04:40:51 -0700 Subject: adds missing require for blank? and present? --- activesupport/lib/active_support/testing/assertions.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'activesupport/lib/active_support') diff --git a/activesupport/lib/active_support/testing/assertions.rb b/activesupport/lib/active_support/testing/assertions.rb index e01aa80877..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 -- cgit v1.2.3