Module: UIC::XMLFileBacked
- Includes:
- FileBacked
- Included in:
- Application, Presentation, StateMachine
- Defined in:
- lib/ruic/interfaces.rb
Overview
Supports classes that represent an XML file on disk.
Instance Attribute Summary collapse
-
#doc ⇒ Nokogiri::XML::Document
The Nokogiri document representing the instance.
Attributes included from FileBacked
Instance Method Summary collapse
- #file=(new_path) ⇒ Object
-
#save! ⇒ true
Overwrite the associated file on disk with the #to_xml representation of this class.
-
#save_as(new_file) ⇒ Object
Save to the supplied file path.
-
#to_xml ⇒ String
The XML representation of the document.
Methods included from FileBacked
#absolute_path, #file_found?, #filename, #relative_path
Instance Attribute Details
#doc ⇒ Nokogiri::XML::Document
Returns the Nokogiri document representing the instance.
61 62 63 |
# File 'lib/ruic/interfaces.rb', line 61 def doc @doc end |
Instance Method Details
#file=(new_path) ⇒ Object
63 64 65 66 67 68 69 |
# File 'lib/ruic/interfaces.rb', line 63 def file=( new_path ) super if file_found? @doc = Nokogiri.XML(file_content,&:noblanks) on_doc_loaded if respond_to?(:on_doc_loaded) end end |
#save! ⇒ true
Overwrite the associated file on disk with the #to_xml representation of this class.
78 79 80 81 |
# File 'lib/ruic/interfaces.rb', line 78 def save! self.file_content = to_xml super end |
#save_as(new_file) ⇒ Object
Save to the supplied file path. Subsequent calls to #save! will save to the new file, not the original file name.
84 85 86 87 |
# File 'lib/ruic/interfaces.rb', line 84 def save_as(new_file) self.file_content = to_xml super end |
#to_xml ⇒ String
Returns the XML representation of the document.
72 73 74 |
# File 'lib/ruic/interfaces.rb', line 72 def to_xml doc.to_xml( indent:1, indent_text:"\t" ) end |