Sha256: 6876e2ec444bf284155548f7c789898cb9a08d2c23108cba480c52879081e619

Contents?: true

Size: 1.94 KB

Versions: 68

Compression:

Stored size: 1.94 KB

Contents

require 'r10k/deployment'
require 'r10k/logging'
require 'r10k/util/purgeable'

module R10K
  module Util

    # Represents a directory that can purge unmanaged contents
    #
    # @todo pick a better name than basedir. Expect this class to be renamed.
    #
    # @api private
    class Basedir

      include R10K::Util::Purgeable
      include R10K::Logging

      # 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]
      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
      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

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

      # List all environments that should exist in this basedir
      # @note This implements a required method for the Purgeable mixin
      # @return [Array<String>]
      def desired_contents
        @sources.flat_map do |src|
          src.desired_contents.collect { |env| File.join(@path, env) }
        end
      end

      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
    end
  end
end

Version data entries

68 entries across 68 versions & 2 rubygems

Version Path
r10k-5.0.0 lib/r10k/util/basedir.rb
r10k-4.1.0 lib/r10k/util/basedir.rb
r10k-4.0.2 lib/r10k/util/basedir.rb
r10k-4.0.1 lib/r10k/util/basedir.rb
r10k-4.0.0 lib/r10k/util/basedir.rb
r10k-4.0.0.pre lib/r10k/util/basedir.rb
r10k-3.16.0 lib/r10k/util/basedir.rb
r10k-3.15.4 lib/r10k/util/basedir.rb
r10k-3.15.3 lib/r10k/util/basedir.rb
r10k-3.15.2 lib/r10k/util/basedir.rb
r10k-3.15.1 lib/r10k/util/basedir.rb
r10k-3.15.0 lib/r10k/util/basedir.rb
akerl-r10k-3.14.2.1 lib/r10k/util/basedir.rb
r10k-3.14.2 lib/r10k/util/basedir.rb
r10k-3.14.1 lib/r10k/util/basedir.rb
r10k-3.14.0 lib/r10k/util/basedir.rb
r10k-3.13.0 lib/r10k/util/basedir.rb
r10k-3.12.1 lib/r10k/util/basedir.rb
r10k-3.12.0 lib/r10k/util/basedir.rb
r10k-3.11.0 lib/r10k/util/basedir.rb