Module: Puppet::Util::Tagging
- Included in:
- Resource, Resource::Catalog, Resource::Status, Transaction, Transaction::Event, Type, Log
- Defined in:
- lib/puppet/util/tagging.rb
Constant Summary collapse
- ValidTagRegex =
/^[0-9A-Za-z_][0-9A-Za-z_:.-]*$/
Instance Method Summary collapse
-
#merge_into(tag_set) ⇒ Object
Merge the tags of this instance into the provide TagSet.
-
#merge_tags(tag_source) ⇒ Object
Merge tags from a tagged instance with no attempts to split, downcase or verify the tags.
-
#raw_tagged?(tag_array) ⇒ Boolean
Answers if this resource is tagged with at least one of the tags given in downcased string form.
-
#set_tags(tag_source) ⇒ Object
Only use this method when copying known tags from one Tagging instance to another.
-
#tag(*ary) ⇒ Object
Add a tag to the current tag set.
-
#tag_if_valid(name) ⇒ Object
Add a name to the current tag set.
-
#tagged?(*tags) ⇒ Boolean
Answers if this resource is tagged with at least one of the given tags.
-
#tags ⇒ Object
Return a copy of the tag list, so someone can’t ask for our tags and then modify them.
- #tags=(tags) ⇒ Object
Instance Method Details
#merge_into(tag_set) ⇒ Object
Merge the tags of this instance into the provide TagSet
94 95 96 |
# File 'lib/puppet/util/tagging.rb', line 94 def merge_into(tag_set) tag_set.merge() unless .nil? end |
#merge_tags(tag_source) ⇒ Object
Merge tags from a tagged instance with no attempts to split, downcase or verify the tags
88 89 90 91 |
# File 'lib/puppet/util/tagging.rb', line 88 def (tag_source) ||= tag_source.merge_into() end |
#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.
69 70 71 72 |
# File 'lib/puppet/util/tagging.rb', line 69 def raw_tagged?(tag_array) = self. !tag_array.index { |t| .include?(t) }.nil? end |
#set_tags(tag_source) ⇒ Object
Only use this method when copying known tags from one Tagging instance to another
75 76 77 |
# File 'lib/puppet/util/tagging.rb', line 75 def (tag_source) = tag_source. 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.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/puppet/util/tagging.rb', line 10 def tag(*ary) ||= ary.flatten.each do |tag| name = tag.to_s.downcase # Add the tag before testing if it's valid since this means that # we never need to test the same valid tag twice. This speeds things # up since we get a lot of duplicates and rarely fail on bad tags if .add?(name) # not seen before, so now we test if it is valid if name =~ ValidTagRegex # avoid adding twice by first testing if the string contains '::' .merge(name.split('::')) if name.include?('::') else .delete(name) fail(Puppet::ParseError, "Invalid tag '#{name}'") end end end end |
#tag_if_valid(name) ⇒ Object
Add a name to the current tag set. Silently ignore names that does not represent valid tags.
Use this method instead of doing this:
tag(name) if is_valid?(name)
since that results in testing the same string twice
40 41 42 43 44 45 46 47 48 |
# File 'lib/puppet/util/tagging.rb', line 40 def tag_if_valid(name) if name.is_a?(String) && name =~ ValidTagRegex name = name.downcase ||= if .add?(name) && name.include?('::') .merge(name.split('::')) 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.
57 58 59 |
# File 'lib/puppet/util/tagging.rb', line 57 def tagged?(*) raw_tagged?(.collect {|t| t.to_s.downcase}) end |
#tags ⇒ Object
Return a copy of the tag list, so someone can’t ask for our tags and then modify them.
81 82 83 84 |
# File 'lib/puppet/util/tagging.rb', line 81 def ||= .dup end |
#tags=(tags) ⇒ Object
98 99 100 101 102 103 104 105 |
# File 'lib/puppet/util/tagging.rb', line 98 def () = return if .nil? = .strip.split(/\s*,\s*/) if .is_a?(String) tag(*) end |