A common module to handle tagging.
So, do you want the bad news or the good news first?
The bad news is that using an array here is hugely costly compared to using a hash. Like, the same speed empty, 50 percent slower with one item, and 300 percent slower at 6 - one of our common peaks for tagging items.
…and that assumes an efficient implementation, just using include?. These methods have even more costs hidden in them.
The good news is that this module has no API. Various objects directly interact with their `@tags` member as an array, or dump it directly in YAML, or whatever.
So, er, you can’t actually change this. No matter how much you want to be cause it is inefficient in both CPU and object allocation terms.
Good luck, my friend. –daniel 2012-07-17
Add a tag to our current list. These tags will be added to all of the objects contained in this scope.
# File lib/puppet/util/tagging.rb, line 26 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
Are we tagged with the provided tag?
# File lib/puppet/util/tagging.rb, line 41 def tagged?(*tags) not ( self.tags & tags.flatten.collect { |t| t.to_s } ).empty? end