Module: Lono::Template::Strategy::Dsl::Builder::Fn
- Extended by:
- Fn
- Included in:
- Fn, Section::Base, Syntax
- Defined in:
- lib/lono/template/strategy/dsl/builder/fn.rb
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
- #conditional_ref(name, options) ⇒ Object
-
#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/strategy/dsl/builder/fn.rb', line 33 def self.define_methods(name, &block) define_method(name, &block) define_method("#{name}!", &block) end |
.included(base) ⇒ Object
130 131 132 |
# File 'lib/lono/template/strategy/dsl/builder/fn.rb', line 130 def self.included(base) base.extend(Fn) end |
Instance Method Details
#conditional_ref(name, options) ⇒ Object
86 87 88 89 |
# File 'lib/lono/template/strategy/dsl/builder/fn.rb', line 86 def conditional_ref(name, ) fallback = [:Fallback] || [:fallback] || ref("AWS::NoValue") if!("Has#{name}", ref(name, ), fallback) end |
#fn ⇒ Object
for fn::if and fn.if to work
125 126 127 |
# File 'lib/lono/template/strategy/dsl/builder/fn.rb', line 125 def fn Fn end |
#fn_id(name) ⇒ Object
65 66 67 |
# File 'lib/lono/template/strategy/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"])
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# 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 = '') ⇒ Object
116 117 118 |
# File 'lib/lono/template/strategy/dsl/builder/fn.rb', line 116 def get_azs(region='') { "Fn::GetAZs" => region } end |
#join(delimiter, *list) ⇒ Object
111 112 113 114 |
# 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 = {}) ⇒ Object
special cases
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/lono/template/strategy/dsl/builder/fn.rb', line 70 def ref(name, ={}) name = name.to_s conditional = .delete(:Conditional) || .delete(:conditional) if conditional conditional_ref(name, ) else split_separator = .delete(:Split) || .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 = {}) ⇒ Object
120 121 122 |
# File 'lib/lono/template/strategy/dsl/builder/fn.rb', line 120 def sub(str, vals={}) { "Fn::Sub" => [str, vals] } end |