From 08499b10c1bdccbcaeeacf1826cc156a80524e0e Mon Sep 17 00:00:00 2001 From: luke Date: Fri, 15 Sep 2006 07:09:28 +0000 Subject: 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 --- lib/puppet/parser/scope.rb | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'lib/puppet/parser') 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 -- cgit