Module: Terraspace::Compiler::DirsConcern

Extended by:
ActiveSupport::Concern, Memoist
Included in:
All::Grapher, All::Preview, Builder, Terraspace::CLI::Build::Placeholder, Dependency::Resolver, Terraform::RemoteState::Fetcher, Terraform::RemoteState::Marker::Output, Terraform::Tfc::Syncer
Defined in:
lib/terraspace/compiler/dirs_concern.rb

Instance Method Summary collapse

Instance Method Details

#cache_dirsObject



6
7
8
9
10
11
12
# File 'lib/terraspace/compiler/dirs_concern.rb', line 6

def cache_dirs
  cache_dirs = []
  with_each_mod("stacks") do |mod|
    cache_dirs << mod.cache_dir
  end
  cache_dirs
end

#dirs(path) ⇒ Object



53
54
55
# File 'lib/terraspace/compiler/dirs_concern.rb', line 53

def dirs(path)
  Dir.glob("#{Terraspace.root}/#{path}")
end

#extract_stack_name(path) ⇒ Object



45
46
47
# File 'lib/terraspace/compiler/dirs_concern.rb', line 45

def extract_stack_name(path)
  path.sub(%r{.*(app|vendor)/stacks/}, '')
end

#local_paths(type_dir) ⇒ Object



49
50
51
# File 'lib/terraspace/compiler/dirs_concern.rb', line 49

def local_paths(type_dir)
  dirs("app/#{type_dir}/*") + dirs("vendor/#{type_dir}/*")
end

#mod_names(type_dir) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/terraspace/compiler/dirs_concern.rb', line 22

def mod_names(type_dir)
  names, built = [], []
  local_paths(type_dir).each do |path|
    next unless File.directory?(path)
    next unless select_stack?(type_dir, path)
    mod_name = File.basename(path)
    next if built.include?(mod_name) # ensures modules in app folder take higher precedence than vendor folder
    names << mod_name
  end
  names
end

#select_stack?(type_dir, path) ⇒ Boolean

Examples:

type_dir stacks
path     /home/ec2-user/environment/downloads/infra/app/stacks/demo

Returns:

  • (Boolean)


38
39
40
41
42
43
# File 'lib/terraspace/compiler/dirs_concern.rb', line 38

def select_stack?(type_dir, path)
  return true unless type_dir == "stacks"
  stack_name = extract_stack_name(path)
  select = Terraspace::Compiler::Select.new(stack_name)
  select.selected?
end

#stack_namesObject



57
58
59
# File 'lib/terraspace/compiler/dirs_concern.rb', line 57

def stack_names
  mod_names("stacks")
end

#with_each_mod(type_dir) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/terraspace/compiler/dirs_concern.rb', line 14

def with_each_mod(type_dir)
  mod_names(type_dir).each do |mod_name|
    consider_stacks = type_dir == "stacks"
    mod = Terraspace::Mod.new(mod_name, @options.merge(consider_stacks: consider_stacks))
    yield(mod)
  end
end