Class: CFA::AugeasWriter::LazyOperations Private
- Inherits:
-
Object
- Object
- CFA::AugeasWriter::LazyOperations
- Defined in:
- lib/cfa/augeas_parser/writer.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
This class depends on ordered operations. So adding and removing
Represents an operation that needs to be done after all modifications.
The reason to have this class is that Augeas renumbers its arrays after some operations like ‘rm` or `insert` so previous paths are no longer valid. For this reason these sensitive operations that change paths need to be done at the end and with careful order. See www.redhat.com/archives/augeas-devel/2017-March/msg00002.html
entries has to be done in order how they are placed in tree.
Instance Method Summary collapse
- #add(located_entry) ⇒ Object private
-
#initialize(aug) ⇒ LazyOperations
constructor
private
A new instance of LazyOperations.
- #remove(located_entry) ⇒ Object private
-
#run ⇒ Object
private
starts all previously inserted operations.
Constructor Details
#initialize(aug) ⇒ LazyOperations
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of LazyOperations.
168 169 170 171 |
# File 'lib/cfa/augeas_parser/writer.rb', line 168 def initialize(aug) @aug = aug @operations = [] end |
Instance Method Details
#add(located_entry) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
173 174 175 |
# File 'lib/cfa/augeas_parser/writer.rb', line 173 def add(located_entry) @operations << { type: :add, located_entry: located_entry } end |
#remove(located_entry) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
177 178 179 |
# File 'lib/cfa/augeas_parser/writer.rb', line 177 def remove(located_entry) @operations << { type: :remove, path: located_entry.path } end |
#run ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
starts all previously inserted operations
182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
# File 'lib/cfa/augeas_parser/writer.rb', line 182 def run # the reverse order is needed because if there are two operations # one after another then the latter cannot affect the former @operations.reverse_each do |operation| case operation[:type] when :remove then aug.rm(operation[:path]) when :add located_entry = operation[:located_entry] add_entry(located_entry) else raise "Invalid lazy operation #{operation.inspect}" end end end |