Module: Puppet::Util::Tagging Private
- Included in:
- Resource, Resource::Catalog, Resource::Status, Transaction, Transaction::Event, Type, Log, SkipTags
- Defined in:
- lib/puppet/util/tagging.rb
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Constant Summary collapse
- ValidTagRegex =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
/\A[[:alnum:]_][[:alnum:]_:.-]*\Z/u
Instance Method Summary collapse
-
#merge_into(tag_set) ⇒ Object
private
Merge the tags of this instance into the provide TagSet.
-
#merge_tags_from(tag_source) ⇒ Object
private
Merge tags from a tagged instance with no attempts to split, downcase or verify the tags.
-
#raw_tagged?(tag_array) ⇒ Boolean
private
Answers if this resource is tagged with at least one of the tags given in downcased string form.
-
#set_tags(tag_source) ⇒ Object
private
Only use this method when copying known tags from one Tagging instance to another.
-
#tag(*ary) ⇒ Object
private
Add a tag to the current tag set.
-
#tag_if_valid(name) ⇒ Object
private
Add a name to the current tag set.
-
#tagged?(*tags) ⇒ Boolean
private
Answers if this resource is tagged with at least one of the given tags.
-
#tags ⇒ Object
private
Return a copy of the tag list, so someone can't ask for our tags and then modify them.
- #tags=(tags) ⇒ Object private
- #valid_tag?(maybe_tag) ⇒ Boolean private
Instance Method Details
#merge_into(tag_set) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Merge the tags of this instance into the provide TagSet
97 98 99 |
# File 'lib/puppet/util/tagging.rb', line 97 def merge_into(tag_set) tag_set.merge(@tags) unless @tags.nil? end |
#merge_tags_from(tag_source) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Merge tags from a tagged instance with no attempts to split, downcase or verify the tags
91 92 93 94 |
# File 'lib/puppet/util/tagging.rb', line 91 def (tag_source) @tags ||= tag_source.merge_into(@tags) end |
#raw_tagged?(tag_array) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
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.
72 73 74 75 |
# File 'lib/puppet/util/tagging.rb', line 72 def raw_tagged?(tag_array) = self. !tag_array.index { |t| .include?(t) }.nil? end |
#set_tags(tag_source) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Only use this method when copying known tags from one Tagging instance to another
78 79 80 |
# File 'lib/puppet/util/tagging.rb', line 78 def (tag_source) @tags = tag_source. end |
#tag(*ary) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
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.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/puppet/util/tagging.rb', line 11 def tag(*ary) @tags ||= ary.flatten.compact.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 @tags.add?(name) # not seen before, so now we test if it is valid if valid_tag?(name) if # avoid adding twice by first testing if the string contains '::' @tags.merge(name.split('::')) if name.include?('::') end else @tags.delete(name) fail(Puppet::ParseError, _("Invalid tag '%{name}'") % { name: name }) end end end end |
#tag_if_valid(name) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
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
43 44 45 46 47 48 49 50 51 |
# File 'lib/puppet/util/tagging.rb', line 43 def tag_if_valid(name) if name.is_a?(String) && valid_tag?(name) name = name.downcase @tags ||= if @tags.add?(name) && name.include?('::') @tags.merge(name.split('::')) end end end |
#tagged?(*tags) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
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.
60 61 62 |
# File 'lib/puppet/util/tagging.rb', line 60 def tagged?(*) raw_tagged?(.collect {|t| t.to_s.downcase}) end |
#tags ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return a copy of the tag list, so someone can't ask for our tags and then modify them.
84 85 86 87 |
# File 'lib/puppet/util/tagging.rb', line 84 def @tags ||= @tags.dup end |
#tags=(tags) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
101 102 103 104 105 106 107 108 |
# File 'lib/puppet/util/tagging.rb', line 101 def () @tags = return if .nil? = .strip.split(/\s*,\s*/) if .is_a?(String) tag(*) end |
#valid_tag?(maybe_tag) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/puppet/util/tagging.rb', line 110 def valid_tag?(maybe_tag) begin tag_enc = maybe_tag.encoding if tag_enc == Encoding::UTF_8 || tag_enc == Encoding::ASCII maybe_tag =~ ValidTagRegex else maybe_tag.encode(Encoding::UTF_8) =~ ValidTagRegex end rescue Encoding::UndefinedConversionError, Encoding::InvalidByteSequenceError false end end |