Class: Bosh::Director::DiffLines

Inherits:
Array show all
Defined in:
lib/bosh/director/manifest/diff_lines.rb

Constant Summary collapse

MANIFEST_KEYS_ORDER =
%w(
  azs
  vm_types
  vm_extensions
  resource_pools
  compilation
  networks
  disk_types
  disk_pools
  name
  director_uuid
  stemcells
  releases
  update
  jobs
  addons
)

Instance Method Summary collapse

Methods inherited from Array

#to_openstruct

Instance Method Details

#orderObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/bosh/director/manifest/diff_lines.rb', line 33

def order
  sections = {}
  key = nil

  self.each do |line|
    if line.indent == 0 && line.text !~ /^[ -]/
      key = line.text
      sections[key] = []
      sections[key] << Line.new(0, '', nil)
    end

    sections[key] << line
  end

  ordered_lines = []
  MANIFEST_KEYS_ORDER.each do |manifest_key|
    section_name = manifest_key + ':'
    lines = sections[section_name]
    ordered_lines += lines.to_a
    sections.delete(section_name)
  end

  sections.each do |_, section_lines|
    section_lines.each do |line|
      ordered_lines << line
    end
  end

  # ignore the empty line before the first section
  ordered_lines.shift
  self.replace(ordered_lines)
end