summaryrefslogtreecommitdiffstats
path: root/lib/puppet/parser/ast/leaf.rb
diff options
context:
space:
mode:
authorBrice Figureau <brice-puppet@daysofwonder.com>2009-07-28 19:42:24 +0200
committerJames Turnbull <james@lovedthanlost.net>2009-08-01 11:15:29 +1000
commit58a73b5c68485dc5d41a46936c31e5fad5f037b5 (patch)
treed8fa2e0b6429a1a1262bc19ad6d876b565500b42 /lib/puppet/parser/ast/leaf.rb
parent3ebf148bf3d82d25e690aec6ec49975e0837e604 (diff)
downloadpuppet-58a73b5c68485dc5d41a46936c31e5fad5f037b5.tar.gz
puppet-58a73b5c68485dc5d41a46936c31e5fad5f037b5.tar.xz
puppet-58a73b5c68485dc5d41a46936c31e5fad5f037b5.zip
Make sure node are referenced by their names
This patch uses the unused AST::HostName as the only way to reference a node in the AST nodes array. The AST::HostName respect the hash properties of the underlying string, to keep the O(1) hash properties. Signed-off-by: Brice Figureau <brice-puppet@daysofwonder.com>
Diffstat (limited to 'lib/puppet/parser/ast/leaf.rb')
-rw-r--r--lib/puppet/parser/ast/leaf.rb18
1 files changed, 17 insertions, 1 deletions
diff --git a/lib/puppet/parser/ast/leaf.rb b/lib/puppet/parser/ast/leaf.rb
index 7743862d7..59bfc9e9d 100644
--- a/lib/puppet/parser/ast/leaf.rb
+++ b/lib/puppet/parser/ast/leaf.rb
@@ -90,11 +90,27 @@ class Puppet::Parser::AST
def initialize(hash)
super
- unless @value =~ %r{^[0-9a-zA-Z\-]+(\.[0-9a-zA-Z\-]+)*$}
+ @value = @value.to_s.downcase
+ if @value =~ /[^-\w.]/
raise Puppet::DevError,
"'%s' is not a valid hostname" % @value
end
end
+
+ def to_classname
+ return @value
+ 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
+ def eql?(value)
+ value = value.value if value.is_a?(HostName)
+ return @value.eql?(value)
+ end
+
+ def hash
+ return @value.hash
+ end
end
# A simple variable. This object is only used during interpolation;