Module: Terraspace::Cloud::Api::Concern

Extended by:
Memoist
Includes:
Errors, Validate
Included in:
Base
Defined in:
lib/terraspace/cloud/api/concern.rb,
lib/terraspace/cloud/api/concern/errors.rb

Defined Under Namespace

Modules: Errors

Instance Method Summary collapse

Methods included from Validate

#validate

Methods included from Errors

#error_message, #errors?

Instance Method Details

#apiObject



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/terraspace/cloud/api/concern.rb', line 7

def api
  validate("stack", cloud_stack_name)
  @options = @options.merge(
    app: Terraspace.app,
    role: Terraspace.role,
    env: Terraspace.env,
    extra: Terraspace.extra,
    region: region,
    name: cloud_stack_name,
  )
  @options.reject! { |k,v| v.nil? }
  Terraspace::Cloud::Api.new(@options) # @options are CLI options
end

#cloud_stack_nameObject



21
22
23
24
25
26
# File 'lib/terraspace/cloud/api/concern.rb', line 21

def cloud_stack_name
  pattern = Terraspace.config.cloud.stack
  expanded = expander.expansion(pattern) # pattern is a String that contains placeholders for substitutions
  expanded.gsub(%r{-+},'-') # remove double dashes are more. IE: -- -> -
          .sub(/^-+/,'').sub(/-+$/,'') # remove leading and trailing -
end

#expanderObject



32
33
34
# File 'lib/terraspace/cloud/api/concern.rb', line 32

def expander
  Terraspace::Compiler::Expander.autodetect(@mod)
end

#regionObject



28
29
30
# File 'lib/terraspace/cloud/api/concern.rb', line 28

def region
  expander.expansion(":REGION")
end