Module: SparkleFormation::SparkleAttribute
- Included in:
- SparkleStruct, Translation
- Defined in:
- lib/sparkle_formation/sparkle_attribute.rb
Overview
Provides template helper methods
Instance Method Summary collapse
-
#_account_id ⇒ Hash
(also: #account_id!)
Account ID generator.
-
#_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.
-
#_depends_on(*args) ⇒ Array<String>
(also: #depends_on!)
Resource dependency generator.
-
#_equals(v1, v2) ⇒ Hash
(also: #equals!)
Fn::Equals generator.
-
#_if(cond, true_value, false_value) ⇒ Hash
(also: #if!)
Fn::If generator.
-
#_no_value ⇒ String
(also: #no_value!)
No value generator.
-
#_not(arg) ⇒ Hash
(also: #not!)
Fn::Not generator.
-
#_notification_arns ⇒ Hash
(also: #notification_arns!)
Notification ARNs generator.
-
#_on_condition(name) ⇒ SparkleStruct
(also: #on_condition!)
Condition setter.
-
#_or(*args) ⇒ Hash
(also: #or!)
Fn::Or generator.
-
#_platform=(plat) ⇒ TrueClass
Set the destination platform.
-
#_region ⇒ Hash
(also: #region!)
Region generator.
-
#_stack_id ⇒ Hash
(also: #stack_id!)
Stack ID generator.
-
#_stack_name ⇒ Hash
(also: #stack_name!)
Stack name generator.
-
#_stack_output(stack_name, output_name) ⇒ Object
(also: #stack_output!)
Reference output value from nested stack.
-
#_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
-
#taggable? ⇒ TrueClass, FalseClass
Resource can be tagged.
Instance Method Details
#_account_id ⇒ Hash Also known as: account_id!
Account ID generator
240 241 242 |
# File 'lib/sparkle_formation/sparkle_attribute.rb', line 240 def _account_id _ref('AWS::AccountId') end |
#_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
154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/sparkle_formation/sparkle_attribute.rb', line 154 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
62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/sparkle_formation/sparkle_attribute.rb', line 62 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
81 82 83 |
# File 'lib/sparkle_formation/sparkle_attribute.rb', line 81 def _cf_base64(arg) {'Fn::Base64' => arg} end |
#_cf_get_azs(region = nil) ⇒ Hash Also known as: get_azs!, azs!
Fn::GetAZs generator
90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/sparkle_formation/sparkle_attribute.rb', line 90 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
12 13 14 15 16 17 18 19 |
# File 'lib/sparkle_formation/sparkle_attribute.rb', line 12 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
40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/sparkle_formation/sparkle_attribute.rb', line 40 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) if(key.is_a?(Symbol)) key = ref!(key) end {'Fn::FindInMap' => [thing, key, *suffix]} end |
#_cf_ref(thing) ⇒ Hash Also known as: _ref, ref!
Symbol value will force key processing
Ref generator
27 28 29 30 |
# File 'lib/sparkle_formation/sparkle_attribute.rb', line 27 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
109 110 111 112 113 |
# File 'lib/sparkle_formation/sparkle_attribute.rb', line 109 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
120 121 122 |
# File 'lib/sparkle_formation/sparkle_attribute.rb', line 120 def _condition(name) {'Condition' => name.is_a?(Symbol) ? _process_key(name) : name} end |
#_depends_on(*args) ⇒ Array<String> Also known as: depends_on!
Resource dependency generator
265 266 267 |
# File 'lib/sparkle_formation/sparkle_attribute.rb', line 265 def _depends_on(*args) _set('DependsOn', [args].flatten.compact.map{|s| _process_key(s)}) end |
#_equals(v1, v2) ⇒ Hash Also known as: equals!
Fn::Equals generator
174 175 176 |
# File 'lib/sparkle_formation/sparkle_attribute.rb', line 174 def _equals(v1, v2) {'Fn::Equals' => _array(v1, v2)} end |
#_if(cond, true_value, false_value) ⇒ Hash Also known as: if!
Fn::If generator
142 143 144 145 |
# File 'lib/sparkle_formation/sparkle_attribute.rb', line 142 def _if(cond, true_value, false_value) cond = cond.is_a?(Symbol) ? _process_key(cond) : cond {'Fn::If' => _array(cond, true_value, false_value)} end |
#_no_value ⇒ String Also known as: no_value!
No value generator
216 217 218 |
# File 'lib/sparkle_formation/sparkle_attribute.rb', line 216 def _no_value _ref('AWS::NoValue') end |
#_not(arg) ⇒ Hash Also known as: not!
Fn::Not generator
183 184 185 186 187 188 189 190 |
# File 'lib/sparkle_formation/sparkle_attribute.rb', line 183 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 |
#_notification_arns ⇒ Hash Also known as: notification_arns!
Notification ARNs generator
232 233 234 |
# File 'lib/sparkle_formation/sparkle_attribute.rb', line 232 def _notification_arns _ref('AWS::NotificationARNs') 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
131 132 133 |
# File 'lib/sparkle_formation/sparkle_attribute.rb', line 131 def _on_condition(name) _set(*_condition(name).to_a.flatten) end |
#_or(*args) ⇒ Hash Also known as: or!
Fn::Or generator
198 199 200 201 202 203 204 205 206 207 208 209 210 |
# File 'lib/sparkle_formation/sparkle_attribute.rb', line 198 def _or(*args) { 'Fn::Or' => _array( *args.map{|v| if(v.is_a?(Symbol) || v.is_a?(String)) _condition(v) else v end } ) } end |
#_platform=(plat) ⇒ TrueClass
Set the destination platform
316 317 318 319 320 |
# File 'lib/sparkle_formation/sparkle_attribute.rb', line 316 def _platform=(plat) @platform || __hashish @platform.clear @platform[plat.to_sym] = true end |
#_region ⇒ Hash Also known as: region!
Region generator
224 225 226 |
# File 'lib/sparkle_formation/sparkle_attribute.rb', line 224 def _region _ref('AWS::Region') end |
#_stack_id ⇒ Hash Also known as: stack_id!
Stack ID generator
248 249 250 |
# File 'lib/sparkle_formation/sparkle_attribute.rb', line 248 def _stack_id _ref('AWS::StackId') end |
#_stack_name ⇒ Hash Also known as: stack_name!
Stack name generator
256 257 258 |
# File 'lib/sparkle_formation/sparkle_attribute.rb', line 256 def _stack_name _ref('AWS::StackName') end |
#_stack_output(stack_name, output_name) ⇒ Object Also known as: stack_output!
Reference output value from nested stack
274 275 276 |
# File 'lib/sparkle_formation/sparkle_attribute.rb', line 274 def _stack_output(stack_name, output_name) _cf_attr(_process_key(stack_name), "Outputs.#{_process_key(output_name)}") end |
#_system(command) ⇒ String Also known as: system!
Execute system command
283 284 285 |
# File 'lib/sparkle_formation/sparkle_attribute.rb', line 283 def _system(command) ::Kernel.send('`', command) end |
#debian? ⇒ TrueClass, FalseClass
308 309 310 |
# File 'lib/sparkle_formation/sparkle_attribute.rb', line 308 def debian? !!@platform[:debian] end |
#dynamic!(name, *args, &block) ⇒ self
Dynamic insertion helper method
327 328 329 |
# File 'lib/sparkle_formation/sparkle_attribute.rb', line 327 def dynamic!(name, *args, &block) SparkleFormation.insert(name, self, *args, &block) end |
#nest!(template, *args, &block) ⇒ self
Stack nesting helper method
345 346 347 |
# File 'lib/sparkle_formation/sparkle_attribute.rb', line 345 def nest!(template, *args, &block) SparkleFormation.nest(template, self, *args, &block) end |
#registry!(name, *args) ⇒ self
Registry insertion helper method
336 337 338 |
# File 'lib/sparkle_formation/sparkle_attribute.rb', line 336 def registry!(name, *args) SparkleFormation::Registry.insert(name, self, *args) end |
#rhel? ⇒ TrueClass, FalseClass
303 304 305 |
# File 'lib/sparkle_formation/sparkle_attribute.rb', line 303 def rhel? !!@platform[:rhel] end |
#taggable? ⇒ TrueClass, FalseClass
Returns resource can be tagged.
289 290 291 292 293 294 295 296 297 298 299 300 |
# File 'lib/sparkle_formation/sparkle_attribute.rb', line 289 def taggable? if(defined?(SfnAws)) if(self[:type]) resource = SfnAws.lookup(self[:type].gsub('::', '_').downcase) resource && resource[:properties].include?('Tags') else if(self._parent) self._parent.taggable? end end end end |