Class: Zonesync::Record

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#commentObject

Returns the value of attribute comment

Returns:

  • (Object)

    the current value of comment



2
3
4
# File 'lib/zonesync/record.rb', line 2

def comment
  @comment
end

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



2
3
4
# File 'lib/zonesync/record.rb', line 2

def name
  @name
end

#rdataObject

Returns the value of attribute rdata

Returns:

  • (Object)

    the current value of rdata



2
3
4
# File 'lib/zonesync/record.rb', line 2

def rdata
  @rdata
end

#ttlObject

Returns the value of attribute ttl

Returns:

  • (Object)

    the current value of ttl



2
3
4
# File 'lib/zonesync/record.rb', line 2

def ttl
  @ttl
end

#typeObject

Returns the value of attribute type

Returns:

  • (Object)

    the current value of type



2
3
4
# File 'lib/zonesync/record.rb', line 2

def type
  @type
end

Class Method Details

.from_dns_zonefile_record(record) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/zonesync/record.rb', line 3

def self.from_dns_zonefile_record record
  type = record.class.name.split("::").last
  rdata = case type
  when "SOA"
    def record.host = origin
    "" # it just gets ignored anyways
  when "A", "AAAA"
    record.address
  when "CNAME", "NS", "PTR"
    record.domainname
  when "MX"
    "#{record.priority} #{record.domainname}"
  when "TXT", "SPF", "NAPTR"
    record.data
  else
    raise NotImplementedError.new(record.class).to_s
  end

  new(
    record.host,
    type,
    record.ttl,
    rdata,
    record.comment,
  )
end

Instance Method Details

#<=>(other) ⇒ Object



30
31
32
# File 'lib/zonesync/record.rb', line 30

def <=> other
  to_sortable <=> other.to_sortable
end

#to_sObject



38
39
40
41
42
# File 'lib/zonesync/record.rb', line 38

def to_s
  string = [name, type, ttl, rdata].join(" ")
  string << " ; #{comment}" if comment
  string
end

#to_sortableObject



34
35
36
# File 'lib/zonesync/record.rb', line 34

def to_sortable
  [type, name, rdata, ttl]
end