Module: R10K::Util::Purgeable

Included in:
Deployment::Basedir, Puppetfile, Source::Git, Source::SVN
Defined in:
lib/r10k/util/purgeable.rb

Instance Method Summary collapse

Instance Method Details

#current_contentsArray<String>

Returns The present directory entries in ‘self.managed_directory`.

Returns:

  • (Array<String>)

    The present directory entries in ‘self.managed_directory`



21
22
23
24
25
26
27
28
# File 'lib/r10k/util/purgeable.rb', line 21

def current_contents
  dir = self.managed_directory
  glob_exp = File.join(dir, '*')

  Dir.glob(glob_exp).map do |fname|
    File.basename fname
  end
end

#desired_contentsArray<String>

This method is abstract.

Including classes must implement this method to list the expected filenames of managed_directory

Returns A list of directory contents that should be present.

Returns:

  • (Array<String>)

    A list of directory contents that should be present



# File 'lib/r10k/util/purgeable.rb', line 10

#managed_directoryString

This method is abstract.

Including classes must implement this method to return the path to the directory that can be purged

Returns The path to the directory to be purged.

Returns:

  • (String)

    The path to the directory to be purged



# File 'lib/r10k/util/purgeable.rb', line 15

#pending_contentsArray<String>

Returns Directory contents that are expected but not present.

Returns:

  • (Array<String>)

    Directory contents that are expected but not present



31
32
33
# File 'lib/r10k/util/purgeable.rb', line 31

def pending_contents
  desired_contents - current_contents
end

#purge!Object

Forcibly remove all unmanaged content in ‘self.managed_directory`



41
42
43
44
45
46
# File 'lib/r10k/util/purgeable.rb', line 41

def purge!
  stale_contents.each do |fname|
    fpath = File.join(self.managed_directory, fname)
    FileUtils.rm_rf fpath, :secure => true
  end
end

#stale_contentsArray<String>

Returns Directory contents that are present but not expected.

Returns:

  • (Array<String>)

    Directory contents that are present but not expected



36
37
38
# File 'lib/r10k/util/purgeable.rb', line 36

def stale_contents
  current_contents - desired_contents
end