Class: Zonesync::Record

Inherits:
Struct
  • Object
show all
Extended by:
T::Sig
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



5
6
7
# File 'lib/zonesync/record.rb', line 5

def comment
  @comment
end

#nameObject

Returns the value of attribute name



5
6
7
# File 'lib/zonesync/record.rb', line 5

def name
  @name
end

#rdataObject

Returns the value of attribute rdata



5
6
7
# File 'lib/zonesync/record.rb', line 5

def rdata
  @rdata
end

#ttlObject

Returns the value of attribute ttl



5
6
7
# File 'lib/zonesync/record.rb', line 5

def ttl
  @ttl
end

#typeObject

Returns the value of attribute type



5
6
7
# File 'lib/zonesync/record.rb', line 5

def type
  @type
end

Class Method Details

.from_dns_zonefile_record(record) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/zonesync/record.rb', line 9

def self.from_dns_zonefile_record record
  new(
    name: record.host,
    type: record.type,
    ttl: record.ttl,
    rdata: record.rdata,
    comment: record.comment,
  )
end

.non_meta(records) ⇒ Object



84
85
86
# File 'lib/zonesync/record.rb', line 84

def self.non_meta(records)
  records.reject { |r| r.manifest? || r.checksum? }
end

.single_record_per_name?(type) ⇒ Boolean



79
80
81
# File 'lib/zonesync/record.rb', line 79

def self.single_record_per_name?(type)
  type == "CNAME" || type == "SOA"
end

Instance Method Details

#<=>(other) ⇒ Object



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

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

#checksum?Boolean



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

def checksum?
  type == "TXT" &&
    name.match?(/^zonesync_checksum\./)
end

#conflicts_with?(other) ⇒ Boolean



63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/zonesync/record.rb', line 63

def conflicts_with?(other)
  return false unless name == other.name && type == other.type

  case type
  when "CNAME", "SOA"
    true
  when "MX"
    existing_priority = rdata.split(' ').first
    new_priority = other.rdata.split(' ').first
    existing_priority == new_priority
  else
    false
  end
end

#identical_to?(other) ⇒ Boolean



58
59
60
# File 'lib/zonesync/record.rb', line 58

def identical_to?(other)
  name == other.name && type == other.type && ttl == other.ttl && rdata == other.rdata
end

#manifest?Boolean



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

def manifest?
  type == "TXT" &&
    name.match?(/^zonesync_manifest\./)
end

#short_name(origin) ⇒ Object



20
21
22
23
24
25
# File 'lib/zonesync/record.rb', line 20

def short_name origin
  ret = name.sub(origin, "")
  ret = ret.sub(/\.$/, "")
  ret = "@" if ret == ""
  ret
end

#to_sObject



51
52
53
54
55
# File 'lib/zonesync/record.rb', line 51

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

#to_sortableObject



45
46
47
48
# File 'lib/zonesync/record.rb', line 45

def to_sortable
  is_soa = type == "SOA" ? 0 : 1
  [is_soa, type, name, rdata, ttl.to_i]
end