kumogata 0.1.3 → 0.1.4

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,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZGM5NjA4MDkxMGZlOGNlNjZiNGFjZjMwZGU1Mzg5YTg5YWQ5NGEwMQ==
4
+ MmU2ZWQyYmY3MzE5MzRjOTg2OTczZjllYWRlYTAyZTg3YmZlM2NkZA==
5
5
  data.tar.gz: !binary |-
6
- ZDY4YmYzOWUzMzcyMzEwNjZlNjNjMzU2MWEzMWJkZWNjN2JmYjcxMA==
6
+ NjFlZWIzYWYxMjBjODE1YmE3M2ZiYjYxYzdhNjNlYmZkMTRjNTk4OQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- YTgzYzQ4MzA4ZWQyNGNlNmYyZGY1ZjIxODZlNTAxZDIzNDc1ZmVhZmMyYTUw
10
- MDBlNjNmOWJkYWQ3OTE1OTNhZDg3NzNkNWU2MWM2MjBlNDM4NDJmNTQxMmNm
11
- YmIxY2M1ZTJjNjRiNDFiYTUxOTM2NDUwNGIxZGMxMDYyZGI1ZDM=
9
+ ZjNmZjViNTc4ZjlmNDlhY2ViYjFjMDNmMmRkY2Q0MGRmNDYyMDkxNjE5ZTlk
10
+ NDU2MTQ0MzNkMWI5ZDMzNWE5NzIzYmZjNzc1ODQ2YjExMGFhN2Y4M2YzZjc4
11
+ OTIwYWU2YTc5Njc3MWM3Njc3NTY0YzVmNTllYTI4NzMzMDNjZmE=
12
12
  data.tar.gz: !binary |-
13
- ZmZjNTEzZDk4ZTU1YzkyZjAwZGVjNDVhNjYyYjU3YzdjYmRiY2U1N2RjN2Iw
14
- NjA2NmY4ZjExMmM5MmFhYmQzZjI4NDQ4Mzc2YTQ3MmMxNmFhMDM1ZTVlMGE5
15
- M2I1NzgxODlkYzkyY2E0MjdlYmQ2MTFlMGQyNjg4MzAwMTNlODk=
13
+ ZjRjODY4MWI2MTliN2JlNjhiMzc2OWIzYmE4MzE1NGM4ZGU4YTUyMDlmNTI2
14
+ YTY3NWNiZGY1YWNhOTE3Y2VkMjA5NmY1MmNmYzY1YmY5NjFkNzgyYjJhNTI1
15
+ ZGM5ZTU0MDZmZTc5OWU4OGI5ZGEzNGIzNzY4ZmZjZTc3ZTY4ODE=
data/README.md CHANGED
@@ -2,8 +2,8 @@
2
2
 
3
3
  Kumogata is a tool for [AWS CloudFormation](https://aws.amazon.com/cloudformation/).
4
4
 
5
- [![Gem Version](https://badge.fury.io/rb/kumogata.png?201403031324)](http://badge.fury.io/rb/kumogata)
6
- [![Build Status](https://drone.io/github.com/winebarrel/kumogata/status.png?201403031324)](https://drone.io/github.com/winebarrel/kumogata/latest)
5
+ [![Gem Version](https://badge.fury.io/rb/kumogata.png?201403031458)](http://badge.fury.io/rb/kumogata)
6
+ [![Build Status](https://drone.io/github.com/winebarrel/kumogata/status.png?201403031458)](https://drone.io/github.com/winebarrel/kumogata/latest)
7
7
 
8
8
  It can define a template in Ruby DSL, such as:
9
9
 
@@ -116,6 +116,38 @@ JSON template can be converted to Ruby template.
116
116
  * `_path()` creates Hash that has a key of path
117
117
  * `_path("/etc/passwd-s3fs") { content "..." }` => `{"/etc/passwd-s3fs": {"content": "..."}}`
118
118
 
119
+ ### _joine()
120
+
121
+ Ruby templates will be converted as follows by `_join()`:
122
+
123
+ ```ruby
124
+ UserData do
125
+ Fn__Base64 _join(<<-EOS)
126
+ #!/bin/bash,
127
+ /opt/aws/bin/cfn-init -s <%= Ref "AWS::StackId" %> -r myEC2Instance --region <%= Ref "AWS::Region" %>
128
+ EOS
129
+ end
130
+ ```
131
+
132
+ ```javascript
133
+ "Fn::Base64": {
134
+ "Fn::Join": [
135
+ "",
136
+ [
137
+ "#!/bin/bash,\n /opt/aws/bin/cfn-init -s\n",
138
+ {
139
+ "Ref": "AWS::StackId"
140
+ },
141
+ "-r myEC2Instance --region\n",
142
+ {
143
+ "Ref": "AWS::Region"
144
+ },
145
+ "\n"
146
+ ]
147
+ ]
148
+ }
149
+ ```
150
+
119
151
  ## Demo
120
152
 
121
153
  * Create resources
@@ -146,9 +146,46 @@ class Kumogata::Client
146
146
  end
147
147
 
148
148
  def define_template_func(scope)
149
- scope.instance_eval do
150
- def _user_data(data)
151
- data.strip_lines.encode64
149
+ scope.instance_eval(<<-'EOS')
150
+ def _user_data(data, options = {})
151
+ options = {
152
+ :encode => true,
153
+ :strip => true,
154
+ }.merge(options)
155
+
156
+ data = data.strip_lines + "\n" if options[:strip]
157
+ data = data.encode64 if options[:encode]
158
+ return data
159
+ end
160
+
161
+ def _join(data, options = {})
162
+ options = {
163
+ :strip => true,
164
+ :trim_mode => nil,
165
+ }.merge(options)
166
+
167
+
168
+ @__refs__ = []
169
+ def Ref(value); @__refs__ << {"Ref" => value}; "\0"; end
170
+ data = ERB.new(data, nil, options[:trim_mode]).result(binding)
171
+ undef Ref
172
+
173
+ data = data.split("\0").zip(@__refs__)
174
+ @__refs__ = nil
175
+
176
+ data = data.flatten.select {|i| not i.nil? }
177
+
178
+ unless data.last.kind_of?(String) and data.last =~ /\n\Z/
179
+ data << "\n"
180
+ end
181
+
182
+ if options[:strip]
183
+ data = data.map {|i| i.kind_of?(String) ? i.strip + "\n" : i }
184
+ end
185
+
186
+ return {
187
+ "Fn::Join" => ["", data]
188
+ }
152
189
  end
153
190
 
154
191
  def _path(path, value = nil, &block)
@@ -158,7 +195,7 @@ class Kumogata::Client
158
195
 
159
196
  @__hash__[path] = value
160
197
  end
161
- end
198
+ EOS
162
199
  end
163
200
 
164
201
  def create_stack(template, stack_name)
@@ -1,3 +1,3 @@
1
1
  module Kumogata
2
- VERSION = '0.1.3'
2
+ VERSION = '0.1.4'
3
3
  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.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Genki Sugawara