diff options
author | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-09-15 07:09:28 +0000 |
---|---|---|
committer | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-09-15 07:09:28 +0000 |
commit | 08499b10c1bdccbcaeeacf1826cc156a80524e0e (patch) | |
tree | 14ca449c5bade630726f9acf39e7b327a327bd4a /lib/puppet | |
parent | 26bf373eee9d5ac09296bd5eab3af11b44f28826 (diff) | |
download | puppet-08499b10c1bdccbcaeeacf1826cc156a80524e0e.tar.gz puppet-08499b10c1bdccbcaeeacf1826cc156a80524e0e.tar.xz puppet-08499b10c1bdccbcaeeacf1826cc156a80524e0e.zip |
Adding the feature from #259. I had to rework the Scope#lookupvar a bit, but everything now works as expected when variables are either undefined or set to empty strings.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1609 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib/puppet')
-rw-r--r-- | lib/puppet/parser/scope.rb | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/lib/puppet/parser/scope.rb b/lib/puppet/parser/scope.rb index 69c8c06ed..a26ec938d 100644 --- a/lib/puppet/parser/scope.rb +++ b/lib/puppet/parser/scope.rb @@ -36,8 +36,13 @@ module Puppet::Parser end end + # Ruby treats variables like methods, so we can cheat here and + # trap missing vars like they were missing methods. def method_missing(name, *args) - if value = @scope.lookupvar(name.to_s) and value != :undefined and value != "" + # We have to tell lookupvar to return :undefined to us when + # appropriate; otherwise it converts to "". + value = @scope.lookupvar(name.to_s, false) + if value != :undefined return value else # Just throw an error immediately, instead of searching for @@ -690,11 +695,16 @@ module Puppet::Parser end end - # Look up a variable. The simplest value search we do. - def lookupvar(name) + # Look up a variable. The simplest value search we do. Default to returning + # an empty string for missing values, but support returning a constant. + def lookupvar(name, usestring = true) value = lookup("variable", name) if value == :undefined - return "" + if usestring + return "" + else + return :undefined + end else return value end |