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
Constructor Details
#initialize(matcher) ⇒ AfterPlacer
Returns a new instance of AfterPlacer.
68 69 70 |
# File 'lib/cfa/placer.rb', line 68 def initialize(matcher) @matcher = matcher end |
Instance Method Details
#new_element(tree) ⇒ AugeasElement, Hash
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 |