class CFA::AfterPlacer

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.

Public Class Methods

new(matcher) click to toggle source

@param [Matcher] matcher

# File lib/cfa/placer.rb, line 68
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 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