Class: DNSer::SoaRecord

Inherits:
Record
  • Object
show all
Defined in:
lib/dnser/records/soa.rb

Instance Attribute Summary

Attributes inherited from Record

#domain

Instance Method Summary collapse

Methods inherited from Record

#comment, #full_host, #priority, #ttl

Constructor Details

#initialize(domain, host, params = {}, &block) ⇒ SoaRecord

Returns a new instance of SoaRecord.

Raises:



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/dnser/records/soa.rb', line 3

def initialize domain, host, params = {}, &block

  [:minimum, :nameserver, :email, :serial, :refresh, :retry, :expire].each do |m|
    instance_variable_set("@#{m}".to_sym, nil)
    self.class.send :define_method, m, proc { |*args|
      instance_variable_set("@#{m}", args.first) unless args.empty?
      instance_variable_get("@#{m}")
    }
  end

  params = {minimum: domain.ttl, refresh: domain.ttl, retry: domain.ttl, expire: domain.ttl, serial: Time.now.strftime("%Y%m%d%H%M")}.merge(params)

  params.each do |key, value|
    self.send key, value if  self.respond_to? key
  end

  super domain, host, params
  instance_eval &block  if block_given?

  raise DNSer::Record::EmptyValue.new(self), 'Email must be defined' unless @email
  raise DNSer::Record::EmptyValue.new(self), 'Email must be defined' unless @nameserver
end

Instance Method Details

#hostObject



26
27
28
# File 'lib/dnser/records/soa.rb', line 26

def host
  @host.to_s
end

#typeObject



30
31
32
# File 'lib/dnser/records/soa.rb', line 30

def type
  :SOA
end

#valueObject



34
35
36
37
38
39
40
41
42
# File 'lib/dnser/records/soa.rb', line 34

def value
  ns = @nameserver.to_s
  if @nameserver.is_a?(DNSer::Record)
    ns = @nameserver.full_host.to_s
  end
  em = @email.to_s.gsub('@', '.')
  em = em + '.' unless em.end_with?('.')
  [ns, em, @serial, @refresh, @retry, @expire, @ttl].join(' ')
end