Module: LazyXmlModel

Extended by:
ActiveSupport::Concern
Defined in:
lib/lazy_xml_model.rb,
lib/lazy_xml_model/version.rb,
lib/lazy_xml_model/element_node.rb,
lib/lazy_xml_model/object_proxy.rb,
lib/lazy_xml_model/element_proxy.rb,
lib/lazy_xml_model/attribute_node.rb,
lib/lazy_xml_model/collection_proxy.rb,
lib/lazy_xml_model/has_one_association.rb,
lib/lazy_xml_model/has_many_association.rb

Defined Under Namespace

Modules: AttributeNode, ElementNode, HasManyAssociation, HasOneAssociation Classes: CollectionProxy, ElementProxy, ObjectProxy

Constant Summary collapse

VERSION =
"0.1.0"

Instance Method Summary collapse

Instance Method Details

#deleteObject



56
57
58
# File 'lib/lazy_xml_model.rb', line 56

def delete
  xml_element.remove
end

#to_xmlObject



51
52
53
54
# File 'lib/lazy_xml_model.rb', line 51

def to_xml
  # TODO: Make this work for non-root objects
  xml_document.to_xml(indent: 2, encoding: 'UTF-8')
end

#xml_documentObject

Instance Methods



39
40
41
# File 'lib/lazy_xml_model.rb', line 39

def xml_document
  @xml_document ||= Nokogiri::XML::Document.parse("<#{root_tag}/>", &:noblanks)
end

#xml_elementObject



47
48
49
# File 'lib/lazy_xml_model.rb', line 47

def xml_element
  @xml_element ||= xml_document.root
end

#xml_parent_elementObject



43
44
45
# File 'lib/lazy_xml_model.rb', line 43

def xml_parent_element
  @xml_parent_element
end