From 37cf224fdb7259c139450bc33c68ec09489be9c2 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Tue, 10 Mar 2009 12:08:42 -0700 Subject: Make it easier to swap XmlMini backends. Require Nokogiri >= 1.1.1 for XmlMini backend tests. --- activesupport/lib/active_support/xml_mini.rb | 21 +++++++++++++++------ .../lib/active_support/xml_mini/nokogiri.rb | 9 ++++++--- 2 files changed, 21 insertions(+), 9 deletions(-) (limited to 'activesupport/lib') 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 diff --git a/activesupport/lib/active_support/xml_mini/nokogiri.rb b/activesupport/lib/active_support/xml_mini/nokogiri.rb index bfafa29dd5..5c8a6bfe89 100644 --- a/activesupport/lib/active_support/xml_mini/nokogiri.rb +++ b/activesupport/lib/active_support/xml_mini/nokogiri.rb @@ -1,4 +1,4 @@ -# = XML Mini Nokogiri implementation +# = XmlMini Nokogiri implementation module ActiveSupport module XmlMini_Nokogiri #:nodoc: extend self @@ -7,8 +7,11 @@ module ActiveSupport # string:: # XML Document string to parse def parse(string) - return {} if string.blank? - doc = Nokogiri::XML(string).to_hash + if string.blank? + {} + else + Nokogiri::XML(string).to_hash + end end module Conversions -- cgit v1.2.3