Class: Moxml::Config
- Inherits:
-
Object
- Object
- Moxml::Config
- Defined in:
- lib/moxml/config.rb
Constant Summary collapse
- VALID_ADAPTERS =
%i[nokogiri oga rexml ox headed_ox libxml].freeze
- DEFAULT_ADAPTER =
:nokogiri- OPAL_DEFAULT_ADAPTER =
:oga- ENTITY_LOAD_MODES =
Entity loading modes:
-
:required - Must load entities, raise error if unavailable (default)
-
:optional - Try to load, continue silently if unavailable
-
:disabled - Don’t load entities, use empty registry
-
:custom - Use custom entity provider via entity_provider callback
-
%i[required optional disabled custom].freeze
- NAMESPACE_VALIDATION_MODES =
%i[strict lenient].freeze
- ENTITY_RESTORATION_MODES =
Entity restoration modes:
-
:lenient (default) — restore any known entity from the registry
-
:strict — only restore DTD-declared entities (falls back to lenient until DTD parsing is implemented)
-
%i[strict lenient].freeze
Class Attribute Summary collapse
Instance Attribute Summary collapse
-
#adapter_name ⇒ Object
readonly
Returns the value of attribute adapter_name.
-
#default_encoding ⇒ Object
Returns the value of attribute default_encoding.
-
#default_indent ⇒ Object
Returns the value of attribute default_indent.
-
#entity_encoding ⇒ Object
Returns the value of attribute entity_encoding.
-
#entity_load_mode ⇒ Object
Returns the value of attribute entity_load_mode.
-
#entity_provider ⇒ Object
Returns the value of attribute entity_provider.
-
#entity_restoration_mode ⇒ Object
Returns the value of attribute entity_restoration_mode.
-
#namespace_validation_mode ⇒ Object
Returns the value of attribute namespace_validation_mode.
-
#preload_entity_sets ⇒ Object
Returns the value of attribute preload_entity_sets.
-
#restore_entities ⇒ Object
Returns the value of attribute restore_entities.
-
#strict_parsing ⇒ Object
Returns the value of attribute strict_parsing.
Class Method Summary collapse
Instance Method Summary collapse
- #adapter ⇒ Object
- #adapter=(name) ⇒ Object
- #default_adapter=(name) ⇒ Object
-
#initialize(adapter_name = nil, strict_parsing = nil, default_encoding = nil) ⇒ Config
constructor
A new instance of Config.
- #load_external_entities ⇒ Object
-
#load_external_entities=(value) ⇒ Object
Backward compatibility: convert old boolean to new symbol.
Constructor Details
#initialize(adapter_name = nil, strict_parsing = nil, default_encoding = nil) ⇒ Config
Returns a new instance of Config.
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/moxml/config.rb', line 61 def initialize(adapter_name = nil, strict_parsing = nil, default_encoding = nil) self.adapter = adapter_name || Config.default.adapter_name @strict_parsing = strict_parsing || Config.default.strict_parsing @default_encoding = default_encoding || Config.default.default_encoding # reserved for future use @default_indent = 2 @entity_encoding = :basic @restore_entities = false @preload_entity_sets = [] @entity_load_mode = :required @entity_provider = nil @namespace_validation_mode = :strict @entity_restoration_mode = :lenient end |
Class Attribute Details
.default_adapter ⇒ Object
23 24 25 |
# File 'lib/moxml/config.rb', line 23 def default_adapter @default_adapter ||= runtime_default_adapter end |
Instance Attribute Details
#adapter_name ⇒ Object (readonly)
Returns the value of attribute adapter_name.
49 50 51 |
# File 'lib/moxml/config.rb', line 49 def adapter_name @adapter_name end |
#default_encoding ⇒ Object
Returns the value of attribute default_encoding.
50 51 52 |
# File 'lib/moxml/config.rb', line 50 def default_encoding @default_encoding end |
#default_indent ⇒ Object
Returns the value of attribute default_indent.
50 51 52 |
# File 'lib/moxml/config.rb', line 50 def default_indent @default_indent end |
#entity_encoding ⇒ Object
Returns the value of attribute entity_encoding.
50 51 52 |
# File 'lib/moxml/config.rb', line 50 def entity_encoding @entity_encoding end |
#entity_load_mode ⇒ Object
Returns the value of attribute entity_load_mode.
50 51 52 |
# File 'lib/moxml/config.rb', line 50 def entity_load_mode @entity_load_mode end |
#entity_provider ⇒ Object
Returns the value of attribute entity_provider.
50 51 52 |
# File 'lib/moxml/config.rb', line 50 def entity_provider @entity_provider end |
#entity_restoration_mode ⇒ Object
Returns the value of attribute entity_restoration_mode.
50 51 52 |
# File 'lib/moxml/config.rb', line 50 def entity_restoration_mode @entity_restoration_mode end |
#namespace_validation_mode ⇒ Object
Returns the value of attribute namespace_validation_mode.
50 51 52 |
# File 'lib/moxml/config.rb', line 50 def namespace_validation_mode @namespace_validation_mode end |
#preload_entity_sets ⇒ Object
Returns the value of attribute preload_entity_sets.
50 51 52 |
# File 'lib/moxml/config.rb', line 50 def preload_entity_sets @preload_entity_sets end |
#restore_entities ⇒ Object
Returns the value of attribute restore_entities.
50 51 52 |
# File 'lib/moxml/config.rb', line 50 def restore_entities @restore_entities end |
#strict_parsing ⇒ Object
Returns the value of attribute strict_parsing.
50 51 52 |
# File 'lib/moxml/config.rb', line 50 def strict_parsing @strict_parsing end |
Class Method Details
.default ⇒ Object
19 20 21 |
# File 'lib/moxml/config.rb', line 19 def default @default ||= new(default_adapter, true, "UTF-8") end |
.detect_loaded_adapter ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/moxml/config.rb', line 33 def detect_loaded_adapter return :nokogiri if Object.const_defined?(:Nokogiri) return :ox if Object.const_defined?(:Ox) return :oga if Object.const_defined?(:Oga) nil end |
.runtime_default_adapter ⇒ Object
27 28 29 30 31 |
# File 'lib/moxml/config.rb', line 27 def runtime_default_adapter return OPAL_DEFAULT_ADAPTER if RUBY_ENGINE == "opal" detect_loaded_adapter || DEFAULT_ADAPTER end |
Instance Method Details
#adapter ⇒ Object
98 99 100 |
# File 'lib/moxml/config.rb', line 98 def adapter @adapter ||= Adapter.load(@adapter_name) end |
#adapter=(name) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/moxml/config.rb', line 77 def adapter=(name) name = name.to_sym @adapter = nil unless VALID_ADAPTERS.include?(name) raise Moxml::AdapterError.new( "Invalid adapter: #{name}", adapter: name, operation: "set_adapter", ) end @adapter_name = name adapter end |
#default_adapter=(name) ⇒ Object
93 94 95 96 |
# File 'lib/moxml/config.rb', line 93 def default_adapter=(name) self.adapter = name self.class.default_adapter = name end |
#load_external_entities ⇒ Object
140 141 142 |
# File 'lib/moxml/config.rb', line 140 def load_external_entities @entity_load_mode == :required end |
#load_external_entities=(value) ⇒ Object
Backward compatibility: convert old boolean to new symbol
132 133 134 135 136 137 138 |
# File 'lib/moxml/config.rb', line 132 def load_external_entities=(value) @entity_load_mode = case value when true then :required when false then :disabled else value end end |