Class: Covalence::EnvironmentRepository

Inherits:
Object
  • Object
show all
Defined in:
lib/covalence/core/repositories/environment_repository.rb

Class Method Summary collapse

Class Method Details

.find_all(data_store = HieraDB::Client.new(Covalence::CONFIG)) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/covalence/core/repositories/environment_repository.rb', line 9

def find_all(data_store = HieraDB::Client.new(Covalence::CONFIG))
  environments_hash = lookup_environments(data_store)

  environments_hash.map do |environment_name, stack_names|
    stacks = stack_names.map do |stack_name|
      StackRepository.find(data_store, environment_name, stack_name)
    end.compact

    check_all_stacks_valid!(environment_name,
                            stack_names,
                            stacks)

    Environment.new(name: environment_name,
                    stacks: stacks)
  end
end

.find_filtered(task, data_store = HieraDB::Client.new(Covalence::CONFIG)) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/covalence/core/repositories/environment_repository.rb', line 26

def find_filtered(task, data_store = HieraDB::Client.new(Covalence::CONFIG))
  environments_hash = lookup_environments(data_store)
  env_request = task['environment']
  stk_request = task['stack']

  if (env_request.nil? || !environments_hash.has_key?(env_request))
    if RESERVED_NS.include?(env_request)
      return Array.new(1, Environment.new(name: env_request,
                               stacks: stk_request))
    else
      raise "'#{env_request}' not found in environments"
    end
  end

  stacks = nil
  if (!stk_request.nil? && environments_hash[env_request].include?(stk_request))
    stack_list = Array.new(1, stk_request)
    stacks = Array.new(1, StackRepository.find(data_store, env_request, stk_request))
  else
    stack_list = environments_hash[env_request]
    stacks = stack_list.map do |stack_name|
      StackRepository.find(data_store, env_request, stack_name)
    end.compact
  end

  check_all_stacks_valid!(env_request,
                          stack_list,
                          stacks)

  Array.new(1, Environment.new(name: env_request,
                               stacks: stacks))
end

.populate_stack(stack, data_store = HieraDB::Client.new(Covalence::CONFIG)) ⇒ Object



59
60
61
# File 'lib/covalence/core/repositories/environment_repository.rb', line 59

def populate_stack(stack, data_store = HieraDB::Client.new(Covalence::CONFIG))
  StackRepository.populate(data_store, stack)
end