Class: ConfCtl::Generation::HostList
- Inherits:
-
Object
- Object
- ConfCtl::Generation::HostList
- Defined in:
- lib/confctl/generation/host_list.rb
Instance Attribute Summary collapse
- #host ⇒ String readonly
Class Method Summary collapse
Instance Method Summary collapse
- #<<(generation) ⇒ Object
- #count ⇒ Integer
- #current ⇒ Generation::Host
- #each ⇒ Object
-
#initialize(host) ⇒ HostList
constructor
A new instance of HostList.
- #sort ⇒ Object
Constructor Details
#initialize(host) ⇒ HostList
Returns a new instance of HostList.
49 50 51 52 |
# File 'lib/confctl/generation/host_list.rb', line 49 def initialize(host) @host = host @generations = [] end |
Instance Attribute Details
#host ⇒ String (readonly)
46 47 48 |
# File 'lib/confctl/generation/host_list.rb', line 46 def host @host end |
Class Method Details
.fetch(mc, profile:) ⇒ Generation::HostList
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(<<~END) realpath #{profile} for generation in `ls -d -1 #{profile}-*-link` ; do echo "$generation;$(readlink $generation);$(stat --format=%Y $generation)" done END list = new(mc.machine.name) lines = out.strip.split("\n") current_path = lines.shift id_rx = /^#{Regexp.escape(profile)}-(\d+)-link$/ lines.each do |line| link, path, created_at = line.split(';') if id_rx =~ link id = ::Regexp.last_match(1).to_i else warn "Invalid profile generation link '#{link}'" next end list << Generation::Host.new( mc.machine.name, profile, id, path, Time.at(created_at.to_i), current: path == current_path, mc: ) end list.sort list end |
Instance Method Details
#<<(generation) ⇒ Object
55 56 57 |
# File 'lib/confctl/generation/host_list.rb', line 55 def <<(generation) generations << generation end |
#count ⇒ Integer
68 69 70 |
# File 'lib/confctl/generation/host_list.rb', line 68 def count generations.length end |
#current ⇒ Generation::Host
73 74 75 |
# File 'lib/confctl/generation/host_list.rb', line 73 def current generations.detect(&:current) end |
#each ⇒ Object
63 64 65 |
# File 'lib/confctl/generation/host_list.rb', line 63 def each(&) generations.each(&) end |
#sort ⇒ Object
59 60 61 |
# File 'lib/confctl/generation/host_list.rb', line 59 def sort generations.sort! { |a, b| a.id <=> b.id } end |