cfndsl 0.0.11 → 0.0.12

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,5 @@
1
1
  require 'cfndsl/JSONable'
2
+ require 'cfndsl/names'
2
3
 
3
4
  module CfnDsl
4
5
  class CloudFormationTemplate < JSONable
@@ -75,15 +76,18 @@ module CfnDsl
75
76
  type["Properties"].each_pair do |pname, ptype|
76
77
  if( ptype.instance_of? String )
77
78
  create_klass = CfnDsl::Types.const_get( ptype );
79
+
78
80
  klass.class_eval do
79
- define_method(pname) do |*values, &block|
80
- if( values.length <1 ) then
81
- values.push create_klass.new
81
+ CfnDsl::methodNames(pname) do |method|
82
+ define_method(method) do |*values, &block|
83
+ if( values.length <1 ) then
84
+ values.push create_klass.new
85
+ end
86
+ @Properties ||= {}
87
+ @Properties[pname] ||= CfnDsl::PropertyDefinition.new( *values )
88
+ @Properties[pname].value.instance_eval &block if block
89
+ @Properties[pname].value
82
90
  end
83
- @Properties ||= {}
84
- @Properties[pname] ||= CfnDsl::PropertyDefinition.new( *values )
85
- @Properties[pname].value.instance_eval &block if block
86
- @Properties[pname].value
87
91
  end
88
92
  end
89
93
  else
@@ -91,27 +95,30 @@ module CfnDsl
91
95
  sing_name = CfnDsl::Plurals.singularize( pname )
92
96
  create_klass = CfnDsl::Types.const_get( ptype[0] )
93
97
  klass.class_eval do
94
- define_method(pname) do |*values, &block|
95
- if( values.length < 1 ) then
96
- values.push []
98
+ CfnDsl::methodNames(pname) do |method|
99
+ define_method(method) do |*values, &block|
100
+ if( values.length < 1 ) then
101
+ values.push []
102
+ end
103
+ @Properties ||= {}
104
+ @Properties[pname] ||= PropertyDefinition.new( *values )
105
+ @Properties[pname].value.instance_eval &block if block
106
+ @Properties[pname].value
97
107
  end
98
- @Properties ||= {}
99
- @Properties[pname] ||= PropertyDefinition.new( *values )
100
- @Properties[pname].value.instance_eval &block if block
101
- @Properties[pname].value
102
108
  end
103
109
 
104
- define_method(sing_name) do |value=nil, &block|
105
- @Properties ||= {}
106
- @Properties[pname] ||= PropertyDefinition.new( [] )
107
- if( !value ) then
108
- value = create_klass.new
110
+ CfnDsl::methodNames(sing_name) do |method|
111
+ define_method(method) do |value=nil, &block|
112
+ @Properties ||= {}
113
+ @Properties[pname] ||= PropertyDefinition.new( [] )
114
+ if( !value ) then
115
+ value = create_klass.new
116
+ end
117
+ @Properties[pname].value.push value
118
+ value.instance_eval &block if block
119
+ value
109
120
  end
110
- @Properties[pname].value.push value
111
- value.instance_eval &block if block
112
- value
113
121
  end
114
-
115
122
  end
116
123
  end
117
124
 
@@ -136,13 +143,15 @@ module CfnDsl
136
143
  names.each_pair do |typename,type|
137
144
  if(type) then
138
145
  class_eval do
139
- define_method( typename) do |name,*values,&block|
140
- name = name.to_s
141
- @Resources ||= {}
142
- resource = @Resources[name] ||= type.new(*values)
143
- resource.instance_eval &block if block
144
- resource.instance_variable_set( "@Type", nametypes[typename] )
145
- resource
146
+ CfnDsl::methodNames(typename) do |method|
147
+ define_method(method) do |name,*values,&block|
148
+ name = name.to_s
149
+ @Resources ||= {}
150
+ resource = @Resources[name] ||= type.new(*values)
151
+ resource.instance_eval &block if block
152
+ resource.instance_variable_set( "@Type", nametypes[typename] )
153
+ resource
154
+ end
146
155
  end
147
156
  end
148
157
  end
@@ -2,15 +2,10 @@ require 'cfndsl/Errors'
2
2
  require 'cfndsl/RefCheck'
3
3
 
4
4
  module CfnDsl
5
- module Functions
6
-
7
- def Tag(key, value)
8
- ##
9
- # Equivalent to the CloudFormation template built in tag object
10
- TagDefinition.new(key, value)
11
- end
12
-
13
-
5
+ module Functions
6
+ ##
7
+ # These functions are available anywhere inside
8
+ # a block for a JSONable object.
14
9
  def Ref(value)
15
10
  ##
16
11
  # Equivalent to the CloudFormation template built in function Ref
@@ -174,7 +169,6 @@ module CfnDsl
174
169
  end
175
170
  end
176
171
 
177
-
178
172
  class RefDefinition < JSONable
179
173
  ##
180
174
  # Handles the Ref objects
@@ -186,14 +180,5 @@ module CfnDsl
186
180
  [@Ref]
187
181
  end
188
182
  end
189
-
190
- class TagDefinition < JSONable
191
- #
192
- # Handles the Tag objects
193
- def initialize( key, value )
194
- @Key = key
195
- @Value = value
196
- end
197
- end
198
183
 
199
184
  end
@@ -9,6 +9,14 @@ module CfnDsl
9
9
  dsl_attr_setter :Type, :DependsOn, :DeletionPolicy
10
10
  dsl_content_object :Property, :Metadata
11
11
 
12
+ def addTag(name, value, propagate=nil)
13
+ self.send(:Tag) {
14
+ Key name
15
+ Value value
16
+ PropagateAtLaunch propagate unless propagate.nil?
17
+ }
18
+ end
19
+
12
20
  def get_references()
13
21
  refs = []
14
22
  if @DependsOn then
data/lib/cfndsl/Types.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'yaml'
2
2
  require 'cfndsl/JSONable'
3
3
  require 'cfndsl/Plurals'
4
+ require 'cfndsl/names'
4
5
 
5
6
  module CfnDsl
6
7
  module Types
@@ -63,23 +64,25 @@ module CfnDsl
63
64
  if( attr_type.kind_of? Array ) then
64
65
  klass = CfnDsl::Types.const_get( attr_type[0] )
65
66
  variable = "@#{attr_name}".to_sym
67
+
66
68
  method = CfnDsl::Plurals::singularize(attr_name)
67
69
  methods = attr_name
68
70
 
69
71
  type.class_eval do
70
- define_method(method) do | value=nil, *rest, &block|
71
- value ||= klass.new
72
- x = instance_variable_get( variable )
73
- if( !x ) then
72
+ CfnDsl::methodNames(method) do |method_name|
73
+ define_method(method_name) do | value=nil, *rest, &block|
74
+ value ||= klass.new
75
+ x = instance_variable_get( variable )
76
+ if( !x ) then
74
77
  x = instance_variable_set( variable, [] )
78
+ end
79
+ x.push value
80
+ value.instance_eval &block if block
81
+ value
75
82
  end
76
- x.push value
77
- value.instance_eval &block if block
78
- value
79
83
  end
80
-
81
- type.class_eval do
82
- define_method(methods) do | value, &block |
84
+ CfnDsl::methodNames(methods) do |methods_name|
85
+ define_method(methods_name) do | value, &block |
83
86
  x = instance_variable_get( variable )
84
87
  if( !x ) then
85
88
  x = instance_variable_set( variable, [] )
@@ -98,13 +101,15 @@ module CfnDsl
98
101
  else
99
102
  klass = CfnDsl::Types.const_get( attr_type );
100
103
  variable = "@#{attr_name}".to_sym
101
-
104
+
102
105
  type.class_eval do
103
- define_method(attr_name) do | value=nil, *rest, &block |
104
- value ||= klass.new
105
- instance_variable_set( variable, value )
106
- value.instance_eval &block if block
107
- value
106
+ CfnDsl::methodNames(attr_name) do |method|
107
+ define_method(method) do | value=nil, *rest, &block |
108
+ value ||= klass.new
109
+ instance_variable_set( variable, value )
110
+ value.instance_eval &block if block
111
+ value
112
+ end
108
113
  end
109
114
  end
110
115
  end
data/lib/cfndsl/module.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'cfndsl/Plurals'
2
+ require 'cfndsl/names'
2
3
  class Module
3
4
  private
4
5
  def dsl_attr_setter(*symbols)
@@ -18,8 +19,10 @@ class Module
18
19
  #
19
20
  symbols.each do |symbol|
20
21
  class_eval do
21
- define_method(symbol) do |value|
22
- instance_variable_set( "@#{symbol}", value)
22
+ CfnDsl::methodNames(symbol) do |method|
23
+ define_method(method) do |value|
24
+ instance_variable_set( "@#{symbol}", value)
25
+ end
23
26
  end
24
27
  end
25
28
  end
@@ -53,17 +56,19 @@ class Module
53
56
  pluralvar = "@#{plural}".to_sym
54
57
  definition_class = CfnDsl.const_get( "#{symbol}Definition" )
55
58
  class_eval do
56
- define_method(symbol) do |name,*values,&block|
57
- name = name.to_s
58
- hash = instance_variable_get( pluralvar )
59
- if( ! hash ) then
60
- hash = {}
61
- instance_variable_set( pluralvar, hash )
62
- end
63
- hash[name] ||= definition_class.new(*values)
64
- hash[name].instance_eval &block if block
65
- return hash[name]
66
- end
59
+ CfnDsl::methodNames(symbol) do |method|
60
+ define_method(method) do |name,*values,&block|
61
+ name = name.to_s
62
+ hash = instance_variable_get( pluralvar )
63
+ if( ! hash ) then
64
+ hash = {}
65
+ instance_variable_set( pluralvar, hash )
66
+ end
67
+ hash[name] ||= definition_class.new(*values)
68
+ hash[name].instance_eval &block if block
69
+ return hash[name]
70
+ end
71
+ end
67
72
  end
68
73
  end
69
74
  end
@@ -0,0 +1,12 @@
1
+ module CfnDsl
2
+ ##
3
+ # iterates through the the valid case-insensitive names
4
+ # for "name".
5
+ def self.methodNames(name)
6
+ name_str = name.to_s
7
+ yield name_str.to_sym
8
+ n = name_str.dup
9
+ n[0] = n[0].swapcase
10
+ yield n.to_sym
11
+ end
12
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cfndsl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.11
4
+ version: 0.0.12
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -32,6 +32,7 @@ files:
32
32
  - lib/cfndsl/Outputs.rb
33
33
  - lib/cfndsl/Errors.rb
34
34
  - lib/cfndsl/Plurals.rb
35
+ - lib/cfndsl/names.rb
35
36
  - lib/cfndsl/CloudFormationTemplate.rb
36
37
  - bin/cfndsl
37
38
  homepage: https://github.com/howech/cfndsl
@@ -54,7 +55,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
54
55
  version: '0'
55
56
  requirements: []
56
57
  rubyforge_project:
57
- rubygems_version: 1.8.23
58
+ rubygems_version: 1.8.11
58
59
  signing_key:
59
60
  specification_version: 3
60
61
  summary: AWS Cloudformation DSL