class CFA::BeforePlacer
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.
Public Class Methods
new(matcher)
click to toggle source
@param [Matcher] matcher
# File lib/cfa/placer.rb, line 43 def initialize(matcher) @matcher = matcher end
Public Instance Methods
new_element(tree)
click to toggle source
(see Placer#new_element
)
# File lib/cfa/placer.rb, line 48 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