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::Errors

#adderrorcontext, #devfail, #error_context, error_location, error_location_with_space, error_location_with_unknowns, #exceptwrap, #fail

Constructor Details

#initialize(hash) ⇒ HostName

Returns a new instance of HostName


29
30
31
32
33
34
35
36
37
38
39
# File 'lib/puppet/parser/ast/leaf.rb', line 29

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") % { value: @value }
    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)

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

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

#hashObject


47
48
49
# File 'lib/puppet/parser/ast/leaf.rb', line 47

def hash
  @value.hash
end