Represents a directory that can purge unmanaged contents
@todo pick a better name than basedir. Expect this class to be renamed.
@api private
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
@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
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
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
# 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