Sha256: 797764d46f65cc5ee8fd2e4d410cb7f24702b1c1a2b6367a3bcb3f97080508df

Contents?: true

Size: 754 Bytes

Versions: 21

Compression:

Stored size: 754 Bytes

Contents

require 'fileutils'

#
# Keep track of dependent VMs.
#
# Poor man's race condition defense - touch and rm files in a directory and count them.
#
module Landrush
  class DependentVMs
    extend Enumerable

    def self.each(&block)
      (dir.directory? ? dir.children : []).each(&block)
    end

    def self.add(hostname)
      FileUtils.touch(file_for(hostname))
    end

    def self.remove(hostname)
      file_for(hostname).tap { |f| f.delete if f.exist? }
    end

    def self.list
      self.map { |path| path.basename.to_s }
    end

    def self.clear!
      dir.rmtree
    end

    def self.file_for(hostname)
      dir.join(hostname)
    end

    def self.dir
      Landrush.working_dir.join('dependent_vms').tap(&:mkpath)
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
landrush-0.19.0 lib/landrush/dependent_vms.rb
landrush-0.18.0 lib/landrush/dependent_vms.rb
landrush-0.17.0 lib/landrush/dependent_vms.rb
landrush-0.16.0 lib/landrush/dependent_vms.rb
landrush-0.15.4 lib/landrush/dependent_vms.rb
landrush-0.15.3 lib/landrush/dependent_vms.rb
landrush-0.15.2 lib/landrush/dependent_vms.rb
landrush-0.15.1 lib/landrush/dependent_vms.rb
landrush-0.15.0 lib/landrush/dependent_vms.rb
landrush-0.14.1 lib/landrush/dependent_vms.rb
landrush-0.14.0 lib/landrush/dependent_vms.rb
landrush-0.13.1 lib/landrush/dependent_vms.rb
landrush-0.13.0 lib/landrush/dependent_vms.rb
landrush-0.12.0 lib/landrush/dependent_vms.rb
landrush-0.11.0 lib/landrush/dependent_vms.rb
landrush-0.10.0 lib/landrush/dependent_vms.rb
landrush-0.9.0 lib/landrush/dependent_vms.rb
landrush-0.8.0 lib/landrush/dependent_vms.rb
landrush-0.7.1 lib/landrush/dependent_vms.rb
landrush-0.7.0 lib/landrush/dependent_vms.rb