Class: ConfigFilesApi::BeforePlacer

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

Overview

Specialized placer, that allows to place config value before 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) ⇒ BeforePlacer

Returns a new instance of BeforePlacer.



16
17
18
# File 'lib/config_files_api/placer.rb', line 16

def initialize(matcher)
  @matcher = matcher
end

Instance Method Details

#new_element(tree) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/config_files_api/placer.rb', line 20

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

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