diff options
author | Luke Kanies <luke@madstop.com> | 2005-07-11 22:40:23 +0000 |
---|---|---|
committer | Luke Kanies <luke@madstop.com> | 2005-07-11 22:40:23 +0000 |
commit | 01a9905c0c20320a27a646bd7414384be783fdcb (patch) | |
tree | d18fcc9cb1d5035565cdfaaa0fc7cb0e309565e4 /lib | |
parent | fffc09c0703e7903310ff6055ded5ae781d67ecc (diff) | |
download | puppet-01a9905c0c20320a27a646bd7414384be783fdcb.tar.gz puppet-01a9905c0c20320a27a646bd7414384be783fdcb.tar.xz puppet-01a9905c0c20320a27a646bd7414384be783fdcb.zip |
moving namevar translation to a method
git-svn-id: https://reductivelabs.com/svn/puppet/library/trunk@362 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib')
-rw-r--r-- | lib/puppet/type.rb | 48 |
1 files changed, 29 insertions, 19 deletions
diff --git a/lib/puppet/type.rb b/lib/puppet/type.rb index bc54b31cd..eedcbc534 100644 --- a/lib/puppet/type.rb +++ b/lib/puppet/type.rb @@ -249,6 +249,7 @@ class Type < Puppet::Element end if @objects.has_key?(newobj.name) + #p @objects raise "Object '%s' of type '%s' already exists with id '%s' vs. '%s'" % [newobj.name,newobj.class.name, @objects[newobj.name].object_id,newobj.object_id] @@ -443,6 +444,8 @@ class Type < Puppet::Element if @states.include?(mname) @states[mname].should = value else + #Puppet.warning "Creating state %s for %s" % + # [stateklass.name,self.name] @states[mname] = stateklass.new( :parent => self, :should => value @@ -532,24 +535,7 @@ class Type < Puppet::Element hash.delete(:noop) end - # we have to set the name of our object before anything else, - # because it might be used in creating the other states - namevar = self.class.namevar - - # if they're not using :name for the namevar but we got :name (probably - # from the parser) - if namevar != :name and hash.include?(:name) and ! hash[:name].nil? - self[namevar] = hash[:name] - hash.delete(:name) - # else if we got the namevar - elsif hash.has_key?(namevar) and ! hash[namevar].nil? - self[namevar] = hash[namevar] - hash.delete(namevar) - # else something's screwy - else - raise TypeError.new("A name must be provided to %s at initialization time" % - self.class) - end + self.nameclean(hash) hash.each { |param,value| #Puppet.debug("adding param '%s' with value '%s'" % @@ -558,7 +544,7 @@ class Type < Puppet::Element } # add this object to the specific class's list of objects - #Puppet.debug("Adding [%s] to %s" % [self.name,self.class]) + #puts caller self.class[self.name] = self # and then add it to the master list @@ -582,6 +568,30 @@ class Type < Puppet::Element #--------------------------------------------------------------- #--------------------------------------------------------------- + # fix any namevar => param translations + def nameclean(hash) + # we have to set the name of our object before anything else, + # because it might be used in creating the other states + namevar = self.class.namevar + + # if they're not using :name for the namevar but we got :name (probably + # from the parser) + if namevar != :name and hash.include?(:name) and ! hash[:name].nil? + self[namevar] = hash[:name] + hash.delete(:name) + # else if we got the namevar + elsif hash.has_key?(namevar) and ! hash[namevar].nil? + self[namevar] = hash[namevar] + hash.delete(namevar) + # else something's screwy + else + raise TypeError.new("A name must be provided to %s at initialization time" % + self.class) + end + end + #--------------------------------------------------------------- + + #--------------------------------------------------------------- def retrieve # it's important to use the method here, so we always get # them back in the right order |