Module: R10K::Util::Purgeable Abstract
- Included in:
- Puppetfile, Basedir
- Defined in:
- lib/r10k/util/purgeable.rb
Overview
Classes using this mixin need to implement #managed_directory and #desired_contents
Mixin for purging stale directory contents.
Instance Method Summary collapse
-
#current_contents ⇒ Array<String>
The present directory entries in ‘self.managed_directory`.
-
#desired_contents ⇒ Array<String>
abstract
A list of directory contents that should be present.
- #logger ⇒ Log4r::Logger abstract
-
#managed_directory ⇒ String
abstract
The path to the directory to be purged.
-
#pending_contents ⇒ Array<String>
Directory contents that are expected but not present.
-
#purge! ⇒ Object
Forcibly remove all unmanaged content in ‘self.managed_directory`.
-
#stale_contents ⇒ Array<String>
Directory contents that are present but not expected.
Instance Method Details
#current_contents ⇒ Array<String>
Returns The present directory entries in ‘self.managed_directory`.
27 28 29 30 31 32 33 34 |
# File 'lib/r10k/util/purgeable.rb', line 27 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_contents ⇒ Array<String>
Including classes must implement this method to list the expected filenames of managed_directory
Returns A list of directory contents that should be present.
|
# File 'lib/r10k/util/purgeable.rb', line 16
|
#logger ⇒ Log4r::Logger
Including classes must provide a logger method
|
# File 'lib/r10k/util/purgeable.rb', line 12
|
#managed_directory ⇒ String
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.
|
# File 'lib/r10k/util/purgeable.rb', line 21
|
#pending_contents ⇒ Array<String>
Returns Directory contents that are expected but not present.
37 38 39 |
# File 'lib/r10k/util/purgeable.rb', line 37 def pending_contents desired_contents - current_contents end |
#purge! ⇒ Object
Forcibly remove all unmanaged content in ‘self.managed_directory`
47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/r10k/util/purgeable.rb', line 47 def purge! if stale_contents.empty? logger.debug1 "No unmanaged contents in #{managed_directory}, nothing to purge" else stale_contents.each do |fname| fpath = File.join(self.managed_directory, fname) logger.info "Removing unmanaged path #{fpath}" FileUtils.rm_rf(fpath, :secure => true) end end end |
#stale_contents ⇒ Array<String>
Returns Directory contents that are present but not expected.
42 43 44 |
# File 'lib/r10k/util/purgeable.rb', line 42 def stale_contents current_contents - desired_contents end |