diff options
| author | Luke Kanies <luke@madstop.com> | 2008-02-12 17:37:51 -0600 |
|---|---|---|
| committer | Luke Kanies <luke@madstop.com> | 2008-02-12 17:37:51 -0600 |
| commit | da78d96cb139db0775e634b2fa4bd9c173752127 (patch) | |
| tree | 4139d3a2011baedb171a8307c4830c5ac3fe3625 /lib/puppet/util | |
| parent | bee9aba2da453151a80c6e1f25f16bec3bfde8d2 (diff) | |
| parent | 3af6827875f4e02b47fe2293280ff9afe811485f (diff) | |
| download | puppet-da78d96cb139db0775e634b2fa4bd9c173752127.tar.gz puppet-da78d96cb139db0775e634b2fa4bd9c173752127.tar.xz puppet-da78d96cb139db0775e634b2fa4bd9c173752127.zip | |
Merge branch '0.24.x'
Conflicts:
CHANGELOG
Diffstat (limited to 'lib/puppet/util')
| -rw-r--r-- | lib/puppet/util/constant_inflector.rb | 14 | ||||
| -rw-r--r-- | lib/puppet/util/graph.rb | 2 | ||||
| -rw-r--r-- | lib/puppet/util/settings.rb | 35 | ||||
| -rw-r--r-- | lib/puppet/util/tagging.rb | 39 |
4 files changed, 73 insertions, 17 deletions
diff --git a/lib/puppet/util/constant_inflector.rb b/lib/puppet/util/constant_inflector.rb new file mode 100644 index 000000000..8b083951f --- /dev/null +++ b/lib/puppet/util/constant_inflector.rb @@ -0,0 +1,14 @@ +# Created on 2008-02-12 +# Copyright Luke Kanies + +# A common module for converting between constants and +# file names. +module Puppet::Util::ConstantInflector + def file2constant(file) + file.split("/").collect { |name| name.capitalize }.join("::").gsub(/_+(.)/) { |term| $1.capitalize } + end + + def constant2file(constant) + constant.to_s.gsub(/([a-z])([A-Z])/) { |term| $1 + "_" + $2 }.gsub("::", "/").downcase + end +end diff --git a/lib/puppet/util/graph.rb b/lib/puppet/util/graph.rb index a9744578b..d1ef36f8e 100644 --- a/lib/puppet/util/graph.rb +++ b/lib/puppet/util/graph.rb @@ -16,7 +16,7 @@ module Puppet::Util::Graph self.each do |child| unless block_given? and ! yield(child) - graph.add_edge!(self, child) + graph.add_edge(self, child) if child.respond_to?(:to_graph) child.to_graph(graph, &block) diff --git a/lib/puppet/util/settings.rb b/lib/puppet/util/settings.rb index f87f96980..2c8fc682a 100644 --- a/lib/puppet/util/settings.rb +++ b/lib/puppet/util/settings.rb @@ -421,19 +421,19 @@ class Puppet::Util::Settings objects += add_user_resources(section, obj, done) end + value = obj.value + # Only files are convertable to transportable resources. - if obj.respond_to? :to_transportable - next if value(obj.name) =~ /^\/dev/ - transobjects = obj.to_transportable - transobjects = [transobjects] unless transobjects.is_a? Array - transobjects.each do |trans| - # transportable could return nil - next unless trans - unless done[:file].include? trans.name - @created << trans.name - objects << trans - done[:file][trans.name] = trans - end + next unless obj.respond_to? :to_transportable and transobjects = obj.to_transportable + + transobjects = [transobjects] unless transobjects.is_a? Array + transobjects.each do |trans| + # transportable could return nil + next unless trans + unless done[:file].include? trans.name + @created << trans.name + objects << trans + done[:file][trans.name] = trans end end end @@ -1036,7 +1036,7 @@ Generated on #{Time.now}. # the variable 'dir', or adding a slash at the end. def munge(value) # If it's not a fully qualified path... - if value.is_a?(String) and value !~ /^\$/ and value !~ /^\// + if value.is_a?(String) and value !~ /^\$/ and value !~ /^\// and value != 'false' # Make it one value = File.join(Dir.getwd, value) end @@ -1065,12 +1065,15 @@ Generated on #{Time.now}. def to_transportable type = self.type return nil unless type - path = @parent.value(self.name).split(File::SEPARATOR) - path.shift # remove the leading nil - objects = [] path = self.value + return nil unless path.is_a?(String) + return nil if path =~ /^\/dev/ + return nil if Puppet::Type::File[path] # skip files that are in our global resource list. + + objects = [] + # Skip plain files that don't exist, since we won't be managing them anyway. return nil unless self.name.to_s =~ /dir$/ or File.exist?(path) or self.create obj = Puppet::TransObject.new(path, "file") diff --git a/lib/puppet/util/tagging.rb b/lib/puppet/util/tagging.rb new file mode 100644 index 000000000..9abb3fb2b --- /dev/null +++ b/lib/puppet/util/tagging.rb @@ -0,0 +1,39 @@ +# 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 + + # Are we tagged with the provided tag? + def tagged?(tag) + defined?(@tags) and @tags.include?(tag.to_s) + 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 |
