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

Constant Summary

Constants inherited from Puppet::Parser::AST

AST

Instance Attribute Summary

Attributes inherited from Leaf

#type, #value

Attributes inherited from Puppet::Parser::AST

#file, #line, #parent, #pos, #scope

Instance Method Summary collapse

Methods inherited from Leaf

#evaluate, #match, #to_s

Methods inherited from Puppet::Parser::AST

#evaluate, #inspect, #safeevaluate

Methods included from Util::MethodHelper

#requiredopts, #set_options, #symbolize_options

Methods included from Util::Errors

#adderrorcontext, #devfail, #error_context, #exceptwrap, #fail

Constructor Details

#initialize(hash) ⇒ HostName

Returns a new instance of HostName.



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/puppet/parser/ast/leaf.rb', line 24

def initialize(hash)
  super

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

  • (Boolean)


38
39
40
# File 'lib/puppet/parser/ast/leaf.rb', line 38

def eql?(value)
  @value.eql?(value.is_a?(HostName) ? value.value : value)
end

#hashObject



42
43
44
# File 'lib/puppet/parser/ast/leaf.rb', line 42

def hash
  @value.hash
end