Class: CFA::AugeasCollection

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/cfa/augeas_parser.rb

Overview

Represents list of same config options in augeas. For example comments are often stored in collections.

Instance Method Summary collapse

Constructor Details

#initialize(tree, name) ⇒ AugeasCollection

Returns a new instance of AugeasCollection.



102
103
104
105
106
# File 'lib/cfa/augeas_parser.rb', line 102

def initialize(tree, name)
  @tree = tree
  @name = name
  load_collection
end

Instance Method Details

#add(value, placer = AppendPlacer.new) ⇒ Object



110
111
112
113
114
115
116
# File 'lib/cfa/augeas_parser.rb', line 110

def add(value, placer = AppendPlacer.new)
  element = placer.new_element(@tree)
  element[:key] = augeas_name
  element[:value] = value
  element[:operation] = :add
  # FIXME: load_collection missing here
end

#delete(value) ⇒ Object



118
119
120
121
122
123
124
125
126
# File 'lib/cfa/augeas_parser.rb', line 118

def delete(value)
  to_delete, to_mark = to_remove(value)
                       .partition { |e| e[:operation] == :add }
  @tree.all_data.delete_if { |e| to_delete.include?(e) }

  to_mark.each { |e| e[:operation] = :remove }

  load_collection
end