summaryrefslogtreecommitdiffstats
path: root/lib/puppet/util
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2008-01-19 13:40:40 -0800
committerLuke Kanies <luke@madstop.com>2008-01-19 13:40:40 -0800
commitf98be4a7198326b26f1072c401b3e337f340db40 (patch)
tree36a3f5637a175bc7da7acb639857bf2c2ca9f0c3 /lib/puppet/util
parent2cbab2c6916d6bd7c5ad01b137b3469eeea8d3e4 (diff)
downloadpuppet-f98be4a7198326b26f1072c401b3e337f340db40.tar.gz
puppet-f98be4a7198326b26f1072c401b3e337f340db40.tar.xz
puppet-f98be4a7198326b26f1072c401b3e337f340db40.zip
Fixing #976 -- both the full name of qualified classes and
the class parts are now added as tags. I've also created a Tagging module that we should push throughout the rest of the system that uses tags.
Diffstat (limited to 'lib/puppet/util')
-rw-r--r--lib/puppet/util/tagging.rb34
1 files changed, 34 insertions, 0 deletions
diff --git a/lib/puppet/util/tagging.rb b/lib/puppet/util/tagging.rb
new file mode 100644
index 000000000..25d74c420
--- /dev/null
+++ b/lib/puppet/util/tagging.rb
@@ -0,0 +1,34 @@
+# Created on 2008-01-19
+# Copyright Luke Kanies
+
+# A common module to handle tagging.
+module Puppet::Util::Tagging
+ # Add a tag to our current list. These tags will be added to all
+ # of the objects contained in this scope.
+ def tag(*ary)
+ @tags ||= []
+
+ qualified = []
+
+ ary.collect { |tag| tag.to_s.downcase }.each do |tag|
+ fail(Puppet::ParseError, "Invalid tag %s" % tag.inspect) unless valid_tag?(tag)
+ qualified << tag if tag.include?("::")
+ @tags << tag unless @tags.include?(tag)
+ end
+
+ qualified.collect { |name| name.split("::") }.flatten.each { |tag| @tags << tag unless @tags.include?(tag) }
+ end
+
+ # Return a copy of the tag list, so someone can't ask for our tags
+ # and then modify them.
+ def tags
+ @tags ||= []
+ @tags.dup
+ end
+
+ private
+
+ def valid_tag?(tag)
+ tag =~ /^\w[-\w:]*$/
+ end
+end