Sha256: e40140901fd2bf64941b61b544ab9d8152705881cd21c871e9e920fd17e0f13f

Contents?: true

Size: 913 Bytes

Versions: 100

Compression:

Stored size: 913 Bytes

Contents

require 'json'

module Convection
  module Model
    ##
    # CloudFormation ResourceTag set
    ##
    class Tags < Hash
      def render
        map do |t|
          {
            'Key' => t[0].to_s,
            'Value' => t[1]
          }
        end
      end
    end

    module Mixin
      ##
      # Add tag helpers to taddable resources
      ##
      module Taggable
        def tags
          @tags ||= Tags.new
        end

        def tag(key, value)
          tags[key] = value
        end

        ## Helper for Asgard
        def immutable_metadata(purpose, target = '')
          tag('immutable_metadata', JSON.generate(
            :purpose => purpose,
            :target => target
          ))
        end

        def render_tags(resource)
          resource.tap do |r|
            r['Properties']['Tags'] = tags.render unless tags.empty?
          end
        end
      end
    end
  end
end

Version data entries

100 entries across 100 versions & 1 rubygems

Version Path
convection-1.1.3 lib/convection/model/mixin/taggable.rb
convection-1.1.2 lib/convection/model/mixin/taggable.rb
convection-1.1.1 lib/convection/model/mixin/taggable.rb
convection-1.1.0 lib/convection/model/mixin/taggable.rb
convection-1.0.7 lib/convection/model/mixin/taggable.rb
convection-1.0.6 lib/convection/model/mixin/taggable.rb
convection-1.0.5 lib/convection/model/mixin/taggable.rb
convection-1.0.4 lib/convection/model/mixin/taggable.rb
convection-1.0.3 lib/convection/model/mixin/taggable.rb
convection-1.0.2 lib/convection/model/mixin/taggable.rb
convection-1.0.1 lib/convection/model/mixin/taggable.rb
convection-1.0.0.pre.beta.10 lib/convection/model/mixin/taggable.rb
convection-1.0.0.pre.beta.9 lib/convection/model/mixin/taggable.rb
convection-1.0.0.pre.beta.8 lib/convection/model/mixin/taggable.rb
convection-1.0.0.pre.beta.7 lib/convection/model/mixin/taggable.rb
convection-1.0.0.pre.beta.6 lib/convection/model/mixin/taggable.rb
convection-1.0.0.pre.beta.4 lib/convection/model/mixin/taggable.rb
convection-1.0.0.pre.beta.1 lib/convection/model/mixin/taggable.rb
convection-0.4.3 lib/convection/model/mixin/taggable.rb
convection-0.4.2 lib/convection/model/mixin/taggable.rb