Class: R10K::Deployment::EnvironmentCollection
- Inherits:
-
Object
- Object
- R10K::Deployment::EnvironmentCollection
- Defined in:
- lib/r10k/deployment/environment_collection.rb
Instance Attribute Summary collapse
-
#update_cache ⇒ Object
readonly
Returns the value of attribute update_cache.
Instance Method Summary collapse
- #current(basedir) ⇒ Object
-
#initialize(config, options = {:update_cache => true}) ⇒ EnvironmentCollection
constructor
A new instance of EnvironmentCollection.
-
#stale(basedir) ⇒ Array<String>
List subdirectories that aren’t associated with an env.
- #to_a ⇒ Array<R10K::Root>
Constructor Details
#initialize(config, options = {:update_cache => true}) ⇒ EnvironmentCollection
Returns a new instance of EnvironmentCollection.
7 8 9 10 11 12 13 |
# File 'lib/r10k/deployment/environment_collection.rb', line 7 def initialize(config, = {:update_cache => true}) @config = config @environments = [] @update_cache = .delete(:update_cache) load_all end |
Instance Attribute Details
#update_cache ⇒ Object (readonly)
Returns the value of attribute update_cache.
5 6 7 |
# File 'lib/r10k/deployment/environment_collection.rb', line 5 def update_cache @update_cache end |
Instance Method Details
#current(basedir) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/r10k/deployment/environment_collection.rb', line 15 def current(basedir) basedir = File.(basedir) tracked_envs = @environments.select do |env| envdir = File.(env.basedir) envdir == basedir end end |
#stale(basedir) ⇒ Array<String>
List subdirectories that aren’t associated with an env
If a branch associated with an environment is deleted then the associated branch ceases to be tracked. This method will scan a directory for subdirectories and return any subdirectories that don’t have an active branch associated.
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/r10k/deployment/environment_collection.rb', line 33 def stale(basedir) basedir = File.(basedir) all_dirs = Dir.glob("#{basedir}/*").map do |file| File.basename(file) if File.directory?(file) end.compact current_dirs = current(basedir).map(&:name) stale_dirs = all_dirs - current_dirs stale_dirs.map {|dir| File.join(basedir, dir)} end |
#to_a ⇒ Array<R10K::Root>
47 48 49 |
# File 'lib/r10k/deployment/environment_collection.rb', line 47 def to_a @environments end |