Module: PracticeTerraforming::Util
- Included in:
- Resource::IAMGroupPolicyAttachment, Resource::IAMRole, Resource::IAMUser, Resource::IAMUserPolicyAttachment, Resource::IamPolicyAttachment, Resource::IamRolePolicyAttachment, Resource::S3
- Defined in:
- lib/practice_terraforming/util.rb
Instance Method Summary collapse
- #apply_template(client, erb) ⇒ Object
- #name_from_tag(resource, default_name) ⇒ Object
- #normalize_module_name(name) ⇒ Object
- #prettify_policy(document, breakline: false, unescape: false) ⇒ Object
- #template_path(template_name) ⇒ Object
Instance Method Details
#apply_template(client, erb) ⇒ Object
5 6 7 |
# File 'lib/practice_terraforming/util.rb', line 5 def apply_template(client, erb) ERB.new(open(template_path(erb)).read, nil, "-").result(binding) end |
#name_from_tag(resource, default_name) ⇒ Object
9 10 11 12 |
# File 'lib/practice_terraforming/util.rb', line 9 def name_from_tag(resource, default_name) name_tag = resource..find { |tag| tag.key == "Name" } name_tag ? name_tag.value : default_name end |
#normalize_module_name(name) ⇒ Object
14 15 16 |
# File 'lib/practice_terraforming/util.rb', line 14 def normalize_module_name(name) name.gsub(/[^a-zA-Z0-9_-]/, "-") end |
#prettify_policy(document, breakline: false, unescape: false) ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/practice_terraforming/util.rb', line 22 def prettify_policy(document, breakline: false, unescape: false) json = JSON.pretty_generate(JSON.parse(unescape ? CGI.unescape(document) : document)) if breakline json[-1] != "\n" ? json << "\n" : json else json.strip end end |
#template_path(template_name) ⇒ Object
18 19 20 |
# File 'lib/practice_terraforming/util.rb', line 18 def template_path(template_name) File.join(__dir__, "template", template_name) << ".erb" end |