Module: SparkleFormation::SparkleAttribute

Included in:
SparkleStruct, Translation
Defined in:
lib/sparkle_formation/sparkle_attribute.rb

Overview

Provides template helper methods

Instance Method Summary collapse

Instance Method Details

#_and(*args) ⇒ Hash Also known as: and!

Note:

symbols will be processed and set as condition. strings will be set as condition directly. procs will be evaluated

Fn::And generator

Parameters:

  • args (Object)

Returns:

  • (Hash)


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

Parameters:

  • pass (Object)

    through arguments

Returns:

  • (Hash)


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

Parameters:

  • arg (Object)

    pass through

Returns:

  • (Hash)


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

Parameters:

  • region (String, Symbol) (defaults to: nil)

    String will pass through. Symbol will be converted to ref

Returns:

  • (Hash)


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

Parameters:

  • args (Object)

Returns:

  • (Hash)


30
31
32
33
34
35
36
37
# File 'lib/sparkle_formation/sparkle_attribute.rb', line 30

def _cf_join(*args)
  options = args.detect{|i| i.is_a?(Hash) && i[:options]} || {:options => {}}
  args.delete(options)
  unless(args.size == 1)
    args = [args]
  end
  {'Fn::Join' => [options[:options][:delimiter] || '', *args]}
end

#_cf_map(thing, key, *suffix) ⇒ Hash Also known as: _cf_find_in_map, find_in_map!, map!

Fn::FindInMap generator

Parameters:

  • thing (String, Symbol)

    thing to find

  • key (String, Symbol)

    thing to search

  • suffix (Object)

    additional args

Returns:

  • (Hash)


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!

Note:

Symbol value will force key processing

Ref generator

Parameters:

  • thing (String, Symbol)

    reference name

Returns:

  • (Hash)


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

Parameters:

  • index (String, Symbol, Integer)

    Symbol will be converted to ref

  • item (Object, Symbol)

    Symbol will be converted to ref

Returns:

  • (Hash)


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

Parameters:

  • name (String, Symbol)

    symbol will be processed

Returns:

  • (Hash)


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

Parameters:

  • v1 (Object)
  • v2 (Object)

Returns:

  • (Hash)


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

Parameters:

  • cond (String, Symbol)

    symbol will be converted to condition

  • true_value (Object)
  • false_value (Object)

Returns:

  • (Hash)


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

Parameters:

  • arg (Object)

Returns:

  • (Hash)


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!

Note:

this is used to set a => “Name” into the current context, generally the top level of a resource

Condition setter

Parameters:

  • name (String, Symbol)

    condition name

Returns:



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

Parameters:

  • v1 (Object)
  • v2 (Object)

Returns:

  • (Hash)


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

Parameters:

  • plat (String, Symbol)

    one of :rhel or :debian

Returns:

  • (TrueClass)


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

Parameters:

  • command (String)

Returns:

  • (String)

    result



233
234
235
# File 'lib/sparkle_formation/sparkle_attribute.rb', line 233

def _system(command)
  ::Kernel.send('`', command)
end

#debian?TrueClass, FalseClass

Returns:

  • (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

Parameters:

  • name (String, Symbol)

    dynamic name

  • args (Object)

    argument list for dynamic

Returns:

  • (self)


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

Parameters:

  • template (String, Symbol)

    template to nest

  • args (String, Symbol)

    stringified and underscore joined for name

Returns:

  • (self)


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

Parameters:

  • name (String, Symbol)

    name of registry item

  • args (Object)

    argument list for registry

Returns:

  • (self)


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

Returns:

  • (TrueClass, FalseClass)


239
240
241
# File 'lib/sparkle_formation/sparkle_attribute.rb', line 239

def rhel?
  !!@platform[:rhel]
end