stack_master 0.11.0 → 0.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dfd66f0ae759e197674b37f60c86753379a27b3d
4
- data.tar.gz: 6ef5f772326ac2128d0d21667b1aa88cc4f066af
3
+ metadata.gz: 6427d9e4a3e305c6d57efd44e015b5e83a415abe
4
+ data.tar.gz: e9509b938fa0646f8c35571c74278b370c4d4512
5
5
  SHA512:
6
- metadata.gz: fd853147d8aa925242872f9fcc24fa3e79572c6b23a3009a721303126afb0a34b411d18d41b90d2377371155bc61a93557b0367a29d1537a1a7bb30d2f905590
7
- data.tar.gz: 39f780912d2be5c8176b2ae36d185fcd2736ebb3f3448ea89d1629299e2cfc7a9141dd8d4f78e6d45be1b0874c8bf1c53c43b223b34975fd354c73eddeac7cf5
6
+ metadata.gz: d32fa9ae827d12afeef460c724a8db1beac7ef6b645533d621ab2bb5ecfef3e15c4b2a8eec1720a4b6f5f2b184bc1bfb532bac3b56cd0cb08c33609d0117fbad
7
+ data.tar.gz: 2c7dbc03cb04804fb152b5f0040aa68b1d631d874ec3ca620698758de8f3e21b661561598fe14cdacc193d258728d9f6af419c07ab16e0f7a7bfb39b79752b27
@@ -23,24 +23,30 @@ module StackMaster
23
23
  include ::SparkleFormation::SparkleAttribute::Aws
24
24
  include ::SparkleFormation::Utils::TypeCheckers
25
25
 
26
- def self.build(vars)
26
+ def self.build(vars, prefix)
27
27
  ::Class.new(self).tap do |klass|
28
28
  vars.each do |key, value|
29
29
  klass.send(:define_method, key) do
30
30
  value
31
31
  end
32
32
  end
33
- end.new(vars)
33
+
34
+ end.new(vars, prefix)
34
35
  end
35
36
 
36
- def initialize(vars)
37
+ def initialize(vars, prefix)
37
38
  self._camel_keys = true
38
39
  @vars = vars
40
+ @prefix = prefix
39
41
  end
40
42
 
41
43
  def has_var?(var_key)
42
44
  @vars.include?(var_key)
43
45
  end
46
+
47
+ def render(file_name, vars = {})
48
+ Template.render(@prefix, file_name, vars)
49
+ end
44
50
  end
45
51
 
46
52
  # Splits up long strings with multiple lines in them to multiple strings
@@ -80,7 +86,7 @@ module StackMaster
80
86
  def self.render(prefix, file_name, vars)
81
87
  file_path = File.join(::SparkleFormation.sparkle_path, prefix, file_name)
82
88
  template = File.read(file_path)
83
- template_context = TemplateContext.build(vars)
89
+ template_context = TemplateContext.build(vars, prefix)
84
90
  compiled_template = SfEruby.new(template).evaluate(template_context)
85
91
  CloudFormationLineFormatter.format(compiled_template)
86
92
  rescue Errno::ENOENT => e
@@ -1,3 +1,3 @@
1
1
  module StackMaster
2
- VERSION = "0.11.0"
2
+ VERSION = "0.12.0"
3
3
  end
@@ -69,6 +69,44 @@ echo $REGION
69
69
  }.to raise_error(StackMaster::SparkleFormation::TemplateFileNotFound)
70
70
  end
71
71
  end
72
+
73
+ context 'with nested templates' do
74
+ let(:inner_user_data) do
75
+ <<-EOS
76
+ REGION=<%= region! %>
77
+ <%= test1 %>
78
+ <%= has_var?(:test2) ? 'yes' : 'no' %>
79
+ EOS
80
+ end
81
+
82
+ let(:outer_user_data) do
83
+ <<-EOS
84
+ #!/bin/bash
85
+ <%= test1 %> <%= test2 %>
86
+ <%= render 'inner.sh.erb', test1: 'inner1' %>
87
+ EOS
88
+ end
89
+
90
+ let(:expected_hash) do
91
+ {"Fn::Base64"=>{"Fn::Join"=>["", [
92
+ "#!/bin/bash\n",
93
+ "outer1", " ", "outer2", "\n",
94
+ "REGION=", {"Ref"=>"AWS::Region"}, "\n",
95
+ "inner1", "\n",
96
+ "no", "\n", "\n"
97
+ ]]}}
98
+ end
99
+
100
+ before do
101
+ allow(File).to receive(:read).and_call_original
102
+ allow(File).to receive(:read).with('/templates_dir/user_data/outer.sh.erb').and_return(outer_user_data)
103
+ allow(File).to receive(:read).with('/templates_dir/user_data/inner.sh.erb').and_return(inner_user_data)
104
+ end
105
+
106
+ it 'renders the outer template, including the inner template with its own var context' do
107
+ expect(@attr.user_data_file!('outer.sh.erb', test1: :outer1, test2: 'outer2')).to eq expected_hash
108
+ end
109
+ end
72
110
  end
73
111
 
74
112
  RSpec.describe SparkleFormation::SparkleAttribute::Aws, '#joined_file!' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stack_master
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.0
4
+ version: 0.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steve Hodgkiss
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-11-24 00:00:00.000000000 Z
12
+ date: 2016-12-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler