diff options
author | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-03-09 18:45:51 +0000 |
---|---|---|
committer | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-03-09 18:45:51 +0000 |
commit | 2dbd7e19de0caa683f7e0b4da5654eb15bc419da (patch) | |
tree | 298ac3b9f49804e32fd135842bae38de3b5d4b46 /lib/puppet/parser | |
parent | 7756f9a57fa83e811888298edd339978bb6a9c83 (diff) | |
download | puppet-2dbd7e19de0caa683f7e0b4da5654eb15bc419da.tar.gz puppet-2dbd7e19de0caa683f7e0b4da5654eb15bc419da.tar.xz puppet-2dbd7e19de0caa683f7e0b4da5654eb15bc419da.zip |
Fixing #96. Defaults are now set when the object is passed out by the scope, rather than when the object is created. This is nice because it also moves awareness of the scope internals out of the AST object and back into the scope.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@996 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib/puppet/parser')
-rw-r--r-- | lib/puppet/parser/ast/objectdef.rb | 46 | ||||
-rw-r--r-- | lib/puppet/parser/scope.rb | 17 |
2 files changed, 18 insertions, 45 deletions
diff --git a/lib/puppet/parser/ast/objectdef.rb b/lib/puppet/parser/ast/objectdef.rb index 0a9ba23cd..9acf56b49 100644 --- a/lib/puppet/parser/ast/objectdef.rb +++ b/lib/puppet/parser/ast/objectdef.rb @@ -65,8 +65,7 @@ class Puppet::Parser::AST end end - # Retrieve the defaults for our type - hash = getdefaults(objtype, scope) + hash = {} # then set all of the specified params @params.each { |param| @@ -105,52 +104,9 @@ class Puppet::Parser::AST error.backtrace = detail.backtrace raise error end -# else -# # but things like components create a new type; if we find -# # one of those, evaluate that with our arguments -# #Puppet.debug("Calling object '%s' with arguments %s" % -# # [object.name, hash.inspect]) -# #obj = object.safeevaluate(scope,hash,objtype,objname) -# obj = object.safeevaluate( -# :scope => scope, -# :arguments => hash, -# :type => objtype, -# :name => objname -# ) -# -# # and pass the result on -# obj -# end }.reject { |obj| obj.nil? } end - # Retrieve the defaults for our type - def getdefaults(objtype, scope) - # first, retrieve the defaults - begin - defaults = scope.lookupdefaults(objtype) - if defaults.length > 0 - #Puppet.debug "Got defaults for %s: %s" % - # [objtype,defaults.inspect] - end - rescue => detail - raise Puppet::DevError, - "Could not lookup defaults for %s: %s" % - [objtype, detail.to_s] - end - - hash = {} - # Add any found defaults to our argument list - defaults.each { |var,value| - Puppet.debug "Found default %s for %s" % - [var,objtype] - - hash[var] = value - } - - return hash - end - # Create our ObjectDef. Handles type checking for us. def initialize(hash) @checked = false diff --git a/lib/puppet/parser/scope.rb b/lib/puppet/parser/scope.rb index 1dde7f642..f247bd7b8 100644 --- a/lib/puppet/parser/scope.rb +++ b/lib/puppet/parser/scope.rb @@ -35,6 +35,20 @@ module Puppet @@declarative = val end + # Add all of the defaults for a given object to that object. + def adddefaults(obj) + defaults = self.lookupdefaults(obj.type) + + defaults.each do |var, value| + unless obj[var] + self.debug "Adding default %s for %s" % + [var, obj.type] + + obj[var] = value + end + end + end + # Add a single object's tags to the global list of tags for # that object. def addtags(obj) @@ -975,6 +989,9 @@ module Puppet # probably should not matter child.tags = self.tags + # Add any defaults. + self.adddefaults(child) + # Then make sure this child's tags are stored in the # central table. This should maybe be in the evaluate # methods, but, eh. |