Class: R10K::Environment::Tarball

Inherits:
WithModules show all
Includes:
Util::Purgeable, Util::Setopts
Defined in:
lib/r10k/environment/tarball.rb

Constant Summary

Constants included from Util::Purgeable

Util::Purgeable::FN_MATCH_OPTS, Util::Purgeable::HIDDEN_FILE

Constants included from Logging

Logging::LOG_LEVELS, Logging::SYSLOG_LEVELS_MAP

Instance Attribute Summary collapse

Attributes inherited from WithModules

#moduledir

Attributes inherited from Base

#basedir, #dirname, #loader, #managed_directories, #name, #puppetfile, #puppetfile_name

Instance Method Summary collapse

Methods included from Util::Purgeable

#current_contents, #logger, #managed_directories, #matches?, #pending_contents, #potentially_purgeable, #purge!, #stale_contents

Methods included from Logging

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

Methods inherited from WithModules

#accept, #add_module, #cleanpath, #deploy, #load_modules, #module_conflicts?, #modules, #purge_exclusions, #resolve_path, #validate_install_path

Methods inherited from Base

#accept, #deploy, #determine_purge_exclusions, #generate_types!, #info, #load_puppetfile_modules, #module_conflicts?, #modules, #purge_exclusions, #whitelist

Constructor Details

#initialize(name, basedir, dirname, options = {}) ⇒ Tarball

Initialize the given tarball environment.

Parameters:

  • name (String)

    The unique name describing this environment.

  • basedir (String)

    The base directory where this environment will be created.

  • dirname (String)

    The directory name for this environment.

  • options (Hash) (defaults to: {})

    An additional set of options for this environment.

  • options (String) (defaults to: {})

    :source Where to get the tarball from

  • options (String) (defaults to: {})

    :version The sha256 digest of the tarball



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/r10k/environment/tarball.rb', line 25

def initialize(name, basedir, dirname, options = {})
  super
  setopts(options, {
    # Standard option interface
    :type      => ::R10K::Util::Setopts::Ignore,
    :source    => :self,
    :version   => :checksum,

    # Type-specific options
    :checksum => :self,
  })

  @tarball = R10K::Tarball.new(name, @source, checksum: @checksum)
end

Instance Attribute Details

#tarballObject (readonly)

Returns the value of attribute tarball.



12
13
14
# File 'lib/r10k/environment/tarball.rb', line 12

def tarball
  @tarball
end

Instance Method Details

#desired_contentsArray<String>

Note:

This implements a required method for the Purgeable mixin

Returns an array of the full paths to all the content being managed.

Returns:

  • (Array<String>)


73
74
75
76
77
# File 'lib/r10k/environment/tarball.rb', line 73

def desired_contents
  desired = []
  desired += @tarball.paths.map { |entry| File.join(@full_path, entry) }
  desired += super
end

#pathObject



40
41
42
# File 'lib/r10k/environment/tarball.rb', line 40

def path
  @path ||= Pathname.new(File.join(@basedir, @dirname))
end

#signatureObject



64
65
66
# File 'lib/r10k/environment/tarball.rb', line 64

def signature
  @checksum || @tarball.cache_checksum
end

#statusObject



54
55
56
57
58
59
60
61
62
# File 'lib/r10k/environment/tarball.rb', line 54

def status
  if not path.exist?
    :absent
  elsif not (tarball.cache_valid? && tarball.insync?(path.to_s, ignore_untracked_files: true))
    :mismatched
  else
    :insync
  end
end

#syncObject



44
45
46
47
48
49
50
51
52
# File 'lib/r10k/environment/tarball.rb', line 44

def sync
  tarball.get unless tarball.cache_valid?
  case status
  when :absent, :mismatched
    tarball.unpack(path.to_s)
    # Untracked files left behind from previous extractions are expected to
    # be deleted by r10k's purge facility.
  end
end