Module: AwsCftTools::Template::Metadata

Included in:
AwsCftTools::Template
Defined in:
lib/aws_cft_tools/template/metadata.rb

Overview

Simple derived information about templates.

Constant Summary collapse

CONTENT_TYPES =

Mapping of filename extensions to content types.

{
  '.json' => 'json',
  '.rb' => 'dsl',
  '.yml' => 'yaml',
  '.yaml' => 'yaml'
}.freeze

Instance Method Summary collapse

Instance Method Details

#nameString

The name of the stack built by this template.

Returns:

  • (String)


41
42
43
44
# File 'lib/aws_cft_tools/template/metadata.rb', line 41

def name
  @name ||= @options[:environment] + '-' +
            filename.to_s.sub(/\.(ya?ml|json|rb)$/, '').split(%r{/}).reverse.join('-')
end

#parametersHash

The parsed parameters for this template in the deployment environment.

Returns:

  • (Hash)


66
67
68
# File 'lib/aws_cft_tools/template/metadata.rb', line 66

def parameters
  @parameters ||= parameters_for_filename_and_environment(parameters_source, @options[:environment])
end

#templateHash

The parsed template as a Ruby data structure.

Returns:

  • (Hash)


50
51
52
# File 'lib/aws_cft_tools/template/metadata.rb', line 50

def template
  @template ||= template_content_for_filename(template_file)
end

#template?Boolean

Queries if the template source looks like a CloudFormation template.

Returns:

  • (Boolean)


33
34
35
# File 'lib/aws_cft_tools/template/metadata.rb', line 33

def template?
  template && template['AWSTemplateFormatVersion']
end

#template_source_for_awsString

The JSON or YAML source that can be submitted to AWS to build the stack.

Returns:

  • (String)


58
59
60
# File 'lib/aws_cft_tools/template/metadata.rb', line 58

def template_source_for_aws
  template_type == 'dsl' ? JSON.pretty_generate(template) : template_source
end

#template_typeString

The type of template content.

Returns:

  • (String)

    One of dsl, json, or yaml.



25
26
27
# File 'lib/aws_cft_tools/template/metadata.rb', line 25

def template_type
  content_type(template_file)
end