Class: Puppet::Parser::AST::HostName

Inherits:
Leaf show all
Defined in:
lib/puppet/parser/ast/leaf.rb

Overview

Host names, either fully qualified or just the short name, or even a regex

Instance Attribute Summary

Attributes inherited from Leaf

#type, #value

Instance Method Summary collapse

Methods inherited from Leaf

#evaluate, #match, #to_s

Constructor Details

#initialize(hash) ⇒ HostName

Returns a new instance of HostName.



86
87
88
89
90
91
92
93
94
95
# File 'lib/puppet/parser/ast/leaf.rb', line 86

def initialize(hash)
  super

  # Note that this is an AST::Regex, not a Regexp
  unless @value.is_a?(Regex)
    @value = @value.to_s.downcase
    @value =~ /[^-\w.]/ and
      raise Puppet::DevError, "'#{@value}' is not a valid hostname"
  end
end

Instance Method Details

#eql?(value) ⇒ Boolean

implementing eql? and hash so that when an HostName is stored in a hash it has the same hashing properties as the underlying value

Returns:



99
100
101
102
# File 'lib/puppet/parser/ast/leaf.rb', line 99

def eql?(value)
  value = value.value if value.is_a?(HostName)
  @value.eql?(value)
end

#hashObject



104
105
106
# File 'lib/puppet/parser/ast/leaf.rb', line 104

def hash
  @value.hash
end