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



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

def comment
  @comment
end

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



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

def name
  @name
end

#rdataObject

Returns the value of attribute rdata

Returns:

  • (Object)

    the current value of rdata



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

def rdata
  @rdata
end

#ttlObject

Returns the value of attribute ttl

Returns:

  • (Object)

    the current value of ttl



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

def ttl
  @ttl
end

#typeObject

Returns the value of attribute type

Returns:

  • (Object)

    the current value of type



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

def type
  @type
end

Class Method Details

.from_dns_zonefile_record(record) ⇒ Object



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

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



63
64
65
# File 'lib/zonesync/record.rb', line 63

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

.single_record_per_name?(type) ⇒ Boolean

Returns:

  • (Boolean)


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

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

Instance Method Details

#<=>(other) ⇒ Object



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

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

#checksum?Boolean

Returns:

  • (Boolean)


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

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

#conflicts_with?(other) ⇒ Boolean

Returns:

  • (Boolean)


54
55
56
57
# File 'lib/zonesync/record.rb', line 54

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

#identical_to?(other) ⇒ Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/zonesync/record.rb', line 50

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

#manifest?Boolean

Returns:

  • (Boolean)


25
26
27
28
# File 'lib/zonesync/record.rb', line 25

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

#short_name(origin) ⇒ Object



18
19
20
21
22
23
# File 'lib/zonesync/record.rb', line 18

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

#to_sObject



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

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

#to_sortableObject



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

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