Class: R10K::Deployment::Environment

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/r10k/deployment/environment.rb

Constant Summary

Constants included from Logging

Logging::LOG_LEVELS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logging

formatter, included, level, level=, levels, #logger, #logger_name, outputter, parse_level

Constructor Details

#initialize(ref, remote, basedir, dirname = nil, source_name = "") ⇒ Environment

Returns a new instance of Environment.

Parameters:

  • ref (String)
  • remote (String)
  • basedir (String)
  • dirname (String) (defaults to: nil)

    The directory to clone the root into, defaults to ref

  • source_name (String) (defaults to: "")

    An additional string which may be used with ref to build dirname



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/r10k/deployment/environment.rb', line 31

def initialize(ref, remote, basedir, dirname = nil, source_name = "")
  @ref     = ref
  @remote  = remote
  @basedir = basedir
  alternate_name =  source_name.empty? ? ref : source_name + "_" + ref
  @dirname = sanitize_dirname(dirname || alternate_name)

  @working_dir = R10K::Git::WorkingDir.new(@ref, @remote, @basedir, @dirname)

  @full_path = File.join(@basedir, @dirname)
end

Instance Attribute Details

#basedirObject (readonly)

Returns the value of attribute basedir.



20
21
22
# File 'lib/r10k/deployment/environment.rb', line 20

def basedir
  @basedir
end

#dirnameObject (readonly)

Returns the value of attribute dirname.



24
25
26
# File 'lib/r10k/deployment/environment.rb', line 24

def dirname
  @dirname
end

#refObject (readonly)

Returns the value of attribute ref.



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

def ref
  @ref
end

#remoteObject (readonly)

Returns the value of attribute remote.



16
17
18
# File 'lib/r10k/deployment/environment.rb', line 16

def remote
  @remote
end

Instance Method Details

#modulesObject



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

def modules
  puppetfile.load
  puppetfile.modules
end

#puppetfileObject



59
60
61
# File 'lib/r10k/deployment/environment.rb', line 59

def puppetfile
  @puppetfile ||= R10K::Puppetfile.new(@full_path)
end

#syncObject



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

def sync
  recursive_needed = !(@working_dir.cloned?)
  @working_dir.sync

  if recursive_needed
    logger.debug "Environment #{@full_path} is a fresh clone; automatically updating modules."
    sync_modules
  end
end

#sync_modulesObject



53
54
55
56
57
# File 'lib/r10k/deployment/environment.rb', line 53

def sync_modules
  modules.each do |mod|
    mod.sync
  end
end