Sha256: 6f36818ab527518ba1055e51d0b91adc82def7ae4ce1d91f0012a0eb6fa92a7c

Contents?: true

Size: 1.24 KB

Versions: 33

Compression:

Stored size: 1.24 KB

Contents

module RecordStore
  class Record::CAA < Record
    attr_accessor :flags, :tag, :value

    LABEL_REGEX = '[a-z0-9](?:-*[a-z0-9])*'
    DOMAIN_REGEX = /\A#{LABEL_REGEX}(?:\.#{LABEL_REGEX})\z/i

    validates :flags, presence: true, numericality:
      {
        only_integer: true, greater_than_or_equal_to: 0,
        less_than_or_equal_to: 255
      }
    validates :tag, inclusion: { in: %w(issue issuewild iodef) }, presence: true
    validate :validate_uri_value, if: :iodef?
    validates :value, format: { with: DOMAIN_REGEX, message: 'is not a fully qualified domain name' }, unless: :iodef?

    def initialize(record)
      super
      @flags = Integer(record.fetch(:flags))
      @tag = record.fetch(:tag)
      @value = record.fetch(:value)
    end

    def rdata
      {
        flags: flags,
        tag: tag,
        value: value,
      }
    end

    def rdata_txt
      "#{flags} #{tag} \"#{value}\""
    end

    protected

    def iodef?
      tag == 'iodef'
    end

    def validate_uri_value
      uri = URI(value)
      return if uri.is_a?(URI::MailTo) || uri.is_a?(URI::HTTP)
      errors.add(:value, "URL scheme should be mailto, http, or https")
    rescue URI::Error
      errors.add(:value, "Value should be a valid URI")
    end
  end
end

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
record_store-6.6.0 lib/record_store/record/caa.rb
record_store-6.5.11 lib/record_store/record/caa.rb
record_store-6.5.10 lib/record_store/record/caa.rb
record_store-6.5.9 lib/record_store/record/caa.rb
record_store-6.5.8 lib/record_store/record/caa.rb
record_store-6.5.5 lib/record_store/record/caa.rb
record_store-6.5.4 lib/record_store/record/caa.rb
record_store-6.5.3 lib/record_store/record/caa.rb
record_store-6.5.2 lib/record_store/record/caa.rb
record_store-6.5.1 lib/record_store/record/caa.rb
record_store-6.5.0 lib/record_store/record/caa.rb
record_store-6.4.1 lib/record_store/record/caa.rb
record_store-6.4.0 lib/record_store/record/caa.rb
record_store-6.3.1 lib/record_store/record/caa.rb
record_store-6.3.0 lib/record_store/record/caa.rb
record_store-6.2.1 lib/record_store/record/caa.rb
record_store-6.2.0 lib/record_store/record/caa.rb
record_store-6.1.2 lib/record_store/record/caa.rb
record_store-6.1.1 lib/record_store/record/caa.rb
record_store-6.1.0 lib/record_store/record/caa.rb