Class: R10K::Deployment::Source
- Inherits:
-
Object
- Object
- R10K::Deployment::Source
- Includes:
- Util::Purgeable
- Defined in:
- lib/r10k/deployment/source.rb
Instance Attribute Summary collapse
-
#basedir ⇒ Object
readonly
Returns the value of attribute basedir.
-
#environments ⇒ Object
readonly
Returns the value of attribute environments.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#remote ⇒ Object
readonly
Returns the value of attribute remote.
-
#source ⇒ String
readonly
The git remote to use for environments.
Class Method Summary collapse
-
.vivify(name, attrs, prefix = false) ⇒ R10K::Deployment::Source
Create a new source from a hash representation.
Instance Method Summary collapse
- #current_contents ⇒ Object
-
#desired_contents ⇒ Array<String>
List all environments that should exist in the basedir for this source.
- #fetch_remote ⇒ Object
-
#initialize(name, remote, basedir, prefix = nil) ⇒ Source
constructor
A new instance of Source.
- #managed_directory ⇒ Object
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
#basedir ⇒ Object (readonly)
Returns the value of attribute basedir.
25 26 27 |
# File 'lib/r10k/deployment/source.rb', line 25 def basedir @basedir end |
#environments ⇒ Object (readonly)
Returns the value of attribute environments.
29 30 31 |
# File 'lib/r10k/deployment/source.rb', line 29 def environments @environments end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
17 18 19 |
# File 'lib/r10k/deployment/source.rb', line 17 def name @name end |
#remote ⇒ Object (readonly)
Returns the value of attribute remote.
21 22 23 |
# File 'lib/r10k/deployment/source.rb', line 21 def remote @remote end |
#source ⇒ String (readonly)
Returns 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
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_contents ⇒ Object
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_contents ⇒ Array<String>
This implements a required method for the Purgeable mixin
List all environments that should exist in the basedir for this source
90 91 92 |
# File 'lib/r10k/deployment/source.rb', line 90 def desired_contents @environments.map {|env| env.dirname } end |
#fetch_remote ⇒ Object
66 67 68 69 |
# File 'lib/r10k/deployment/source.rb', line 66 def fetch_remote @cache.sync load_environments end |
#managed_directory ⇒ Object
73 74 75 |
# File 'lib/r10k/deployment/source.rb', line 73 def managed_directory @basedir end |