Class: R10K::Deployment::Source

Inherits:
Object
  • Object
show all
Includes:
Util::Purgeable
Defined in:
lib/r10k/deployment/source.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Util::Purgeable

#pending_contents, #purge!, #stale_contents

Constructor Details

#initialize(name, remote, basedir, prefix = nil) ⇒ Source

Returns a new instance of Source.



55
56
57
58
59
60
61
62
63
64
# File 'lib/r10k/deployment/source.rb', line 55

def initialize(name, remote, basedir, prefix = nil)
  @name    = name
  @remote  = remote
  @basedir = basedir
  @prefix = prefix.nil? ? false : prefix

  @cache   = R10K::Git::Cache.generate(@remote)

  load_environments
end

Instance Attribute Details

#basedirObject (readonly)

Returns the value of attribute basedir.



25
26
27
# File 'lib/r10k/deployment/source.rb', line 25

def basedir
  @basedir
end

#environmentsObject (readonly)

Returns the value of attribute environments.



29
30
31
# File 'lib/r10k/deployment/source.rb', line 29

def environments
  @environments
end

#nameObject (readonly)

Returns the value of attribute name.



17
18
19
# File 'lib/r10k/deployment/source.rb', line 17

def name
  @name
end

#remoteObject (readonly)

Returns the value of attribute remote.



21
22
23
# File 'lib/r10k/deployment/source.rb', line 21

def remote
  @remote
end

#sourceString (readonly)

Returns The git remote to use for environments.

Returns:

  • (String)

    The git remote to use for environments



21
# File 'lib/r10k/deployment/source.rb', line 21

attr_reader :remote

Class Method Details

.vivify(name, attrs, prefix = false) ⇒ R10K::Deployment::Source

Create a new source from a hash representation

Parameters:

  • name (String)

    The name of the source

  • opts (Hash)

    The properties to use for the source

  • prefix (true, false) (defaults to: false)

    Whether to prefix the source name to created environments

Returns:

Raises:

  • (ArgumentError)


45
46
47
48
49
50
51
52
53
# File 'lib/r10k/deployment/source.rb', line 45

def self.vivify(name, attrs, prefix = false)
  remote  = (attrs.delete(:remote) || attrs.delete('remote'))
  basedir = (attrs.delete(:basedir) || attrs.delete('basedir'))
  prefix_config = (attrs.delete(:prefix) || attrs.delete('prefix'))
  prefix_outcome = prefix_config.nil? ? prefix : prefix_config

  raise ArgumentError, "Unrecognized attributes for #{self.name}: #{attrs.inspect}" unless attrs.empty?
  new(name, remote, basedir, prefix_outcome)
end

Instance Method Details

#current_contentsObject



77
78
79
80
81
82
83
84
85
# File 'lib/r10k/deployment/source.rb', line 77

def current_contents
  dir = self.managed_directory
  glob_part = @prefix ? @name.to_s() + '_*' : '*'
  glob_exp = File.join(dir, glob_part)

  Dir.glob(glob_exp).map do |fname|
    File.basename fname
  end
end

#desired_contentsArray<String>

Note:

This implements a required method for the Purgeable mixin

List all environments that should exist in the basedir for this source

Returns:

  • (Array<String>)


90
91
92
# File 'lib/r10k/deployment/source.rb', line 90

def desired_contents
  @environments.map {|env| env.dirname }
end

#fetch_remoteObject



66
67
68
69
# File 'lib/r10k/deployment/source.rb', line 66

def fetch_remote
  @cache.sync
  load_environments
end

#managed_directoryObject



73
74
75
# File 'lib/r10k/deployment/source.rb', line 73

def managed_directory
  @basedir
end