Class: ConfigFilesApi::AugeasParser
- Inherits:
-
Object
- Object
- ConfigFilesApi::AugeasParser
- Defined in:
- lib/config_files_api/augeas_parser.rb
Overview
Instance Method Summary collapse
-
#initialize(lens) ⇒ AugeasParser
constructor
A new instance of AugeasParser.
- #parse(raw_string) ⇒ Object
- #serialize(data) ⇒ Object
Constructor Details
#initialize(lens) ⇒ AugeasParser
Returns a new instance of AugeasParser.
185 186 187 |
# File 'lib/config_files_api/augeas_parser.rb', line 185 def initialize(lens) @lens = lens end |
Instance Method Details
#parse(raw_string) ⇒ Object
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
# File 'lib/config_files_api/augeas_parser.rb', line 189 def parse(raw_string) @old_content = raw_string # open augeas without any autoloading and it should not touch disk and # load lenses as needed only root = load_path = nil Augeas.open(root, load_path, Augeas::NO_MODL_AUTOLOAD) do |aug| aug.set("/input", raw_string) report_error(aug) unless aug.text_store(@lens, "/input", "/store") tree = AugeasTree.new tree.load_from_augeas(aug, "/store") return tree end end |
#serialize(data) ⇒ Object
206 207 208 209 210 211 212 213 214 215 216 217 218 219 |
# File 'lib/config_files_api/augeas_parser.rb', line 206 def serialize(data) # open augeas without any autoloading and it should not touch disk and # load lenses as needed only root = load_path = nil Augeas.open(root, load_path, Augeas::NO_MODL_AUTOLOAD) do |aug| aug.set("/input", @old_content || "") data.save_to_augeas(aug, "/store") res = aug.text_retrieve(@lens, "/input", "/store", "/output") report_error(aug) unless res return aug.get("/output") end end |