Method: ConfCtl::Generation::BuildList#initialize

Defined in:
lib/confctl/generation/build_list.rb

#initialize(host) ⇒ String



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/confctl/generation/build_list.rb', line 14

def initialize(host)
  @host = host
  @generations = []
  @index = {}

  return unless Dir.exist?(dir)

  Dir.entries(dir).each do |v|
    abs_path = File.join(dir, v)
    next if %w[. ..].include?(v) || !Dir.exist?(abs_path) || File.symlink?(abs_path)

    gen = Generation::Build.new(host)

    begin
      gen.load(v)
    rescue Error => e
      warn "Ignoring invalid generation #{gen.dir}"
      next
    end

    generations << gen
    index[gen.name] = gen
  end

  generations.sort! do |a, b|
    a.date <=> b.date
  end

  current_gen =
    if File.exist?(current_symlink)
      name = File.basename(File.readlink(current_symlink))
      index[name] || generations.last
    else
      generations.last
    end

  change_current(current_gen) if current_gen
end