Class: Moxml::Adapter::CustomizedLibxml::Node
- Inherits:
-
Object
- Object
- Moxml::Adapter::CustomizedLibxml::Node
- Defined in:
- lib/moxml/adapter/customized_libxml/node.rb
Overview
Base wrapper class for LibXML nodes
This wrapper hides LibXML's strict document ownership model, allowing nodes to be moved between documents transparently. Similar pattern to Ox adapter's customized classes.
The Libxml adapter owns wrapper type mapping in one place so the wrapper classes do not duplicate node-type knowledge.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#native ⇒ Object
readonly
Returns the value of attribute native.
Instance Method Summary collapse
-
#==(other) ⇒ Object
(also: #eql?)
Compare wrappers based on their native nodes.
-
#document ⇒ Object
Get the document this node belongs to.
-
#document_present? ⇒ Boolean
Check if node has a document.
- #hash ⇒ Object
-
#initialize(native_node) ⇒ Node
constructor
A new instance of Node.
-
#replace_native!(fresh) ⇒ Object
Swap the wrapped native node.
Constructor Details
#initialize(native_node) ⇒ Node
Returns a new instance of Node.
17 18 19 |
# File 'lib/moxml/adapter/customized_libxml/node.rb', line 17 def initialize(native_node) @native = native_node end |
Instance Attribute Details
#native ⇒ Object (readonly)
Returns the value of attribute native.
15 16 17 |
# File 'lib/moxml/adapter/customized_libxml/node.rb', line 15 def native @native end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
Compare wrappers based on their native nodes. Either side may arrive double-wrapped (a Customized node stored as another wrapper's native); LibXML's eql? raises on the class mismatch, so unwrap both before comparing.
33 34 35 36 37 38 39 40 |
# File 'lib/moxml/adapter/customized_libxml/node.rb', line 33 def ==(other) return false unless other mine = @native.is_a?(CustomizedLibxml::Node) ? @native.native : @native theirs = other.is_a?(self.class) ? other.native : other theirs = theirs.native while theirs.is_a?(CustomizedLibxml::Node) mine == theirs end |
#document ⇒ Object
Get the document this node belongs to
54 55 56 |
# File 'lib/moxml/adapter/customized_libxml/node.rb', line 54 def document @native.doc if document_present? end |
#document_present? ⇒ Boolean
Check if node has a document
49 50 51 |
# File 'lib/moxml/adapter/customized_libxml/node.rb', line 49 def document_present? @native.is_a?(::LibXML::XML::Node) && !@native.doc.nil? end |
#hash ⇒ Object
44 45 46 |
# File 'lib/moxml/adapter/customized_libxml/node.rb', line 44 def hash @native.hash end |
#replace_native!(fresh) ⇒ Object
Swap the wrapped native node. Used by the Libxml adapter when libxml-ruby's content= setter would silently re-escape stored text; replacing the node with a fresh raw-storage instance is the only way to preserve verbatim content.
25 26 27 |
# File 'lib/moxml/adapter/customized_libxml/node.rb', line 25 def replace_native!(fresh) @native = fresh end |