Sha256: 1422400011541f1d551a7cae682d0c3f034c5d5b19c4702aaac4f60fb44ca1d2

Contents?: true

Size: 863 Bytes

Versions: 10

Compression:

Stored size: 863 Bytes

Contents

module Zonesync
  class Record < Struct.new(:name, :type, :ttl, :rdata)
    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,
      )
    end

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

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

    def to_s
      values.join(" ")
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
zonesync-0.6.1 lib/zonesync/record.rb
zonesync-0.6.0 lib/zonesync/record.rb
zonesync-0.5.2 lib/zonesync/record.rb
zonesync-0.5.1 lib/zonesync/record.rb
zonesync-0.5.0 lib/zonesync/record.rb
zonesync-0.4.1 lib/zonesync/record.rb
zonesync-0.4.0 lib/zonesync/record.rb
zonesync-0.3.0 lib/zonesync/record.rb
zonesync-0.2.0 lib/zonesync/record.rb
zonesync-0.1.2 lib/zonesync/record.rb