Class: Awshark::CloudFormation::Template
- Inherits:
-
Object
- Object
- Awshark::CloudFormation::Template
- Includes:
- Files
- Defined in:
- lib/awshark/cloud_formation/template.rb
Instance Attribute Summary collapse
-
#bucket ⇒ Object
readonly
Returns the value of attribute bucket.
-
#format ⇒ Object
readonly
Returns the value of attribute format.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#stage ⇒ Object
readonly
Returns the value of attribute stage.
Instance Method Summary collapse
- #body ⇒ Object
- #context ⇒ Object
-
#initialize(path, options = {}) ⇒ Template
constructor
A new instance of Template.
- #size ⇒ Object
- #uploaded? ⇒ Boolean
- #url ⇒ Object
Methods included from Files
Constructor Details
#initialize(path, options = {}) ⇒ Template
Returns a new instance of Template.
11 12 13 14 15 16 17 18 19 |
# File 'lib/awshark/cloud_formation/template.rb', line 11 def initialize(path, = {}) @path = path @bucket_and_path = [:bucket] @bucket = ([:bucket] || '').split('/')[0] @name = [:name] @stage = [:stage] @format = [:format] || 'yaml' end |
Instance Attribute Details
#bucket ⇒ Object (readonly)
Returns the value of attribute bucket.
9 10 11 |
# File 'lib/awshark/cloud_formation/template.rb', line 9 def bucket @bucket end |
#format ⇒ Object (readonly)
Returns the value of attribute format.
9 10 11 |
# File 'lib/awshark/cloud_formation/template.rb', line 9 def format @format end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
9 10 11 |
# File 'lib/awshark/cloud_formation/template.rb', line 9 def name @name end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
8 9 10 |
# File 'lib/awshark/cloud_formation/template.rb', line 8 def path @path end |
#stage ⇒ Object (readonly)
Returns the value of attribute stage.
9 10 11 |
# File 'lib/awshark/cloud_formation/template.rb', line 9 def stage @stage end |
Instance Method Details
#body ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/awshark/cloud_formation/template.rb', line 22 def body return nil if template_path.blank? content = File.read(template_path) content = ERB.new(content).result_with_hash(context) if format == 'json' json = parse_string(template_path, content) return JSON.pretty_generate(json) end content end |
#context ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/awshark/cloud_formation/template.rb', line 37 def context @context ||= begin context = parse_file(context_path) || {} context = context[stage] if context.key?(stage) { context: RecursiveOpenStruct.new(context), aws_account_id: Awshark.config.sts.aws_account_id, stage: stage, ssm: ssm } end end |
#size ⇒ Object
53 54 55 |
# File 'lib/awshark/cloud_formation/template.rb', line 53 def size body.size end |
#uploaded? ⇒ Boolean
58 59 60 |
# File 'lib/awshark/cloud_formation/template.rb', line 58 def uploaded? @uploaded == true end |
#url ⇒ Object
63 64 65 66 67 |
# File 'lib/awshark/cloud_formation/template.rb', line 63 def url upload unless uploaded? "https://#{bucket}.s3.#{region}.amazonaws.com/#{s3_key}" end |