Sha256: 9b95a72a47a3f8fb0c8118626eee6d615cb5475bff68abb4e226831760c2c004

Contents?: true

Size: 827 Bytes

Versions: 28

Compression:

Stored size: 827 Bytes

Contents

module Terraforming
  module Util
    def apply_template(client, erb)
      ERB.new(open(template_path(erb)).read, nil, "-").result(binding)
    end

    def name_from_tag(resource, default_name)
      name_tag = resource.tags.find { |tag| tag.key == "Name" }
      name_tag ? name_tag.value : default_name
    end

    def normalize_module_name(name)
      name.gsub(/[^a-zA-Z0-9_-]/, "-")
    end

    def template_path(template_name)
      File.join(File.expand_path(File.dirname(__FILE__)), "template", template_name) << ".erb"
    end

    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
  end
end

Version data entries

28 entries across 28 versions & 2 rubygems

Version Path
terraforming-0.5.0 lib/terraforming/util.rb
terraforming-0.4.0 lib/terraforming/util.rb
terraforming-0.3.2 lib/terraforming/util.rb
terraforming-0.3.1 lib/terraforming/util.rb
terraforming-0.3.0 lib/terraforming/util.rb
terraforming-0.2.0 lib/terraforming/util.rb
terraforming-0.1.6 lib/terraforming/util.rb
terraforming-0.1.5 lib/terraforming/util.rb