Sha256: 536e4f57a41b35d5313257914bc49d703db3a484503a6d3ff13ae06162f523f6

Contents?: true

Size: 1.3 KB

Versions: 46

Compression:

Stored size: 1.3 KB

Contents

# Created on 2008-01-19
# Copyright Luke Kanies

# A common module to handle tagging.
module Puppet::Util::Tagging
  # Add a tag to our current list.  These tags will be added to all
  # of the objects contained in this scope.
  def tag(*ary)
    @tags ||= []

    qualified = []

    ary.collect { |tag| tag.to_s.downcase }.each do |tag|
      fail(Puppet::ParseError, "Invalid tag #{tag.inspect}") unless valid_tag?(tag)
      qualified << tag if tag.include?("::")
      @tags << tag unless @tags.include?(tag)
    end

    handle_qualified_tags( qualified )
  end

  # Are we tagged with the provided tag?
  def tagged?(*tags)
    not ( self.tags & tags.flatten.collect { |t| t.to_s } ).empty?
  end

  # Return a copy of the tag list, so someone can't ask for our tags
  # and then modify them.
  def tags
    @tags ||= []
    @tags.dup
  end

  def tags=(tags)
    @tags = []

    return if tags.nil? or tags == ""

    tags = tags.strip.split(/\s*,\s*/) if tags.is_a?(String)

    tags.each do |t|
      tag(t)
    end
  end

  private

  def handle_qualified_tags( qualified )
    # LAK:NOTE See http://snurl.com/21zf8  [groups_google_com]
    qualified.collect { |name| x = name.split("::") }.flatten.each { |tag| @tags << tag unless @tags.include?(tag) }
  end

  def valid_tag?(tag)
    tag =~ /^\w[-\w:.]*$/
  end
end

Version data entries

46 entries across 46 versions & 3 rubygems

Version Path
puppet-2.6.18 lib/puppet/util/tagging.rb
librarian-puppet-0.9.4 vendor/gems/ruby/1.8/gems/puppet-2.7.18/lib/puppet/util/tagging.rb
puppet-2.7.19 lib/puppet/util/tagging.rb
supply_drop-0.11.0 examples/vendored-puppet/vendor/puppet-2.7.8/lib/puppet/util/tagging.rb
librarian-puppet-0.9.3 vendor/gems/ruby/1.8/gems/puppet-2.7.18/lib/puppet/util/tagging.rb
supply_drop-0.10.2 examples/vendored-puppet/vendor/puppet-2.7.8/lib/puppet/util/tagging.rb
puppet-2.7.18 lib/puppet/util/tagging.rb
puppet-2.6.17 lib/puppet/util/tagging.rb
supply_drop-0.10.1 examples/vendored-puppet/vendor/puppet-2.7.8/lib/puppet/util/tagging.rb
supply_drop-0.10.0 examples/vendored-puppet/vendor/puppet-2.7.8/lib/puppet/util/tagging.rb
puppet-2.7.17 lib/puppet/util/tagging.rb
puppet-2.7.16 lib/puppet/util/tagging.rb
puppet-2.7.14 lib/puppet/util/tagging.rb
puppet-2.6.16 lib/puppet/util/tagging.rb
puppet-2.7.13 lib/puppet/util/tagging.rb
puppet-2.6.15 lib/puppet/util/tagging.rb
supply_drop-0.9.0 examples/vendored-puppet/vendor/puppet-2.7.8/lib/puppet/util/tagging.rb
supply_drop-0.8.1 examples/vendored-puppet/vendor/puppet-2.7.8/lib/puppet/util/tagging.rb
supply_drop-0.8.0 examples/vendored-puppet/vendor/puppet-2.7.8/lib/puppet/util/tagging.rb
puppet-2.7.12 lib/puppet/util/tagging.rb