Class: ConfigFilesApi::AfterPlacer

Inherits:
Object
  • Object
show all
Defined in:
lib/config_files_api/placer.rb

Overview

Specialized placer, that allows to place config value after found one. If noone is found, then append to the end Useful, when config option should be inserted to specific location.

Instance Method Summary collapse

Constructor Details

#initialize(matcher) ⇒ AfterPlacer

Returns a new instance of AfterPlacer.



37
38
39
# File 'lib/config_files_api/placer.rb', line 37

def initialize(matcher)
  @matcher = matcher
end

Instance Method Details

#new_element(tree) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/config_files_api/placer.rb', line 41

def new_element(tree)
  index = tree.data.index(&@matcher)

  res = {}
  if index
    tree.data.insert(index + 1, res)
  else
    tree.data << res
  end
  res
end