Module: SparkleFormation::SparkleAttribute
- Included in:
- SparkleStruct, Translation
- Defined in:
- lib/sparkle_formation/sparkle_attribute.rb
Overview
Provides template helper methods
Instance Method Summary collapse
-
#_and(*args) ⇒ Hash
(also: #and!)
Fn::And generator.
-
#_cf_attr(*args) ⇒ Hash
(also: #_cf_get_att, #get_att!, #attr!)
Fn::GetAtt generator.
-
#_cf_base64(arg) ⇒ Hash
(also: #base64!)
Fn::Base64 generator.
-
#_cf_get_azs(region = nil) ⇒ Hash
(also: #get_azs!, #azs!)
Fn::GetAZs generator.
-
#_cf_join(*args) ⇒ Hash
(also: #join!)
Fn::Join generator.
-
#_cf_map(thing, key, *suffix) ⇒ Hash
(also: #_cf_find_in_map, #find_in_map!, #map!)
Fn::FindInMap generator.
-
#_cf_ref(thing) ⇒ Hash
(also: #_ref, #ref!)
Ref generator.
-
#_cf_select(index, item) ⇒ Hash
(also: #select!)
Fn::Select generator.
-
#_condition(name) ⇒ Hash
(also: #condition!)
Condition generator.
-
#_equals(v1, v2) ⇒ Hash
(also: #equals!)
Fn::Equals generator.
-
#_if(cond, true_value, false_value) ⇒ Hash
(also: #if!)
Fn::If generator.
-
#_not(arg) ⇒ Hash
(also: #not!)
Fn::Not generator.
-
#_on_condition(name) ⇒ SparkleStruct
(also: #on_condition!)
Condition setter.
-
#_or(v1, v2) ⇒ Hash
(also: #or!)
Fn::Or generator.
-
#_platform=(plat) ⇒ TrueClass
Set the destination platform.
-
#_system(command) ⇒ String
(also: #system!)
Execute system command.
- #debian? ⇒ TrueClass, FalseClass
-
#dynamic!(name, *args, &block) ⇒ self
Dynamic insertion helper method.
-
#nest!(template, *args, &block) ⇒ self
Stack nesting helper method.
-
#registry!(name, *args) ⇒ self
Registry insertion helper method.
- #rhel? ⇒ TrueClass, FalseClass
Instance Method Details
#_and(*args) ⇒ Hash Also known as: and!
symbols will be processed and set as condition. strings will be set as condition directly. procs will be evaluated
Fn::And generator
170 171 172 173 174 175 176 177 178 179 180 181 182 |
# File 'lib/sparkle_formation/sparkle_attribute.rb', line 170 def _and(*args) { 'Fn::And' => _array( *args.map{|v| if(v.is_a?(Symbol) || v.is_a?(String)) _condition(v) else v end } ) } end |
#_cf_attr(*args) ⇒ Hash Also known as: _cf_get_att, get_att!, attr!
Fn::GetAtt generator
78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/sparkle_formation/sparkle_attribute.rb', line 78 def _cf_attr(*args) args = args.map do |thing| if(thing.is_a?(Symbol)) _process_key(thing, :force) else thing end end {'Fn::GetAtt' => args} end |
#_cf_base64(arg) ⇒ Hash Also known as: base64!
Fn::Base64 generator
97 98 99 |
# File 'lib/sparkle_formation/sparkle_attribute.rb', line 97 def _cf_base64(arg) {'Fn::Base64' => arg} end |
#_cf_get_azs(region = nil) ⇒ Hash Also known as: get_azs!, azs!
Fn::GetAZs generator
106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/sparkle_formation/sparkle_attribute.rb', line 106 def _cf_get_azs(region=nil) region = case region when Symbol _cf_ref(region) when NilClass '' else region end {'Fn::GetAZs' => region} end |
#_cf_join(*args) ⇒ Hash Also known as: join!
Fn::Join generator
30 31 32 33 34 35 36 37 |
# File 'lib/sparkle_formation/sparkle_attribute.rb', line 30 def _cf_join(*args) = args.detect{|i| i.is_a?(Hash) && i[:options]} || {:options => {}} args.delete() unless(args.size == 1) args = [args] end {'Fn::Join' => [[:options][:delimiter] || '', *args]} end |
#_cf_map(thing, key, *suffix) ⇒ Hash Also known as: _cf_find_in_map, find_in_map!, map!
Fn::FindInMap generator
58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/sparkle_formation/sparkle_attribute.rb', line 58 def _cf_map(thing, key, *suffix) suffix = suffix.map do |item| if(item.is_a?(Symbol)) _process_key(item, :force) else item end end thing = _process_key(thing, :force) if thing.is_a?(Symbol) key = _process_key(key, :force) if key.is_a?(Symbol) {'Fn::FindInMap' => [_process_key(thing), {'Ref' => _process_key(key)}, *suffix]} end |
#_cf_ref(thing) ⇒ Hash Also known as: _ref, ref!
Symbol value will force key processing
Ref generator
45 46 47 48 |
# File 'lib/sparkle_formation/sparkle_attribute.rb', line 45 def _cf_ref(thing) thing = _process_key(thing, :force) if thing.is_a?(Symbol) {'Ref' => thing} end |
#_cf_select(index, item) ⇒ Hash Also known as: select!
Fn::Select generator
125 126 127 128 129 |
# File 'lib/sparkle_formation/sparkle_attribute.rb', line 125 def _cf_select(index, item) index = index.is_a?(Symbol) ? _cf_ref(index) : index item = _cf_ref(item) if item.is_a?(Symbol) {'Fn::Select' => [index, item]} end |
#_condition(name) ⇒ Hash Also known as: condition!
Condition generator
136 137 138 |
# File 'lib/sparkle_formation/sparkle_attribute.rb', line 136 def _condition(name) {'Condition' => name.is_a?(Symbol) ? _process_key(name) : name} end |
#_equals(v1, v2) ⇒ Hash Also known as: equals!
Fn::Equals generator
190 191 192 |
# File 'lib/sparkle_formation/sparkle_attribute.rb', line 190 def _equals(v1, v2) {'Fn::Equals' => _array(v1, v2)} end |
#_if(cond, true_value, false_value) ⇒ Hash Also known as: if!
Fn::If generator
158 159 160 161 |
# File 'lib/sparkle_formation/sparkle_attribute.rb', line 158 def _if(cond, true_value, false_value) cond = cond.is_a?(Symbol) || cond.is_a?(String) ? _condition(cond) : cond {'Fn::If' => _array(cond, true_value, false_value)} end |
#_not(arg) ⇒ Hash Also known as: not!
Fn::Not generator
199 200 201 202 203 204 205 206 |
# File 'lib/sparkle_formation/sparkle_attribute.rb', line 199 def _not(arg) if(arg.is_a?(String) || arg.is_a?(Symbol)) arg = _condition(arg) else arg = _array(arg).first end {'Fn::Not' => [arg]} end |
#_on_condition(name) ⇒ SparkleStruct Also known as: on_condition!
this is used to set a => “Name” into the current context, generally the top level of a resource
Condition setter
147 148 149 |
# File 'lib/sparkle_formation/sparkle_attribute.rb', line 147 def _on_condition(name) _set(*_condition(name).to_a.flatten) end |
#_or(v1, v2) ⇒ Hash Also known as: or!
Fn::Or generator
214 215 216 217 218 219 220 221 222 223 224 225 226 |
# File 'lib/sparkle_formation/sparkle_attribute.rb', line 214 def _or(v1, v2) { 'Fn::Or' => _array( *[v1,v2].map{|v| if(v.is_a?(Symbol) || v.is_a?(String)) _condition(v) else v end } ) } end |
#_platform=(plat) ⇒ TrueClass
Set the destination platform
252 253 254 255 256 |
# File 'lib/sparkle_formation/sparkle_attribute.rb', line 252 def _platform=(plat) @platform || __hashish @platform.clear @platform[plat.to_sym] = true end |
#_system(command) ⇒ String Also known as: system!
Execute system command
233 234 235 |
# File 'lib/sparkle_formation/sparkle_attribute.rb', line 233 def _system(command) ::Kernel.send('`', command) end |
#debian? ⇒ TrueClass, FalseClass
244 245 246 |
# File 'lib/sparkle_formation/sparkle_attribute.rb', line 244 def debian? !!@platform[:debian] end |
#dynamic!(name, *args, &block) ⇒ self
Dynamic insertion helper method
263 264 265 |
# File 'lib/sparkle_formation/sparkle_attribute.rb', line 263 def dynamic!(name, *args, &block) SparkleFormation.insert(name, self, *args, &block) end |
#nest!(template, *args, &block) ⇒ self
Stack nesting helper method
281 282 283 |
# File 'lib/sparkle_formation/sparkle_attribute.rb', line 281 def nest!(template, *args, &block) SparkleFormation.nest(template, self, *args, &block) end |
#registry!(name, *args) ⇒ self
Registry insertion helper method
272 273 274 |
# File 'lib/sparkle_formation/sparkle_attribute.rb', line 272 def registry!(name, *args) SfnRegistry.insert(name, self, *args) end |
#rhel? ⇒ TrueClass, FalseClass
239 240 241 |
# File 'lib/sparkle_formation/sparkle_attribute.rb', line 239 def rhel? !!@platform[:rhel] end |