Sha256: 24a057430b504bfc29bed2004e276c29e60b476420edde44155d430fd84f9d08

Contents?: true

Size: 1.13 KB

Versions: 35

Compression:

Stored size: 1.13 KB

Contents

module RecordStore
  class Record::PTR < Record
    attr_accessor :ptrdname

    OCTET_LABEL_SEQUENCE_REGEX = /\A(?:([0-9]|[1-9][0-9]|[1-9][0-9][0-9])\.){1,4}/
    IN_ADDR_ARPA_SUFFIX_REGEX = /in-addr\.arpa\.\z/
    FQDN_FORMAT_REGEX = Regexp.new(OCTET_LABEL_SEQUENCE_REGEX.source + IN_ADDR_ARPA_SUFFIX_REGEX.source)

    validates_format_of :fqdn, with: FQDN_FORMAT_REGEX

    validate :validate_fqdn_octets_in_range
    validate :validate_fqdn_is_in_addr_arpa_subzone

    def initialize(record)
      super

      @ptrdname = Record.ensure_ends_with_dot(record.fetch(:ptrdname))
    end

    def rdata
      { ptrdname: ptrdname }
    end

    def rdata_txt
      ptrdname.to_s
    end

    def validate_fqdn_octets_in_range
      OCTET_LABEL_SEQUENCE_REGEX.match(fqdn) do |m|
        unless m.captures.all? { |o| o.to_d.between?(0, 255) }
          errors.add(:fqdn, 'octet labels must be within the range 0-255')
        end
      end
    end

    def validate_fqdn_is_in_addr_arpa_subzone
      unless IN_ADDR_ARPA_SUFFIX_REGEX.match?(fqdn)
        errors.add(:fqdn, 'PTR records may only exist in the in-addr.arpa zone')
      end
    end
  end
end

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
record_store-8.0.4 lib/record_store/record/ptr.rb
record_store-8.0.3 lib/record_store/record/ptr.rb
record_store-8.0.2 lib/record_store/record/ptr.rb
record_store-8.0.1 lib/record_store/record/ptr.rb
record_store-8.0.0 lib/record_store/record/ptr.rb
record_store-7.1.1 lib/record_store/record/ptr.rb
record_store-7.1.0 lib/record_store/record/ptr.rb
record_store-7.0.1 lib/record_store/record/ptr.rb
record_store-7.0.0 lib/record_store/record/ptr.rb
record_store-6.7.2 lib/record_store/record/ptr.rb
record_store-6.7.1 lib/record_store/record/ptr.rb
record_store-6.7.0 lib/record_store/record/ptr.rb
record_store-6.6.0 lib/record_store/record/ptr.rb
record_store-6.5.11 lib/record_store/record/ptr.rb
record_store-6.5.10 lib/record_store/record/ptr.rb
record_store-6.5.9 lib/record_store/record/ptr.rb
record_store-6.5.8 lib/record_store/record/ptr.rb
record_store-6.5.5 lib/record_store/record/ptr.rb
record_store-6.5.4 lib/record_store/record/ptr.rb
record_store-6.5.3 lib/record_store/record/ptr.rb