kumogata 0.1.9 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6b7300b43907200cf152f62177d203af6a1771c9
4
- data.tar.gz: e94419046f5079f0e4b229664dd1e4ddd7772fb9
3
+ metadata.gz: 6dba7edb943ddc60c3ba51b2280ab75963303884
4
+ data.tar.gz: 71da06088335d8104b011df5771a380a6de9f1b0
5
5
  SHA512:
6
- metadata.gz: b8e8307dc2eb200b708bd7f70b68f8cc1b66f2dea90612b690f73b792ef2f214ddeec221f96c5bcc622e4f1b5288a16379aca133c316885a30130a7f1eda4102
7
- data.tar.gz: d0b5242a7b7d944ba0f4867f257cecbf7bb28f1a1853266f48a8a32f3c934ee34fb544b93a5f6b6e02ce28b98b0df3bfa787f63d5b38b455575932aed882d4ca
6
+ metadata.gz: 2f37f6ebd3c5ff220a829e48b99eb1f5c8b506879449876dcbcf9f961324b41dedc3b1f4c925b4fe672469f98bb568d04341c6367d66dea1d1e33a72e46fe781
7
+ data.tar.gz: c1d201f490a069ff328464f796cce66516b8e2159027248dbff67c2942033522108b22c21601523bc757c588a4ae1d044e463040a30449bed78648f458b16964
data/README.md CHANGED
@@ -5,8 +5,8 @@
5
5
 
6
6
  Kumogata is a tool for [AWS CloudFormation](https://aws.amazon.com/cloudformation/).
7
7
 
8
- [![Gem Version](https://badge.fury.io/rb/kumogata.png?201403050015)](http://badge.fury.io/rb/kumogata)
9
- [![Build Status](https://drone.io/github.com/winebarrel/kumogata/status.png?201403050015)](https://drone.io/github.com/winebarrel/kumogata/latest)
8
+ [![Gem Version](https://badge.fury.io/rb/kumogata.png?201403050111)](http://badge.fury.io/rb/kumogata)
9
+ [![Build Status](https://drone.io/github.com/winebarrel/kumogata/status.png?201403050111)](https://drone.io/github.com/winebarrel/kumogata/latest)
10
10
 
11
11
  It can define a template in Ruby DSL, such as:
12
12
 
@@ -115,18 +115,19 @@ JSON template can be converted to Ruby template.
115
115
  * `Fn::GetAtt` => `Fn__GetAtt`
116
116
  * `_{ ... }` is convered to Hash
117
117
  * `SecurityGroups [_{Ref "WebServerSecurityGroup"}]` => `{"SecurityGroups": [{"Ref": "WebServerSecurityGroup"}]}`
118
- * ~~_user_data() creates Base64-encoded UserData~~
119
- * `_user_data()` has been removed
120
118
  * `_path()` creates Hash that has a key of path
121
119
  * `_path("/etc/passwd-s3fs") { content "..." }` => `{"/etc/passwd-s3fs": {"content": "..."}}`
120
+ * ~~_user_data() creates Base64-encoded UserData~~
121
+ * `_user_data()` has been removed
122
+ * `_join()` has been removed
122
123
 
123
- ### _joine()
124
+ ### String#fn_joine()
124
125
 
125
126
  Ruby templates will be converted as follows by `_join()`:
126
127
 
127
128
  ```ruby
128
129
  UserData do
129
- Fn__Base64 _join(<<-EOS)
130
+ Fn__Base64 (<<-EOS).fn_join
130
131
  #!/bin/bash
131
132
  /opt/aws/bin/cfn-init -s <%= Ref "AWS::StackName" %> -r myEC2Instance --region <%= Ref "AWS::Region" %>
132
133
  EOS
@@ -147,35 +147,6 @@ class Kumogata::Client
147
147
 
148
148
  def define_template_func(scope)
149
149
  scope.instance_eval(<<-'EOS')
150
- def _join(data, options = {})
151
- options = {
152
- :undent => true,
153
- :trim_mode => nil,
154
- }.merge(options)
155
-
156
- data = data.undent if options[:undent]
157
-
158
- @__refs__ = []
159
- def Ref(value); @__refs__ << {"Ref" => value}; "\0"; end
160
- data = ERB.new(data, nil, options[:trim_mode]).result(binding)
161
- undef Ref
162
-
163
- data = data.split("\0").zip(@__refs__)
164
- @__refs__ = nil
165
-
166
- data = data.flatten.select {|i| not i.nil? }.map {|i|
167
- if i.kind_of?(String)
168
- StringIO.new(i).to_a
169
- else
170
- i
171
- end
172
- }.flatten
173
-
174
- return {
175
- 'Fn::Join' => ['', data]
176
- }
177
- end
178
-
179
150
  def _path(path, value = nil, &block)
180
151
  if block
181
152
  value = Dslh::ScopeBlock.nest(binding, 'block')
@@ -33,4 +33,34 @@ class String
33
33
  min_space_num = self.split("\n").delete_if{|s| s=~ /^\s*$/ }.map{|s| s[/^\s+/].length }.min
34
34
  gsub(/^[ \t]{,#{min_space_num}}/, '')
35
35
  end
36
+
37
+ def fn_join(options = {})
38
+ options = {
39
+ :undent => true,
40
+ :trim_mode => nil,
41
+ }.merge(options)
42
+
43
+ data = self.dup
44
+ data = data.undent if options[:undent]
45
+ trim_mode = options[:trim_mode]
46
+ null = "\0"
47
+
48
+ data = Object.new.instance_eval(<<-EOS)
49
+ @__refs__ = []
50
+ def Ref(value); @__refs__ << {'Ref' => value}; #{null.inspect}; end
51
+ ERB.new(#{data.inspect}, nil, #{trim_mode.inspect}).result(binding).split(#{null.inspect}).zip(@__refs__)
52
+ EOS
53
+
54
+ data = data.flatten.select {|i| not i.nil? }.map {|i|
55
+ if i.kind_of?(String)
56
+ StringIO.new(i).to_a
57
+ else
58
+ i
59
+ end
60
+ }.flatten
61
+
62
+ return {
63
+ 'Fn::Join' => ['', data]
64
+ }
65
+ end
36
66
  end
@@ -1,3 +1,3 @@
1
1
  module Kumogata
2
- VERSION = '0.1.9'
2
+ VERSION = '0.2.0'
3
3
  end
@@ -94,7 +94,7 @@ end
94
94
  EOS
95
95
  end
96
96
 
97
- it 'convert Ruby template to JSON template with _join()' do
97
+ it 'convert Ruby template to JSON template with fn_join()' do
98
98
  template = <<-TEMPLATE
99
99
  Parameters do
100
100
  Password do
@@ -111,7 +111,7 @@ Resources do
111
111
  InstanceType "t1.micro"
112
112
 
113
113
  UserData do
114
- Fn__Base64 _join(<<-EOS)
114
+ Fn__Base64 (<<-EOS).fn_join
115
115
  #!/bin/bash
116
116
  echo START | logger
117
117
  /opt/aws/bin/cfn-init -s <%= Ref "AWS::StackName" %> -r myEC2Instance --region <%= Ref "AWS::Region" %>
@@ -139,7 +139,7 @@ Resources do
139
139
 
140
140
  commands do
141
141
  any_name do
142
- command _join(<<-EOS)
142
+ command (<<-EOS).fn_join
143
143
  echo <%= Ref "Password" %> > /tmp/my-password
144
144
  EOS
145
145
  end
@@ -233,7 +233,7 @@ end
233
233
  EOS
234
234
  end
235
235
 
236
- it 'convert Ruby template to JSON template with _user_data()' do
236
+ it 'convert Ruby template to JSON template with converting user_data' do
237
237
  template = <<-TEMPLATE
238
238
  Parameters do
239
239
  Password do
@@ -304,7 +304,7 @@ Resources do
304
304
  InstanceType "t1.micro"
305
305
 
306
306
  UserData do
307
- Fn__Base64 _join(<<-EOS)
307
+ Fn__Base64 (<<-EOS).fn_join
308
308
  #!/bin/bash
309
309
  echo START | logger
310
310
  /opt/aws/bin/cfn-init -s <%= Ref "AWS::StackName" %> -r #{resource_name} --region <%= Ref "AWS::Region" %>
@@ -332,7 +332,7 @@ Resources do
332
332
 
333
333
  commands do
334
334
  any_name do
335
- command _join(<<-EOS)
335
+ command (<<-EOS).fn_join
336
336
  echo <%= Ref "Password" %> > /tmp/my-password
337
337
  EOS
338
338
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kumogata
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.9
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Genki Sugawara