Class: ConfigFilesApi::AugeasCollection

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/config_files_api/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



10
11
12
13
14
# File 'lib/config_files_api/augeas_parser.rb', line 10

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

Instance Method Details

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



18
19
20
21
22
# File 'lib/config_files_api/augeas_parser.rb', line 18

def add(value, placer = AppendPlacer.new)
  element = placer.new_element(@tree)
  element[:key] = augeas_name
  element[:value] = value
end

#delete(value) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/config_files_api/augeas_parser.rb', line 24

def delete(value)
  key = augeas_name
  @tree.data.reject! do |entry|
    entry[:key] == key &&
      if value.is_a?(Regexp)
        value =~ entry[:value]
      else
        value == entry[:value]
      end
  end

  load_collection
end