class Domain < ApplicationRecord after_create :create_abuse_postmaster has_many :credentials, dependent: :destroy has_many :virtuals, dependent: :destroy validates :domain, presence: true validates :domain, uniqueness: true validates :domain, format: { with: /\A(((?!-))(xn--|_)?[a-z0-9-]{0,61}[a-z0-9]{1,1}\.)*(xn--)?([a-z0-9][a-z0-9\-]{0,60}|[a-z0-9-]{1,30}\.[a-z]{2,})\z/, message: "domain not valid" } private def create_abuse_postmaster Virtual.create(email: "abuse@#{self.domain}", destination: "jez@warwickhunt.com", domain_id: self.id) Virtual.create(email: "postmaster@#{self.domain}", destination: "jez@warwickhunt.com", domain_id: self.id) end end