Sha256: f3210f9e2942a684e1128e4dc2fdd51668125570a89498dd94b26108035d3386

Contents?: true

Size: 545 Bytes

Versions: 6

Compression:

Stored size: 545 Bytes

Contents

# frozen_string_literal: true

class Invite < ApplicationRecord
  include PagesCore::HasRoles

  belongs_to :user
  has_many :roles, class_name: "InviteRole", dependent: :destroy

  before_validation :ensure_token

  validates :user_id, presence: true

  validates :email,
            presence: true,
            format: { with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i },
            uniqueness: { case_sensitive: false }

  validates :token, presence: true

  private

  def ensure_token
    self.token ||= SecureRandom.hex(32)
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
pages_core-3.9.0 app/models/invite.rb
pages_core-3.8.3 app/models/invite.rb
pages_core-3.8.2 app/models/invite.rb
pages_core-3.8.1 app/models/invite.rb
pages_core-3.8.0 app/models/invite.rb
pages_core-3.7.0 app/models/invite.rb