Class: ConfCtl::Generation::HostList

Inherits:
Object
  • Object
show all
Defined in:
lib/confctl/generation/host_list.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host) ⇒ HostList

Returns a new instance of HostList.

Parameters:

  • host (String)


49
50
51
52
# File 'lib/confctl/generation/host_list.rb', line 49

def initialize(host)
  @host = host
  @generations = []
end

Instance Attribute Details

#hostString (readonly)

Returns:

  • (String)


46
47
48
# File 'lib/confctl/generation/host_list.rb', line 46

def host
  @host
end

Class Method Details

.fetch(mc, profile:) ⇒ Generation::HostList

Parameters:

Returns:



6
7
8
9
10
11
12
13
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
# File 'lib/confctl/generation/host_list.rb', line 6

def self.fetch(mc, profile:)
  out, = mc.bash_script("    realpath \#{profile}\n\n    for generation in `ls -d -1 \#{profile}-*-link` ; do\n      echo \"$generation;$(readlink $generation);$(stat --format=%Y $generation)\"\n    done\n  END\n\n  list = new(mc.machine.name)\n  lines = out.strip.split(\"\\n\")\n  current_path = lines.shift\n  id_rx = /^\#{Regexp.escape(profile)}-(\\d+)-link$/\n\n  lines.each do |line|\n    link, path, created_at = line.split(';')\n\n    if id_rx =~ link\n      id = ::Regexp.last_match(1).to_i\n    else\n      warn \"Invalid profile generation link '\#{link}'\"\n      next\n    end\n\n    list << Generation::Host.new(\n      mc.machine.name,\n      profile,\n      id,\n      path,\n      Time.at(created_at.to_i),\n      current: path == current_path,\n      mc:\n    )\n  end\n\n  list.sort\n  list\nend\n")

Instance Method Details

#<<(generation) ⇒ Object

Parameters:



55
56
57
# File 'lib/confctl/generation/host_list.rb', line 55

def <<(generation)
  generations << generation
end

#countInteger

Returns:

  • (Integer)


68
69
70
# File 'lib/confctl/generation/host_list.rb', line 68

def count
  generations.length
end

#currentGeneration::Host

Returns:



73
74
75
# File 'lib/confctl/generation/host_list.rb', line 73

def current
  generations.detect(&:current)
end

#eachObject



63
64
65
# File 'lib/confctl/generation/host_list.rb', line 63

def each(&)
  generations.each(&)
end

#sortObject



59
60
61
# File 'lib/confctl/generation/host_list.rb', line 59

def sort
  generations.sort! { |a, b| a.id <=> b.id }
end