Class: Terraspace::Builder::Allow::Base

Inherits:
Object
  • Object
show all
Includes:
App::CallableOption::Concern
Defined in:
lib/terraspace/builder/allow/base.rb

Direct Known Subclasses

Env, Region, Stack

Instance Method Summary collapse

Methods included from App::CallableOption::Concern

#callable_option

Constructor Details

#initialize(mod) ⇒ Base

Returns a new instance of Base.



5
6
7
8
# File 'lib/terraspace/builder/allow/base.rb', line 5

def initialize(mod)
  @mod = mod # Only Region subclass uses @mod but keeping interface same for Env for simplicity
  @stack_name = mod.name
end

Instance Method Details

#allowed?Boolean

Returns:

  • (Boolean)


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

def allowed?
  if allows.nil? && denys.nil?
    true
  elsif denys.nil?
    allows.include?(check_value)
  elsif allows.nil?
    !denys.include?(check_value)
  else
    allows.include?(check_value) && !denys.include?(check_value)
  end
end

#allowsObject



34
35
36
37
38
39
40
# File 'lib/terraspace/builder/allow/base.rb', line 34

def allows
  callable_option(
    config_name: "config.allow.#{config_name}",
    config_value: config.dig(:allow, config_name),
    passed_args: [@stack_name],
  )
end

#check!Object



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/terraspace/builder/allow/base.rb', line 10

def check!
  messages = []
  unless allowed?
    messages << message # message is interface method
  end
  unless messages.empty?
    puts "ERROR: The configs do not allow this.".color(:red)
    puts messages
    exit 1
  end
end

#denysObject



42
43
44
45
46
47
48
# File 'lib/terraspace/builder/allow/base.rb', line 42

def denys
  callable_option(
    config_name: "config.deny.#{config_name}",
    config_value: config.dig(:deny, config_name),
    passed_args: [@stack_name],
  )
end