Module: Puppet::Util::Tagging
- Included in:
- Parser::Resource, Resource, Resource::Catalog, Resource::Status, Transaction, Transaction::Event, Type, Log
- Defined in:
- lib/vendor/puppet/util/tagging.rb
Overview
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
Instance Method Summary collapse
-
#tag(*ary) ⇒ Object
Add a tag to our current list.
-
#tagged?(*tags) ⇒ Boolean
Are we tagged with the provided tag?.
-
#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
#tag(*ary) ⇒ Object
Add a tag to our current list. These tags will be added to all of the objects contained in this scope.
26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/vendor/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 ( qualified ) end |
#tagged?(*tags) ⇒ Boolean
Are we tagged with the provided tag?
41 42 43 |
# File 'lib/vendor/puppet/util/tagging.rb', line 41 def tagged?(*) not ( self. & .flatten.collect { |t| t.to_s } ).empty? end |
#tags ⇒ Object
Return a copy of the tag list, so someone can’t ask for our tags and then modify them.
47 48 49 50 |
# File 'lib/vendor/puppet/util/tagging.rb', line 47 def @tags ||= [] @tags.dup end |