Class: CFA::AugeasWriter::LazyOperations Private

Inherits:
Object
  • Object
show all
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.

Note:

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

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.

Parameters:

  • aug

    result of Augeas.create



171
172
173
174
# File 'lib/cfa/augeas_parser/writer.rb', line 171

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.



176
177
178
# File 'lib/cfa/augeas_parser/writer.rb', line 176

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.



180
181
182
# File 'lib/cfa/augeas_parser/writer.rb', line 180

def remove(located_entry)
  @operations << { type: :remove, path: located_entry.path }
end

#runObject

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



185
186
187
188
189
190
191
192
193
194
195
196
197
198
# File 'lib/cfa/augeas_parser/writer.rb', line 185

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 remove_entry(operation[:path])
    when :add
      located_entry = operation[:located_entry]
      add_entry(located_entry)
    else
      raise "Invalid lazy operation #{operation.inspect}"
    end
  end
end