Class: Stacker::Stack::Template
- Inherits:
-
Component
show all
- Extended by:
- Memoist
- Defined in:
- lib/stacker/stack/template.rb
Defined Under Namespace
Classes: JSONFormatter
Constant Summary
collapse
- FORMAT_VERSION =
'2010-09-09'
Instance Attribute Summary
Attributes inherited from Component
#stack
Instance Method Summary
collapse
Methods inherited from Component
#initialize
Instance Method Details
#diff(*args) ⇒ Object
44
45
46
|
# File 'lib/stacker/stack/template.rb', line 44
def diff *args
Differ.json_diff local, remote, *args
end
|
#dump ⇒ Object
53
54
55
|
# File 'lib/stacker/stack/template.rb', line 53
def dump
write remote
end
|
#exists? ⇒ Boolean
16
17
18
|
# File 'lib/stacker/stack/template.rb', line 16
def exists?
File.exists? path
end
|
#local ⇒ Object
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/stacker/stack/template.rb', line 20
def local
@local ||= begin
if exists?
template = JSON.parse File.read path
template['AWSTemplateFormatVersion'] ||= FORMAT_VERSION
template
else
{}
end
end
rescue JSON::ParserError
raise TemplateSyntaxError.new path
end
|
#remote ⇒ Object
34
35
36
37
38
39
40
41
42
|
# File 'lib/stacker/stack/template.rb', line 34
def remote
@remote ||= JSON.parse client.template
rescue AWS::CloudFormation::Errors::ValidationError => err
if err.message =~ /does not exist/
raise DoesNotExistError.new err.message
else
raise Error.new err.message
end
end
|
#write(value = local) ⇒ Object
49
50
51
|
# File 'lib/stacker/stack/template.rb', line 49
def write value = local
File.write path, JSONFormatter.format(value)
end
|