Class: CFA::AfterPlacer
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
-
#initialize(matcher) ⇒ AfterPlacer
constructor
A new instance of AfterPlacer.
-
#new_element(tree) ⇒ AugeasElement, Hash
The new element; it is empty! Note that the return value is actually a Hash; AugeasElement documents its structure.
Constructor Details
#initialize(matcher) ⇒ AfterPlacer
Returns a new instance of AfterPlacer.
65 66 67 |
# File 'lib/cfa/placer.rb', line 65 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.
70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/cfa/placer.rb', line 70 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 |