From 0bd6e933c01868db7c7e20d46c972c4e7395b743 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Thu, 24 Sep 2009 18:36:40 -0700 Subject: [PATCH] Restore split between require-time and runtime load path mungery. Simplifies vendor requires. --- .../lib/action_view/template/handlers/builder.rb | 2 +- actionpack/test/template/form_options_helper_test.rb | 2 +- activesupport/lib/active_support.rb | 3 ++- .../lib/active_support/cache/mem_cache_store.rb | 2 +- .../lib/active_support/core_ext/array/conversions.rb | 2 +- .../lib/active_support/core_ext/hash/conversions.rb | 2 +- .../lib/active_support/core_ext/string/xchar.rb | 2 +- activesupport/lib/active_support/values/time_zone.rb | 2 +- activesupport/lib/active_support/vendor.rb | 10 ++++++++++ activesupport/lib/active_support/vendor/builder.rb | 7 ------- activesupport/lib/active_support/vendor/i18n.rb | 7 ------- activesupport/lib/active_support/vendor/memcache.rb | 7 ------- activesupport/lib/active_support/vendor/tzinfo.rb | 7 ------- activesupport/test/abstract_unit.rb | 2 +- 14 files changed, 20 insertions(+), 37 deletions(-) create mode 100644 activesupport/lib/active_support/vendor.rb delete mode 100644 activesupport/lib/active_support/vendor/builder.rb delete mode 100644 activesupport/lib/active_support/vendor/i18n.rb delete mode 100644 activesupport/lib/active_support/vendor/memcache.rb delete mode 100644 activesupport/lib/active_support/vendor/tzinfo.rb diff --git a/actionpack/lib/action_view/template/handlers/builder.rb b/actionpack/lib/action_view/template/handlers/builder.rb index ba0d17b5af..5f381f7bf0 100644 --- a/actionpack/lib/action_view/template/handlers/builder.rb +++ b/actionpack/lib/action_view/template/handlers/builder.rb @@ -6,7 +6,7 @@ class Builder < TemplateHandler self.default_format = Mime::XML def compile(template) - require 'active_support/vendor/builder' + require 'builder' "xml = ::Builder::XmlMarkup.new(:indent => 2);" + "self.output_buffer = xml.target!;" + template.source + diff --git a/actionpack/test/template/form_options_helper_test.rb b/actionpack/test/template/form_options_helper_test.rb index f3cdab05bf..aa40e46aa8 100644 --- a/actionpack/test/template/form_options_helper_test.rb +++ b/actionpack/test/template/form_options_helper_test.rb @@ -1,5 +1,5 @@ require 'abstract_unit' -require 'active_support/vendor/tzinfo' +require 'tzinfo' TZInfo::Timezone.cattr_reader :loaded_zones diff --git a/activesupport/lib/active_support.rb b/activesupport/lib/active_support.rb index 4444268997..0478ae4ebc 100644 --- a/activesupport/lib/active_support.rb +++ b/activesupport/lib/active_support.rb @@ -35,6 +35,7 @@ def load_all!; load_all_hooks.each { |hook| hook.call } end end require 'active_support/autoload' +require 'active_support/vendor' -require 'active_support/vendor/i18n' +require 'i18n' I18n.load_path << "#{File.dirname(__FILE__)}/active_support/locale/en.yml" diff --git a/activesupport/lib/active_support/cache/mem_cache_store.rb b/activesupport/lib/active_support/cache/mem_cache_store.rb index ea38baa9ad..516af99ce9 100644 --- a/activesupport/lib/active_support/cache/mem_cache_store.rb +++ b/activesupport/lib/active_support/cache/mem_cache_store.rb @@ -1,4 +1,4 @@ -require 'active_support/vendor/memcache' +require 'memcache' module ActiveSupport module Cache diff --git a/activesupport/lib/active_support/core_ext/array/conversions.rb b/activesupport/lib/active_support/core_ext/array/conversions.rb index 0743ab181e..c53cf3f530 100644 --- a/activesupport/lib/active_support/core_ext/array/conversions.rb +++ b/activesupport/lib/active_support/core_ext/array/conversions.rb @@ -157,7 +157,7 @@ def to_formatted_s(format = :default) # def to_xml(options = {}) raise "Not all elements respond to to_xml" unless all? { |e| e.respond_to? :to_xml } - require 'active_support/vendor/builder' unless defined?(Builder) + require 'builder' unless defined?(Builder) options = options.dup options[:root] ||= all? { |e| e.is_a?(first.class) && first.class.to_s != "Hash" } ? ActiveSupport::Inflector.pluralize(ActiveSupport::Inflector.underscore(first.class.name)) : "records" diff --git a/activesupport/lib/active_support/core_ext/hash/conversions.rb b/activesupport/lib/active_support/core_ext/hash/conversions.rb index 1f8bd7cd82..bd9419e1a2 100644 --- a/activesupport/lib/active_support/core_ext/hash/conversions.rb +++ b/activesupport/lib/active_support/core_ext/hash/conversions.rb @@ -84,7 +84,7 @@ def to_query(namespace = nil) alias_method :to_param, :to_query def to_xml(options = {}) - require 'active_support/vendor/builder' unless defined?(Builder) + require 'builder' unless defined?(Builder) options = options.dup options[:indent] ||= 2 diff --git a/activesupport/lib/active_support/core_ext/string/xchar.rb b/activesupport/lib/active_support/core_ext/string/xchar.rb index 26857c8b0d..7183218634 100644 --- a/activesupport/lib/active_support/core_ext/string/xchar.rb +++ b/activesupport/lib/active_support/core_ext/string/xchar.rb @@ -6,7 +6,7 @@ # fast_xs extension unavailable else begin - require 'active_support/vendor/builder' + require 'builder' rescue LoadError # builder demands the first shot at defining String#to_xs end diff --git a/activesupport/lib/active_support/values/time_zone.rb b/activesupport/lib/active_support/values/time_zone.rb index 4eb268ac7d..564528bfe2 100644 --- a/activesupport/lib/active_support/values/time_zone.rb +++ b/activesupport/lib/active_support/values/time_zone.rb @@ -306,7 +306,7 @@ def period_for_local(time, dst=true) # TODO: Preload instead of lazy load for thread safety def tzinfo - require 'active_support/vendor/tzinfo' unless defined?(TZInfo) + require 'tzinfo' unless defined?(TZInfo) @tzinfo ||= TZInfo::Timezone.get(MAPPING[name]) end diff --git a/activesupport/lib/active_support/vendor.rb b/activesupport/lib/active_support/vendor.rb new file mode 100644 index 0000000000..d9dfc184da --- /dev/null +++ b/activesupport/lib/active_support/vendor.rb @@ -0,0 +1,10 @@ +[%w(builder 2.1.2), %w(i18n 0.1.3), %w(memcache-client 1.7.5), %w(tzinfo 0.3.13)].each do |lib, version| + # Try to activate a gem ~> satisfying the requested version first. + begin + gem lib, "~> #{version}" + # Use the vendored lib if the gem's missing or we aren't using RubyGems. + rescue LoadError, NoMethodError + # Push, not unshift, so the vendored lib is lowest priority. + $LOAD_PATH << File.expand_path("#{File.dirname(__FILE__)}/vendor/#{lib}-#{version}/lib") + end +end diff --git a/activesupport/lib/active_support/vendor/builder.rb b/activesupport/lib/active_support/vendor/builder.rb deleted file mode 100644 index 349825f438..0000000000 --- a/activesupport/lib/active_support/vendor/builder.rb +++ /dev/null @@ -1,7 +0,0 @@ -begin - gem 'builder', '~> 2.1.2' -rescue LoadError, NoMethodError - $LOAD_PATH.unshift File.expand_path("#{File.dirname(__FILE__)}/builder-2.1.2/lib") -end - -require 'builder' diff --git a/activesupport/lib/active_support/vendor/i18n.rb b/activesupport/lib/active_support/vendor/i18n.rb deleted file mode 100644 index 05c03277e3..0000000000 --- a/activesupport/lib/active_support/vendor/i18n.rb +++ /dev/null @@ -1,7 +0,0 @@ -begin - gem 'i18n', '~> 0.1.3' -rescue LoadError, NoMethodError - $LOAD_PATH.unshift File.expand_path("#{File.dirname(__FILE__)}/i18n-0.1.3/lib") -end - -require 'i18n' diff --git a/activesupport/lib/active_support/vendor/memcache.rb b/activesupport/lib/active_support/vendor/memcache.rb deleted file mode 100644 index 878464f6db..0000000000 --- a/activesupport/lib/active_support/vendor/memcache.rb +++ /dev/null @@ -1,7 +0,0 @@ -begin - gem 'memcache-client', '~> 1.7.5' -rescue LoadError, NoMethodError - $LOAD_PATH.unshift File.expand_path("#{File.dirname(__FILE__)}/memcache-client-1.7.5/lib") -end - -require 'memcache' diff --git a/activesupport/lib/active_support/vendor/tzinfo.rb b/activesupport/lib/active_support/vendor/tzinfo.rb deleted file mode 100644 index 0d47361d97..0000000000 --- a/activesupport/lib/active_support/vendor/tzinfo.rb +++ /dev/null @@ -1,7 +0,0 @@ -begin - gem 'tzinfo', '~> 0.3.13' -rescue LoadError, NoMethodError - $LOAD_PATH.unshift File.expand_path("#{File.dirname(__FILE__)}/tzinfo-0.3.13/lib") -end - -require 'tzinfo' diff --git a/activesupport/test/abstract_unit.rb b/activesupport/test/abstract_unit.rb index ee6084dfcd..af9656615c 100644 --- a/activesupport/test/abstract_unit.rb +++ b/activesupport/test/abstract_unit.rb @@ -19,7 +19,7 @@ require 'active_support/ruby/shim' def uses_memcached(test_name) - require 'active_support/vendor/memcache' + require 'memcache' begin MemCache.new('localhost').stats yield