module Lono::Template::Strategy::Dsl::Builder::Fn

Constants

FUNCTIONS

Also act as documentation on the method signatures Also used in Coder crafting so should always list all the functions here even if they are overriden with specific implementations below

Public Class Methods

define_methods(name, &block) click to toggle source

Defines both normal method and bang method. Example: if and if!

# File lib/lono/template/strategy/dsl/builder/fn.rb, line 33
def self.define_methods(name, &block)
  define_method(name, &block)
  define_method("#{name}!", &block)
end
included(base) click to toggle source
# File lib/lono/template/strategy/dsl/builder/fn.rb, line 130
def self.included(base)
  base.extend(Fn)
end

Public Instance Methods

conditional_ref(name, options) click to toggle source
# File lib/lono/template/strategy/dsl/builder/fn.rb, line 86
def conditional_ref(name, options)
  fallback = options[:Fallback] || options[:fallback] || ref("AWS::NoValue")
  if!("Has#{name}", ref(name, options), fallback)
end
fn() click to toggle source

for fn::if and fn.if to work

# File lib/lono/template/strategy/dsl/builder/fn.rb, line 125
def fn
  Fn
end
fn_id(name) click to toggle source
# File lib/lono/template/strategy/dsl/builder/fn.rb, line 65
def fn_id(name)
  "Fn::#{name.to_s.camelize}"
end
get_att(*item) click to toggle source

Examples:

get_attr("logical_id.attribute")
get_attr("logical_id", "attribute")
get_attr(["logical_id", "attribute"])
# File lib/lono/template/strategy/dsl/builder/fn.rb, line 95
def get_att(*item)
  item = item.flatten
  item.last.is_a?(Hash) ? item.pop : {}

  # list is an Array
  list = if item.size == 1
            item.first.split('.')
          else
            item
          end
  # list.map!(&:camelize) unless options[:autoformat] == false # TODO: maybe add as an option.
  # feel this may be to destructive since am going with auto_camelize false for resources now.
  args = [list[0], list[1..-1].join('.')]
  { "Fn::GetAtt" => args }
end
get_azs(region='') click to toggle source
# File lib/lono/template/strategy/dsl/builder/fn.rb, line 116
def get_azs(region='')
  { "Fn::GetAZs" => region }
end
join(delimiter, *list) click to toggle source
# File lib/lono/template/strategy/dsl/builder/fn.rb, line 111
def join(delimiter, *list)
  list = list.flatten
  { "Fn::Join" => [delimiter, list] }
end
ref(name, options={}) click to toggle source

special cases

# File lib/lono/template/strategy/dsl/builder/fn.rb, line 70
def ref(name, options={})
  name = name.to_s
  conditional = options.delete(:Conditional) || options.delete(:conditional)
  if conditional
    conditional_ref(name, options)
  else
    split_separator = options.delete(:Split) || options.delete(:split)
    if split_separator
      split_separator = ',' if split_separator == true
      split(split_separator, ref(name))
    else
      { "Ref" => name }
    end
  end
end
sub(str, vals={}) click to toggle source
# File lib/lono/template/strategy/dsl/builder/fn.rb, line 120
def sub(str, vals={})
  { "Fn::Sub" => [str, vals] }
end