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

#_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

#_platform=(plat) ⇒ TrueClass

Set the destination platform

Parameters:

  • plat (String, Symbol)

    one of :rhel or :debian

Returns:

  • (TrueClass)


146
147
148
149
150
# File 'lib/sparkle_formation/sparkle_attribute.rb', line 146

def _platform=(plat)
  @platform || __hashish
  @platform.clear
  @platform[plat.to_sym] = true
end

#debian?TrueClass, FalseClass

Returns:

  • (TrueClass, FalseClass)


138
139
140
# File 'lib/sparkle_formation/sparkle_attribute.rb', line 138

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)


157
158
159
# File 'lib/sparkle_formation/sparkle_attribute.rb', line 157

def dynamic!(name, *args, &block)
  SparkleFormation.insert(name, 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)


166
167
168
# File 'lib/sparkle_formation/sparkle_attribute.rb', line 166

def registry!(name, *args)
  SfnRegistry.insert(name, self, *args)
end

#rhel?TrueClass, FalseClass

Returns:

  • (TrueClass, FalseClass)


133
134
135
# File 'lib/sparkle_formation/sparkle_attribute.rb', line 133

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