Module: Puppet::Util::Tagging

Included in:
Resource, Resource::Catalog, Resource::Status, Transaction, Transaction::Event, Type, Log
Defined in:
lib/puppet/util/tagging.rb

Overview

API:

  • public

Constant Summary collapse

ValidTagRegex =

API:

  • public

/^\w[-\w:.]*$/

Instance Method Summary collapse

Instance Method Details

#raw_tagged?(tag_array) ⇒ Boolean

Answers if this resource is tagged with at least one of the tags given in downcased string form.

The method is a faster variant of the tagged? method that does no conversion of its arguments.

Parameters:

  • array of tags to look for

Returns:

  • true if this instance is tagged with at least one of the provided tags

API:

  • public



47
48
49
50
# File 'lib/puppet/util/tagging.rb', line 47

def raw_tagged?(tag_array)
  my_tags = self.tags
  !tag_array.index { |t| my_tags.include?(t) }.nil?
end

#tag(*ary) ⇒ Object

Add a tag to the current tag set. When a tag set is used for a scope, these tags will be added to all of the objects contained in this scope when the objects are finished.

API:

  • public



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/puppet/util/tagging.rb', line 10

def tag(*ary)
  @tags ||= new_tags

  ary.flatten.each do |tag|
    name = tag.to_s.downcase
    if name =~ ValidTagRegex
      @tags << name
      if split_qualified_tags?
        name.split("::").each do |section|
          @tags << section
        end
      end
    else
      fail(Puppet::ParseError, "Invalid tag '#{name}'")
    end
  end
end

#tagged?(*tags) ⇒ Boolean

Answers if this resource is tagged with at least one of the given tags.

The given tags are converted to downcased strings before the match is performed.

Parameters:

  • splat of tags to look for

Returns:

  • true if this instance is tagged with at least one of the provided tags

API:

  • public



35
36
37
# File 'lib/puppet/util/tagging.rb', line 35

def tagged?(*tags)
  raw_tagged?(tags.collect {|t| t.to_s.downcase})
end

#tagsObject

Return a copy of the tag list, so someone can’t ask for our tags and then modify them.

API:

  • public



54
55
56
57
# File 'lib/puppet/util/tagging.rb', line 54

def tags
  @tags ||= new_tags
  @tags.dup
end

#tags=(tags) ⇒ Object

API:

  • public



59
60
61
62
63
64
65
66
# File 'lib/puppet/util/tagging.rb', line 59

def tags=(tags)
  @tags = new_tags

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

  tags = tags.strip.split(/\s*,\s*/) if tags.is_a?(String)
  tags.each {|t| tag(t) }
end