Class: R10K::Deployment::EnvironmentCollection

Inherits:
Object
  • Object
show all
Defined in:
lib/r10k/deployment/environment_collection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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, options = {:update_cache => true})
  @config       = config
  @environments = []

  @update_cache = options.delete(:update_cache)
  load_all
end

Instance Attribute Details

#update_cacheObject (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.expand_path(basedir)
  tracked_envs = @environments.select do |env|
    envdir = File.expand_path(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.

Parameters:

  • basedir (String)

    The directory to scan

Returns:

  • (Array<String>)

    A list of filenames



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.expand_path(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_aArray<R10K::Root>

Returns:



47
48
49
# File 'lib/r10k/deployment/environment_collection.rb', line 47

def to_a
  @environments
end