Sha256: 6dad47750a799049d8ad6518eeff5d6f15fac0a1cd70423b58683a13daf45e1e

Contents?: true

Size: 1.01 KB

Versions: 29

Compression:

Stored size: 1.01 KB

Contents

module Lono::Template::Strategy::Dsl::Builder::Helpers
  module TagsHelper
    def tags(hash={})
      if hash.empty?
        tag_list(@tags) if @tags # when hash is empty, use @tags variable. If not set then return nil
      else
        tag_list(hash)
      end
    end

    def tag_list(hash)
      raise "tags hash cannot be empty" if hash == nil

      if hash.is_a?(Array)
        hash = hash.inject({}) do |h,i|
          i.symbolize_keys!
          h[i[:Key]] = i[:Value]
          h
        end
        return tag_list(hash) # recursive call tag_list to normalized the argument with a Hash
      end

      propagate = hash[:PropagateAtLaunch] # special treatment
      list = hash.map do |k,v|
        h = {Key: k.to_s, Value: v}
        h[:PropagateAtLaunch] = propagate unless propagate.nil?
        h
      end
      list.reject { |h| h[:Key] == "PropagateAtLaunch" }
    end

    def dimensions(hash)
      tag_list(hash).map { |h|
        h[:Name] = h.delete(:Key) || h.delete(:key)
        h
      }
    end
  end
end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
lono-7.5.2 lib/lono/template/strategy/dsl/builder/helpers/tags_helper.rb
lono-7.5.1 lib/lono/template/strategy/dsl/builder/helpers/tags_helper.rb
lono-7.5.0 lib/lono/template/strategy/dsl/builder/helpers/tags_helper.rb
lono-7.4.11 lib/lono/template/strategy/dsl/builder/helpers/tags_helper.rb
lono-7.4.10 lib/lono/template/strategy/dsl/builder/helpers/tags_helper.rb
lono-7.4.9 lib/lono/template/strategy/dsl/builder/helpers/tags_helper.rb
lono-7.4.8 lib/lono/template/strategy/dsl/builder/helpers/tags_helper.rb
lono-7.4.7 lib/lono/template/strategy/dsl/builder/helpers/tags_helper.rb
lono-7.4.6 lib/lono/template/strategy/dsl/builder/helpers/tags_helper.rb
lono-7.4.5 lib/lono/template/strategy/dsl/builder/helpers/tags_helper.rb
lono-7.4.4 lib/lono/template/strategy/dsl/builder/helpers/tags_helper.rb
lono-7.4.3 lib/lono/template/strategy/dsl/builder/helpers/tags_helper.rb
lono-7.4.2 lib/lono/template/strategy/dsl/builder/helpers/tags_helper.rb
lono-7.4.1 lib/lono/template/strategy/dsl/builder/helpers/tags_helper.rb
lono-7.4.0 lib/lono/template/strategy/dsl/builder/helpers/tags_helper.rb
lono-7.3.2 lib/lono/template/strategy/dsl/builder/helpers/tags_helper.rb
lono-7.3.1 lib/lono/template/strategy/dsl/builder/helpers/tags_helper.rb
lono-7.3.0 lib/lono/template/strategy/dsl/builder/helpers/tags_helper.rb
lono-7.2.3 lib/lono/template/strategy/dsl/builder/helpers/tags_helper.rb
lono-7.2.2 lib/lono/template/strategy/dsl/builder/helpers/tags_helper.rb