Class: Jets::Cfn::Template

Inherits:
Object
  • Object
show all
Includes:
AwsServices
Defined in:
lib/jets/cfn/template.rb

Constant Summary collapse

@@cache =

Caches reduce filesystem IO calls

{}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from AwsServices

#apigateway, #aws_lambda, #aws_options, #cfn, #dynamodb, #logs, #s3, #s3_resource, #sns, #sqs, #sts

Methods included from AwsServices::StackStatus

#lookup, #stack_exists?, #stack_in_progress?

Methods included from AwsServices::GlobalMemoist

included

Constructor Details

#initialize(path, options = {}) ⇒ Template

Returns a new instance of Template.



7
8
9
10
# File 'lib/jets/cfn/template.rb', line 7

def initialize(path, options={})
  @path = path
  @options = options
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



5
6
7
# File 'lib/jets/cfn/template.rb', line 5

def path
  @path
end

Class Method Details

.load_file(path) ⇒ Object



64
65
66
67
68
69
70
# File 'lib/jets/cfn/template.rb', line 64

def load_file(path)
  if @@cache[path]
    @@cache[path]
  else
    @@cache[path] = Jets::Util::Yamler.load_file(path).deep_symbolize_keys
  end
end

.lookup_logical_id(template_name, key) ⇒ Object

Jets::Cfn::Template.lookup_logical_id(template_name, key) Jets::Cfn::Template.lookup_logical_id(“api-resources”, “UpApiResource”)



74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/jets/cfn/template.rb', line 74

def lookup_logical_id(template_name, key)
  expr = "#{Jets::Names.templates_folder}/#{template_name}-*"
  template_paths = Dir.glob(expr).sort.to_a
  found_template = template_paths.detect do |path|
    next unless File.file?(path)

    template = Jets::Cfn::Template.load_file(path)
    template[:Outputs].keys.include?(key.to_sym)
  end

  name = File.basename(found_template).sub(/\.yml$/,'')
  name.underscore.camelize # IE: ApiResources1
end

Instance Method Details

#bodyObject



12
13
14
# File 'lib/jets/cfn/template.rb', line 12

def body
  @body ||= IO.read(path)
end

#stack_optionObject



20
21
22
23
24
25
26
# File 'lib/jets/cfn/template.rb', line 20

def stack_option
  if upload_to_s3?
    from_s3
  else
    from_path
  end
end

#urlObject



16
17
18
# File 'lib/jets/cfn/template.rb', line 16

def url
  @url ||= upload_file_to_s3
end