Class: Jets::Cfn::Template
- Inherits:
-
Object
- Object
- Jets::Cfn::Template
- Includes:
- AwsServices
- Defined in:
- lib/jets/cfn/template.rb
Constant Summary collapse
- @@cache =
Caches reduce filesystem IO calls
{}
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Class Method Summary collapse
- .load_file(path) ⇒ Object
-
.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”).
Instance Method Summary collapse
- #body ⇒ Object
-
#initialize(path, options = {}) ⇒ Template
constructor
A new instance of Template.
- #stack_option ⇒ Object
- #url ⇒ Object
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
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, ={}) @path = path @options = end |
Instance Attribute Details
#path ⇒ Object (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
#body ⇒ Object
12 13 14 |
# File 'lib/jets/cfn/template.rb', line 12 def body @body ||= IO.read(path) end |
#stack_option ⇒ Object
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 |
#url ⇒ Object
16 17 18 |
# File 'lib/jets/cfn/template.rb', line 16 def url @url ||= upload_file_to_s3 end |