Module: Puppet::Util::Tagging

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

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.



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

def tag(*ary)
  @tags ||= new_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)


21
22
23
# File 'lib/puppet/util/tagging.rb', line 21

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.



27
28
29
30
# File 'lib/puppet/util/tagging.rb', line 27

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

#tags=(tags) ⇒ Object



32
33
34
35
36
37
38
39
40
# File 'lib/puppet/util/tagging.rb', line 32

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