class R10K::Util::Basedir

Represents a directory that can purge unmanaged contents

@todo pick a better name than basedir. Expect this class to be renamed.

@api private

Public Class Methods

from_deployment(path, deployment) click to toggle source

Create a new Basedir by selecting sources from a deployment that match the specified path.

@param path [String] @param deployment [R10K::Deployment]

@return [R10K::Util::Basedir]

# File lib/r10k/util/basedir.rb, line 25
def self.from_deployment(path, deployment)
  sources = deployment.sources.select { |source| source.managed_directory == path }
  new(path, sources)
end
new(path, sources) click to toggle source

@param path [String] The path to the directory to manage @param sources [Array<#desired_contents>] A list of objects that may create filesystem entries

# File lib/r10k/util/basedir.rb, line 32
def initialize(path, sources)
  if sources.is_a? R10K::Deployment
    raise ArgumentError, _("Expected Array<#desired_contents>, got R10K::Deployment")
  end
  @path    = path
  @sources = sources
end

Public Instance Methods

desired_contents() click to toggle source

List all environments that should exist in this basedir @note This implements a required method for the Purgeable mixin @return [Array<String>]

# File lib/r10k/util/basedir.rb, line 50
def desired_contents
  @sources.flat_map do |src|
    src.desired_contents.collect { |env| File.join(@path, env) }
  end
end
managed_directories() click to toggle source

Return the path of the basedir @note This implements a required method for the Purgeable mixin @return [Array]

# File lib/r10k/util/basedir.rb, line 43
def managed_directories
  [@path]
end
purge!() click to toggle source
Calls superclass method R10K::Util::Purgeable#purge!
# File lib/r10k/util/basedir.rb, line 56
def purge!
  @sources.each do |source|
    logger.debug1 _("Source %{source_name} in %{path} manages contents %{contents}") % {source_name: source.name, path: @path, contents: source.desired_contents.inspect}
  end

  super
end