Class: RedZone::Record

Inherits:
Object
  • Object
show all
Defined in:
lib/redzone/record.rb

Overview

DNS Record

Instance Method Summary collapse

Constructor Details

#initialize(record) ⇒ Record

Returns a new instance of a domain record

Parameters:

  • record (Hash)

Options Hash (record):

  • :name (String)

    The record name (Required)

  • :class (String) — default: 'IN'

    The record class. (Optional)

  • :ttl (String)

    The ttl for the record (Optional)

  • :type (String)

    The type of record, eg: CNAME, A, AAAA. (Required)

  • :data (String)

    The record data (Required)

  • :comment (String)

    A comment for the record

Raises:

  • (ArgumentError)


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/redzone/record.rb', line 13

def initialize(record)
  raise ArgumentError, ':name is required' unless record.has_key?(:name)
  raise ArgumentError, ':type is required' unless record.has_key?(:type)
  raise ArgumentError, ':data is required' unless record.has_key?(:data) 
  @name    = record[:name]
  @class   = record[:class] || 'IN'
  @type    = record[:type]
  if record.has_key?(:ttl) and not record[:ttl].nil?
    @ttl     = Lifetime.new(record[:ttl]).seconds
  end
  @data    = record[:data]
  if @type == "TXT"
    @data = '"%s"' % [@data.gsub(/^\s*"?|"?\s*$/,'').gsub(/\n/,'')]
  end
  if record.has_key?(:comment) and not record[:comment].nil?
    @comment = " ; %s" % [record[:comment]]
  end
end

Instance Method Details

#to_sString

Returns the domain record as a string to be written in the zone file

Returns:

  • (String)

    record line



33
34
35
# File 'lib/redzone/record.rb', line 33

def to_s
  "%-20s %-8s %s    %-8s %-20s%s\n" % [@name, @ttl, @class, @type, @data, @comment || '']
end