Module: MARC::MagicReader

Defined in:
lib/marc/xml_parsers.rb

Overview

The MagicReader will try to use the best available XML Parser at the time of initialization. The order is currently:

* Nokogiri
* libxml-ruby (MRI only) ** DEPRECATED **
* jstax (JRuby only) ** DEPRECATED **
* rexml

With the idea that other parsers could be added as their modules are added. Realistically, this list should be limited to stream-based parsers. The magic should be used selectively, however. After all, one project’s definition of ‘best’ might not apply universally. It is arguable which is “best” on JRuby: Nokogiri or jrexml.

Class Method Summary collapse

Class Method Details

.extended(receiver) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/marc/xml_parsers.rb', line 26

def self.extended(receiver)
  magic = MARC::XMLReader.best_available
  case magic
  when "nokogiri"
    receiver.extend(NokogiriReader)
  when "libxml"
    warn "libxml support will be removed in version 1.3. Prefer nokogiri instead"
    receiver.extend(LibXMLReader)
  when "jstax"
    warn "jstax support will be removed in version 1.3. Prefer nokogiri instead"
    receiver.extend(JRubySTAXReader)
  when "jrexml"
    warn "jrexml support is broken upstream; falling back to just rexml. Prefer nokogiri instead"
    receiver.extend(REXMLReader)
  else receiver.extend(REXMLReader)
  end
end