2009-04-22 20:41:28 -04:00
|
|
|
require 'active_support/core_ext/module/delegation'
|
|
|
|
|
2009-01-29 11:24:16 -05:00
|
|
|
module ActiveSupport
|
2009-03-09 15:46:06 -04:00
|
|
|
# = XmlMini
|
2009-03-09 16:42:42 -04:00
|
|
|
#
|
|
|
|
# To use the much faster libxml parser:
|
|
|
|
# gem 'libxml-ruby', '=0.9.7'
|
|
|
|
# XmlMini.backend = 'LibXML'
|
2009-01-29 11:24:16 -05:00
|
|
|
module XmlMini
|
|
|
|
extend self
|
2008-11-26 02:37:10 -05:00
|
|
|
|
2009-03-10 15:08:42 -04:00
|
|
|
attr_reader :backend
|
|
|
|
delegate :parse, :to => :backend
|
2009-03-09 20:27:39 -04:00
|
|
|
|
2009-03-09 15:46:06 -04:00
|
|
|
def backend=(name)
|
2009-03-10 15:08:42 -04:00
|
|
|
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
|
2009-03-09 15:39:20 -04:00
|
|
|
end
|
2009-03-09 15:46:06 -04:00
|
|
|
end
|
2008-11-26 02:37:10 -05:00
|
|
|
|
2009-03-09 16:42:42 -04:00
|
|
|
XmlMini.backend = 'REXML'
|
2009-03-09 15:46:06 -04:00
|
|
|
end
|