Module: Lono::Template::Dsl::Builder::Fn
Constant Summary collapse
- 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
{ base64: :simple, cidr: :array, find_in_map: :array, get_att: :array, # special case # get_azs: :simple, # special map to GetAZs, and default region='' import_value: :simple, # join: :array, # special case select: :array, split: :array, # sub: :array, # special case transform: :simple, # Conditional methods # Most of the condition methods need to be accessed via the modulde # since they are Ruby keywords. So Fn::if , also builder has an fn method # so they can also be called via fn::if and: :array, equals: :array, if: :array, # special case, if is a Ruby keyword not: :array, or: :array, ref: :simple, }
Class Method Summary collapse
-
.define_methods(name, &block) ⇒ Object
Defines both normal method and bang method.
- .included(base) ⇒ Object
Instance Method Summary collapse
-
#fn ⇒ Object
for fn::if and fn.if to work.
- #fn_id(name) ⇒ Object
-
#get_att(*item) ⇒ Object
Examples: get_attr(“logical_id.attribute”) get_attr(“logical_id”, “attribute”) get_attr([“logical_id”, “attribute”]).
- #get_azs(region = '') ⇒ Object
- #join(delimiter, *list) ⇒ Object
-
#ref(name, options = {}) ⇒ Object
special cases.
- #sub(str, vals = {}) ⇒ Object
Class Method Details
.define_methods(name, &block) ⇒ Object
Defines both normal method and bang method. Example: if and if!
33 34 35 36 |
# File 'lib/lono/template/dsl/builder/fn.rb', line 33 def self.define_methods(name, &block) define_method(name, &block) define_method("#{name}!", &block) end |
.included(base) ⇒ Object
118 119 120 |
# File 'lib/lono/template/dsl/builder/fn.rb', line 118 def self.included(base) base.extend(Fn) end |
Instance Method Details
#fn ⇒ Object
for fn::if and fn.if to work
113 114 115 |
# File 'lib/lono/template/dsl/builder/fn.rb', line 113 def fn Fn end |
#fn_id(name) ⇒ Object
65 66 67 |
# File 'lib/lono/template/dsl/builder/fn.rb', line 65 def fn_id(name) "Fn::#{name.to_s.camelize}" end |
#get_att(*item) ⇒ Object
Examples:
get_attr("logical_id.attribute")
get_attr("logical_id", "attribute")
get_attr(["logical_id", "attribute"])
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/lono/template/dsl/builder/fn.rb', line 83 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 = '') ⇒ Object
104 105 106 |
# File 'lib/lono/template/dsl/builder/fn.rb', line 104 def get_azs(region='') { "Fn::GetAZs" => region } end |
#join(delimiter, *list) ⇒ Object
99 100 101 102 |
# File 'lib/lono/template/dsl/builder/fn.rb', line 99 def join(delimiter, *list) list = list.flatten { "Fn::Join" => [delimiter, list] } end |
#ref(name, options = {}) ⇒ Object
special cases
70 71 72 73 74 75 76 77 |
# File 'lib/lono/template/dsl/builder/fn.rb', line 70 def ref(name, ={}) name = name.to_s.camelize if [:Conditional] || [:conditional] if!("Has#{name}", ref(name), ref("AWS::NoValue")) else { "Ref" => name } end end |
#sub(str, vals = {}) ⇒ Object
108 109 110 |
# File 'lib/lono/template/dsl/builder/fn.rb', line 108 def sub(str, vals={}) { "Fn::Sub" => [str, vals] } end |