Sha256: 95629bbe9c20648691551082ac93758bf4770015c29de9a5d6147e747e9d4466

Contents?: true

Size: 803 Bytes

Versions: 1

Compression:

Stored size: 803 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(policy_document, breakline = false)
      json = JSON.pretty_generate(JSON.parse(CGI.unescape(policy_document)))

      if breakline
        json[-1] != "\n" ? json << "\n" : json
      else
        json.strip
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
terraforming-0.1.4 lib/terraforming/util.rb