Class: R10K::Util::Basedir Private

Inherits:
Object
  • Object
show all
Includes:
Logging, Purgeable
Defined in:
lib/r10k/util/basedir.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

TODO:

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

Represents a directory that can purge unmanaged contents

Constant Summary

Constants included from Logging

Logging::LOG_LEVELS, Logging::SYSLOG_LEVELS_MAP

Constants included from Purgeable

Purgeable::FN_MATCH_OPTS, Purgeable::HIDDEN_FILE

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Logging

add_outputters, debug_formatter, default_formatter, default_outputter, #logger, #logger_name, parse_level

Methods included from Purgeable

#current_contents, #logger, #matches?, #pending_contents, #potentially_purgeable, #stale_contents

Constructor Details

#initialize(path, sources) ⇒ Basedir

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Basedir.

Parameters:

  • path (String)

    The path to the directory to manage

  • sources (Array<#desired_contents>)

    A list of objects that may create filesystem entries



32
33
34
35
36
37
38
# 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

Class Method Details

.from_deployment(path, deployment) ⇒ R10K::Util::Basedir

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

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

Parameters:

Returns:



25
26
27
28
# 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

Instance Method Details

#desired_contentsArray<String>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Note:

This implements a required method for the Purgeable mixin

List all environments that should exist in this basedir

Returns:

  • (Array<String>)


50
51
52
53
54
# 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_directoriesArray

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Note:

This implements a required method for the Purgeable mixin

Return the path of the basedir

Returns:

  • (Array)


43
44
45
# File 'lib/r10k/util/basedir.rb', line 43

def managed_directories
  [@path]
end

#purge!Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



56
57
58
59
60
61
62
# 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