kumogata 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- ZTg3ZWZjNjE5YzRhM2IwMDVjNDQ1ZDg0ODE3ZmRiMjIyZmZiNjVkZA==
5
- data.tar.gz: !binary |-
6
- MDhhMGQyNjdkZGRhYjc4NDY3MjFmNjVkYTExZmM1ODM5Y2QzMGQ1Nw==
2
+ SHA1:
3
+ metadata.gz: db60c6a575c8c56ed2ba12127b18b12a99ed8574
4
+ data.tar.gz: dcdeb75938b99e1a0a2b0e292eaf98e62591d08c
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- MDc3NWQzOWVlMTc3ODg4OThlMjFkYTg0NDcxNjA2NDVhY2E4M2FlZDJhNTZm
10
- MWFhYWI4ZDA5ZTYwODJmNGY3ZWIzNGFmMjA0NTgxNDA1NTExNmJhZGUxMDJl
11
- YzdkNjEwNmJhZmFjZGNhNmY3MDEzNDM5YTI0Y2QwNmYzOTcyNmE=
12
- data.tar.gz: !binary |-
13
- YmRmNjI1YTk5NjdlNDExMTZmZTY3Yjk3NDc2ZGYzMjdkN2I3M2Q2YmI4OGRk
14
- NDkwOGY4MzEyOWU0MDZmNjQ2ZmFkZGNhYjU0N2VmNzY0NTM2OTVhMzJjYTU1
15
- ZjJmYTZmYWM4NzMyNjQyYmI3ZDU3NTc0ZDk1NjA3NjUyNDI3NTU=
6
+ metadata.gz: 0fd37ebd51c74951cd9e239d788cd4b0cba744a8ab41e6d2d584cb77a889439f439c7c1594f6181c6a866b2bbc103370a0b30f9cf7aedca599fd73333161795a
7
+ data.tar.gz: 31ee88842b7d4d6829972d0e3f45ecf506f40a9090793ccc99a1a6c0de6147f50a1ce032385a18e66a1097e874308743c8e41c5a37f0a81172b3ddb1b09ccd50
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?201403051030)](http://badge.fury.io/rb/kumogata)
9
- [![Build Status](https://drone.io/github.com/winebarrel/kumogata/status.png?201403051030)](https://drone.io/github.com/winebarrel/kumogata/latest)
8
+ [![Gem Version](https://badge.fury.io/rb/kumogata.png?201403051942)](http://badge.fury.io/rb/kumogata)
9
+ [![Build Status](https://drone.io/github.com/winebarrel/kumogata/status.png?201403051942)](https://drone.io/github.com/winebarrel/kumogata/latest)
10
10
 
11
11
  It can define a template in Ruby DSL, such as:
12
12
 
@@ -163,6 +163,48 @@ end
163
163
  }
164
164
  ```
165
165
 
166
+ ### Split of configuration
167
+
168
+ * template.rb
169
+
170
+ ```ruby
171
+ Resources do
172
+ require 'template2'
173
+ end
174
+ ```
175
+
176
+ * template2.rb
177
+
178
+ ```ruby
179
+ myEC2Instance do
180
+ Type "AWS::EC2::Instance"
181
+ Properties do
182
+ ImageId "ami-XXXXXXXX"
183
+ InstanceType { Ref "InstanceType" }
184
+ KeyName "your_key_name"
185
+ end
186
+ end
187
+ ```
188
+
189
+ * Converted JSON template
190
+
191
+ ```javascript
192
+ {
193
+ "Resources": {
194
+ "myEC2Instance": {
195
+ "Type": "AWS::EC2::Instance",
196
+ "Properties": {
197
+ "ImageId": "ami-XXXXXXXX",
198
+ "InstanceType": {
199
+ "Ref": "InstanceType"
200
+ },
201
+ "KeyName": "your_key_name"
202
+ }
203
+ }
204
+ }
205
+ }
206
+ ```
207
+
166
208
  ## Demo
167
209
 
168
210
  * Create resources
@@ -107,7 +107,9 @@ class Kumogata::Client
107
107
  Dslh.eval(template.read, {
108
108
  :key_conv => key_converter,
109
109
  :value_conv => value_converter,
110
- :scope_hook => method(:define_template_func),
110
+ :scope_hook => proc {|scope|
111
+ define_template_func(scope, template.path)
112
+ },
111
113
  :filename => template.path,
112
114
  })
113
115
  end
@@ -145,8 +147,28 @@ class Kumogata::Client
145
147
  Dslh.deval(template, :key_conv => key_conv, :value_conv => value_conv, :exclude_key => exclude_key)
146
148
  end
147
149
 
148
- def define_template_func(scope)
149
- scope.instance_eval(<<-'EOS')
150
+ def define_template_func(scope, path_or_url)
151
+ scope.instance_eval(<<-EOS)
152
+ def require(path)
153
+ unless path =~ %r|\\A/| or path =~ %r|\\A\\w+://|
154
+ path = File.expand_path(File.join(File.dirname(#{path_or_url.inspect}), path))
155
+ end
156
+
157
+ begin
158
+ if File.exist?(path + '.rb')
159
+ open(path + '.rb') {|f| instance_eval(f.read) }
160
+ else
161
+ open(path) {|f| instance_eval(f.read) }
162
+ end
163
+ rescue => e
164
+ begin
165
+ Kernel.require(file)
166
+ rescue
167
+ raise e
168
+ end
169
+ end
170
+ end
171
+
150
172
  def _path(path, value = nil, &block)
151
173
  if block
152
174
  value = Dslh::ScopeBlock.nest(binding, 'block')
@@ -1,3 +1,3 @@
1
1
  module Kumogata
2
- VERSION = '0.2.3'
2
+ VERSION = '0.2.4'
3
3
  end
@@ -512,6 +512,62 @@ end
512
512
  }
513
513
  }
514
514
  }
515
+ }
516
+ EOS
517
+ end
518
+
519
+ it 'convert splitted Ruby template to JSON template' do
520
+ json_template = nil
521
+
522
+ part_of_template = <<-EOS
523
+ myEC2Instance do
524
+ Type "AWS::EC2::Instance"
525
+ Properties do
526
+ ImageId "ami-XXXXXXXX"
527
+ InstanceType "t1.micro"
528
+ end
529
+ end
530
+ EOS
531
+
532
+ tempfile(part_of_template, '.rb') do |f|
533
+ template = <<-EOS
534
+ Resources do
535
+ require #{f.path.inspect}
536
+ end
537
+
538
+ Outputs do
539
+ AZ do
540
+ Value do
541
+ Fn__GetAtt "myEC2Instance", "AvailabilityZone"
542
+ end
543
+ end
544
+ end
545
+ EOS
546
+
547
+ json_template = run_client(:convert, :template => template)
548
+ end
549
+
550
+ expect(json_template).to eq((<<-EOS).chomp)
551
+ {
552
+ "Resources": {
553
+ "myEC2Instance": {
554
+ "Type": "AWS::EC2::Instance",
555
+ "Properties": {
556
+ "ImageId": "ami-XXXXXXXX",
557
+ "InstanceType": "t1.micro"
558
+ }
559
+ }
560
+ },
561
+ "Outputs": {
562
+ "AZ": {
563
+ "Value": {
564
+ "Fn::GetAtt": [
565
+ "myEC2Instance",
566
+ "AvailabilityZone"
567
+ ]
568
+ }
569
+ }
570
+ }
515
571
  }
516
572
  EOS
517
573
  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.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Genki Sugawara
@@ -14,140 +14,140 @@ dependencies:
14
14
  name: aws-sdk
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ! '>='
17
+ - - '>='
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ! '>='
24
+ - - '>='
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: dslh
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ! '>='
31
+ - - '>='
32
32
  - !ruby/object:Gem::Version
33
33
  version: 0.2.3
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ! '>='
38
+ - - '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: 0.2.3
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: hashie
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ! '>='
45
+ - - '>='
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ! '>='
52
+ - - '>='
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: highline
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ! '>='
59
+ - - '>='
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ! '>='
66
+ - - '>='
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: json
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ! '>='
73
+ - - '>='
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ! '>='
80
+ - - '>='
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: term-ansicolor
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ! '>='
87
+ - - '>='
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ! '>='
94
+ - - '>='
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: uuidtools
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - ! '>='
101
+ - - '>='
102
102
  - !ruby/object:Gem::Version
103
103
  version: '0'
104
104
  type: :runtime
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - ! '>='
108
+ - - '>='
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: bundler
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - ! '>='
115
+ - - '>='
116
116
  - !ruby/object:Gem::Version
117
117
  version: '0'
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - ! '>='
122
+ - - '>='
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: rake
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
- - - ! '>='
129
+ - - '>='
130
130
  - !ruby/object:Gem::Version
131
131
  version: '0'
132
132
  type: :development
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
- - - ! '>='
136
+ - - '>='
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0'
139
139
  - !ruby/object:Gem::Dependency
140
140
  name: rspec
141
141
  requirement: !ruby/object:Gem::Requirement
142
142
  requirements:
143
- - - ! '>='
143
+ - - '>='
144
144
  - !ruby/object:Gem::Version
145
145
  version: 2.11.0
146
146
  type: :development
147
147
  prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
- - - ! '>='
150
+ - - '>='
151
151
  - !ruby/object:Gem::Version
152
152
  version: 2.11.0
153
153
  description: A tool for AWS CloudFormation. It can define a template in Ruby DSL.
@@ -195,17 +195,17 @@ require_paths:
195
195
  - lib
196
196
  required_ruby_version: !ruby/object:Gem::Requirement
197
197
  requirements:
198
- - - ! '>='
198
+ - - '>='
199
199
  - !ruby/object:Gem::Version
200
200
  version: '0'
201
201
  required_rubygems_version: !ruby/object:Gem::Requirement
202
202
  requirements:
203
- - - ! '>='
203
+ - - '>='
204
204
  - !ruby/object:Gem::Version
205
205
  version: '0'
206
206
  requirements: []
207
207
  rubyforge_project:
208
- rubygems_version: 2.1.11
208
+ rubygems_version: 2.0.14
209
209
  signing_key:
210
210
  specification_version: 4
211
211
  summary: A tool for AWS CloudFormation.
@@ -220,3 +220,4 @@ test_files:
220
220
  - spec/kumogata_update_spec.rb
221
221
  - spec/kumogata_validate_spec.rb
222
222
  - spec/spec_helper.rb
223
+ has_rdoc: