lib/puppet/parser/ast/leaf.rb in puppet-2.7.26 vs lib/puppet/parser/ast/leaf.rb in puppet-3.0.0.rc4
- old
+ new
@@ -20,46 +20,39 @@
end
# The boolean class. True or false. Converts the string it receives
# to a Ruby boolean.
class Boolean < AST::Leaf
-
- # Use the parent method, but then convert to a real boolean.
def initialize(hash)
super
unless @value == true or @value == false
- raise Puppet::DevError,
- "'#{@value}' is not a boolean"
+ raise Puppet::DevError, "'#{@value}' is not a boolean"
end
@value
end
-
- def to_s
- @value ? "true" : "false"
- end
end
# The base string class.
class String < AST::Leaf
def evaluate(scope)
@value.dup
end
def to_s
- "\"#{@value}\""
+ @value.inspect
end
end
# An uninterpreted string.
class FlatString < AST::Leaf
def evaluate(scope)
@value
end
def to_s
- "\"#{@value}\""
+ @value.inspect
end
end
class Concat < AST::Leaf
def evaluate(scope)
@@ -92,14 +85,14 @@
class HostName < AST::Leaf
def initialize(hash)
super
# Note that this is an AST::Regex, not a Regexp
- @value = @value.to_s.downcase unless @value.is_a?(Regex)
- if @value =~ /[^-\w.]/
- raise Puppet::DevError,
- "'#{@value}' is not a valid hostname"
+ unless @value.is_a?(Regex)
+ @value = @value.to_s.downcase
+ @value =~ /[^-\w.]/ and
+ raise Puppet::DevError, "'#{@value}' is not a valid hostname"
end
end
# implementing eql? and hash so that when an HostName is stored
# in a hash it has the same hashing properties as the underlying value
@@ -109,27 +102,24 @@
end
def hash
@value.hash
end
-
- def to_s
- @value.to_s
- end
end
# A simple variable. This object is only used during interpolation;
# the VarDef class is used for assignment.
class Variable < Name
# Looks up the value of the object in the scope tree (does
# not include syntactical constructs, like '$' and '{}').
def evaluate(scope)
parsewrap do
- if (var = scope.lookupvar(@value, :file => file, :line => line)) == :undefined
- var = :undef
+ if scope.include?(@value)
+ scope[@value, {:file => file, :line => line}]
+ else
+ :undef
end
- var
end
end
def to_s
"\$#{value}"
@@ -139,10 +129,10 @@
class HashOrArrayAccess < AST::Leaf
attr_accessor :variable, :key
def evaluate_container(scope)
container = variable.respond_to?(:evaluate) ? variable.safeevaluate(scope) : variable
- (container.is_a?(Hash) or container.is_a?(Array)) ? container : scope.lookupvar(container, :file => file, :line => line)
+ (container.is_a?(Hash) or container.is_a?(Array)) ? container : scope[container, {:file => file, :line => line}]
end
def evaluate_key(scope)
key.respond_to?(:evaluate) ? key.safeevaluate(scope) : key
end