Class: CFA::BeforePlacer
Overview
Finds a specific element using a Matcher and places the new element before it. Appends at the end if a match is not found.
Useful when a config option should be inserted to a specific location, or when assigning a comment to an option.
Instance Method Summary collapse
-
#initialize(matcher) ⇒ BeforePlacer
constructor
A new instance of BeforePlacer.
-
#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) ⇒ BeforePlacer
Returns a new instance of BeforePlacer.
40 41 42 |
# File 'lib/cfa/placer.rb', line 40 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; AugeasElement documents its structure.
45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/cfa/placer.rb', line 45 def new_element(tree) index = tree.all_data.index(&@matcher) res = create_element if index tree.all_data.insert(index, res) else tree.all_data << res end res end |