From 0bd6e933c01868db7c7e20d46c972c4e7395b743 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Thu, 24 Sep 2009 18:36:40 -0700 Subject: Restore split between require-time and runtime load path mungery. Simplifies vendor requires. --- activesupport/lib/active_support/cache/mem_cache_store.rb | 2 +- activesupport/lib/active_support/core_ext/array/conversions.rb | 2 +- activesupport/lib/active_support/core_ext/hash/conversions.rb | 2 +- activesupport/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 ------- 10 files changed, 15 insertions(+), 33 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 (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 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 @@ class Array # 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 @@ class Hash 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 @@ rescue LoadError # 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 @@ module ActiveSupport # 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' -- cgit v1.2.3