Module: Puppet::Util::Tagging

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

Overview

A common module to handle tagging.

Instance Method Summary collapse

Instance Method Details

#tag(*ary) ⇒ Object

Add a tag to our current list. These tags will be added to all of the objects contained in this scope.



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/puppet/util/tagging.rb', line 8

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

#tagged?(*tags) ⇒ Boolean

Are we tagged with the provided tag?

Returns:

  • (Boolean)


23
24
25
# File 'lib/puppet/util/tagging.rb', line 23

def tagged?(*tags)
  not ( self.tags & tags.flatten.collect { |t| t.to_s } ).empty?
end

#tagsObject

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



29
30
31
32
# File 'lib/puppet/util/tagging.rb', line 29

def tags
  @tags ||= []
  @tags.dup
end

#tags=(tags) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/puppet/util/tagging.rb', line 34

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