Sha256: 5f651eb01e02bf69d554c44349854b8a06f98d72f8d6d7a4ebc38b3d537dcd93
Contents?: true
Size: 1.96 KB
Versions: 5
Compression:
Stored size: 1.96 KB
Contents
module RecordStore class Record FQDN_REGEX = /\A(\*\.)?([a-z0-9_]+(-[a-z0-9]+)*\._?)+[a-z]{2,}\.\Z/i CNAME_REGEX = /\A(\*\.)?([a-z0-9]+(-[a-z0-9]+)*\._?)+[a-z]{2,}\.\Z/i include ActiveModel::Validations attr_accessor :fqdn, :ttl, :id validates :ttl, numericality: { only_integer: true, greater_than_or_equal_to: 0, less_than_or_equal_to: 2147483647 } validates :fqdn, format: { with: Record::FQDN_REGEX }, length: { maximum: 254 } validate :validate_label_length def initialize(record) @fqdn = Record.ensure_ends_with_dot(record.fetch(:fqdn)) @ttl = record.fetch(:ttl) @id = record.fetch(:record_id, nil) end def self.build_from_yaml_definition(yaml_definition) record_type = yaml_definition.fetch(:type) # TODO: remove backward compatibility support for ALIAS records using cname attribute instead of alias # REMOVE after merging https://github.com/Shopify/record-store/pull/781 case record_type when 'ALIAS' if yaml_definition.key?(:cname) yaml_definition[:alias] = yaml_definition.delete(:cname) end end Record.const_get(record_type).new(yaml_definition) end def log!(logger=STDOUT) logger.puts to_s end def to_hash { type: type, fqdn: fqdn, ttl: ttl }.merge(rdata) end def type self.class.name.split('::').last end def ==(other) other.class == self.class && other.to_hash == self.to_hash end alias_method :eql?, :== def hash to_hash.hash end def to_json { ttl: ttl, rdata: rdata } end def key "#{type},#{fqdn}" end protected def validate_label_length unless fqdn.split('.').all? { |label| label.length <= 63 } errors.add(:fqdn, "A label should be at most 63 characters") end end def self.ensure_ends_with_dot(fqdn) fqdn.end_with?(".") ? fqdn : "#{fqdn}." end end end
Version data entries
5 entries across 5 versions & 1 rubygems