aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/xml_mini.rb
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2009-03-10 12:08:42 -0700
committerJeremy Kemper <jeremy@bitsweat.net>2009-03-10 12:08:42 -0700
commit37cf224fdb7259c139450bc33c68ec09489be9c2 (patch)
tree4e207ec7fd5a934ab02a21c8c4b25598781e4e6f /activesupport/lib/active_support/xml_mini.rb
parent694998ee4fb8d257ba78424cab630846327a0889 (diff)
downloadrails-37cf224fdb7259c139450bc33c68ec09489be9c2.tar.gz
rails-37cf224fdb7259c139450bc33c68ec09489be9c2.tar.bz2
rails-37cf224fdb7259c139450bc33c68ec09489be9c2.zip
Make it easier to swap XmlMini backends. Require Nokogiri >= 1.1.1 for XmlMini backend tests.
Diffstat (limited to 'activesupport/lib/active_support/xml_mini.rb')
-rw-r--r--activesupport/lib/active_support/xml_mini.rb21
1 files changed, 15 insertions, 6 deletions
diff --git a/activesupport/lib/active_support/xml_mini.rb b/activesupport/lib/active_support/xml_mini.rb
index 0513c0d4d0..ccd1349491 100644
--- a/activesupport/lib/active_support/xml_mini.rb
+++ b/activesupport/lib/active_support/xml_mini.rb
@@ -6,15 +6,24 @@ module ActiveSupport
# XmlMini.backend = 'LibXML'
module XmlMini
extend self
- delegate :parse, :to => :@backend
- class << self
- attr_reader :backend
- end
+ attr_reader :backend
+ delegate :parse, :to => :backend
def backend=(name)
- require "active_support/xml_mini/#{name.to_s.downcase}.rb"
- @backend = ActiveSupport.const_get("XmlMini_#{name}")
+ if name.is_a?(Module)
+ @backend = name
+ else
+ require "active_support/xml_mini/#{name.to_s.downcase}.rb"
+ @backend = ActiveSupport.const_get("XmlMini_#{name}")
+ end
+ end
+
+ def with_backend(name)
+ old_backend, self.backend = backend, name
+ yield
+ ensure
+ self.backend = old_backend
end
end