Class: Terraspace::Compiler::Select

Inherits:
Object
  • Object
show all
Defined in:
lib/terraspace/compiler/select.rb

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Select

Returns a new instance of Select.



3
4
5
6
# File 'lib/terraspace/compiler/select.rb', line 3

def initialize(path)
  @path = path
  @stack_name = extract_stack_name(path)
end

Instance Method Details

#extract_stack_name(path) ⇒ Object



24
25
26
# File 'lib/terraspace/compiler/select.rb', line 24

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

#selected?Boolean

Returns:

  • (Boolean)


8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/terraspace/compiler/select.rb', line 8

def selected?
  all = Terraspace.config.all
  # Key difference between include_stacks vs all.include_stacks option is that
  # the option can be nil. The local variable is guaranteed to be an Array.
  # This simplifies the logic.
  include_stacks = all.include_stacks || []
  ignore_stacks  = all.ignore_stacks  || []

  if all.include_stacks.nil?
    !ignore_stacks.include?(@stack_name)
  else
    stacks = include_stacks - ignore_stacks
    stacks.include?(@stack_name)
  end
end