Module: Moxml::Adapter

Defined in:
lib/moxml/adapter.rb,
lib/moxml/adapter/ox.rb,
lib/moxml/adapter/oga.rb,
lib/moxml/adapter/base.rb,
lib/moxml/adapter/rexml.rb,
lib/moxml/adapter/libxml.rb,
lib/moxml/adapter/nokogiri.rb,
lib/moxml/adapter/headed_ox.rb,
lib/moxml/adapter/customized_ox.rb,
lib/moxml/adapter/customized_oga.rb,
lib/moxml/adapter/customized_rexml.rb,
lib/moxml/adapter/customized_libxml.rb,
lib/moxml/adapter/customized_ox/text.rb,
lib/moxml/adapter/customized_libxml/node.rb,
lib/moxml/adapter/customized_libxml/text.rb,
lib/moxml/adapter/libxml/entity_restorer.rb,
lib/moxml/adapter/customized_libxml/cdata.rb,
lib/moxml/adapter/customized_ox/attribute.rb,
lib/moxml/adapter/customized_ox/namespace.rb,
lib/moxml/adapter/customized_libxml/comment.rb,
lib/moxml/adapter/customized_libxml/element.rb,
lib/moxml/adapter/customized_rexml/formatter.rb,
lib/moxml/adapter/libxml/entity_ref_registry.rb,
lib/moxml/adapter/customized_oga/xml_generator.rb,
lib/moxml/adapter/customized_libxml/declaration.rb,
lib/moxml/adapter/customized_oga/xml_declaration.rb,
lib/moxml/adapter/customized_ox/entity_reference.rb,
lib/moxml/adapter/customized_rexml/entity_reference.rb,
lib/moxml/adapter/customized_libxml/entity_reference.rb,
lib/moxml/adapter/customized_libxml/processing_instruction.rb

Defined Under Namespace

Modules: CustomizedLibxml, CustomizedOga, CustomizedOx, CustomizedRexml Classes: Base, HeadedOx, Libxml, Nokogiri, Oga, OgaSAXBridge, Ox, OxSAXBridge, REXMLSAX2Bridge, Rexml

Constant Summary collapse

AVAILABLE_ADAPTERS =
%i[nokogiri oga rexml ox headed_ox libxml].freeze
OPAL_AVAILABLE_ADAPTERS =

Adapters that work under the Opal (JavaScript) runtime. REXML is pure Ruby and Opal reimplements strscan/stringio in its stdlib, enabling REXML to compile cleanly to JavaScript.

%i[rexml].freeze
CONST_NAME_MAP =

Registry mapping adapter names to their class name suffixes. Special cases (like :headed_ox → “HeadedOx”) live here instead of a case statement, keeping the dispatch open for extension.

{
  headed_ox: "HeadedOx",
}.freeze

Class Method Summary collapse

Class Method Details

.available?(name) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/moxml/adapter.rb', line 36

def available?(name)
  platform_adapters.include?(name.to_sym)
end

.load(name) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/moxml/adapter.rb', line 22

def load(name)
  validate_platform!(name)
  require_adapter(name)
  const_name = const_name_for(name)
  const_get(const_name)
rescue LoadError => e
  raise Moxml::AdapterError.new(
    "Could not load #{name} adapter. Please ensure the #{name} gem is installed",
    adapter: name,
    operation: "load",
    native_error: e,
  )
end

.platform_adaptersObject



40
41
42
# File 'lib/moxml/adapter.rb', line 40

def platform_adapters
  RUBY_ENGINE == "opal" ? OPAL_AVAILABLE_ADAPTERS : AVAILABLE_ADAPTERS
end