Class: Zone

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-powerdns/includes/Zone.class.rb

Overview

Copyright © 2013 Matthias Kadenbach github.com/mattes/vagrant-dnsmasq

Constant Summary collapse

MATCH =
/^[a-z0-9]+([\-\.]{1}[a-z0-9]+)*$/

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Zone

Returns a new instance of Zone.

Raises:

  • (ArgumentError)


8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/vagrant-powerdns/includes/Zone.class.rb', line 8

def initialize(name)
  @name = nil

  if name.is_a? Zone
    name = name.dotted
  end

  raise ArgumentError, "Invalid Zone: #{name.to_s}" if !name.is_a?(String)
  raise ArgumentError, "no zone name given" if name.empty?

  # parse domain name ...
  name = name.to_s
  name = name[1..-1] if name.start_with? '.'
  name = name.downcase
  raise ArgumentError, "Zone '#{name}' must match #{MATCH}" unless Zone::valid?(name)
  @name = name # without leading .
end

Class Method Details

.valid?(name) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/vagrant-powerdns/includes/Zone.class.rb', line 26

def self.valid?(name)
  if not name.empty? and Zone::MATCH.match(name.downcase) then true else false end
end

Instance Method Details

#dottedObject



30
31
32
# File 'lib/vagrant-powerdns/includes/Zone.class.rb', line 30

def dotted
  '.' + @name
end

#nameObject



34
35
36
# File 'lib/vagrant-powerdns/includes/Zone.class.rb', line 34

def name
  @name
end

#to_sObject



38
39
40
# File 'lib/vagrant-powerdns/includes/Zone.class.rb', line 38

def to_s
  dotted
end