Class: CFA::AfterPlacer

Inherits:
Placer
  • Object
show all
Defined in:
lib/cfa/placer.rb

Overview

Finds a specific element using a Matcher and places the new element after it. Appends at the end if a match is not found.

Useful when a config option should be inserted to a specific location.

Instance Method Summary collapse

Constructor Details

#initialize(matcher) ⇒ AfterPlacer

Returns a new instance of AfterPlacer.

Parameters:



68
69
70
# File 'lib/cfa/placer.rb', line 68

def initialize(matcher)
  @matcher = matcher
end

Instance Method Details

#new_element(tree) ⇒ AugeasElement, Hash

Returns the new element; it is empty! Note that the return value is actually a Hash; CFA::AugeasElement documents its structure.

Parameters:

Returns:



73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/cfa/placer.rb', line 73

def new_element(tree)
  index = tree.all_data.index(&@matcher)

  res = create_element
  if index
    tree.all_data.insert(index + 1, res)
  else
    tree.all_data << res
  end

  res
end