pool.rb 702 Bytes
# frozen_string_literal: true

# == Schema Information
#
# Table name: heimdall_engine_roles
#
#  id         :integer          not null, primary key
#  name       :string
#  created_at :datetime
#  updated_at :datetime
#  deleted_at :datetime
#  erasable   :boolean
#
class Pool < ApplicationRecord

  validates :name, :editable_until, presence: true

  has_many :matches, dependent: :destroy, inverse_of: :pool
  has_many :groups, inverse_of: :pool
  has_many :users, through: :groups, inverse_of: :pools

  scope :active, -> { where(active: true) }
  accepts_nested_attributes_for :matches, reject_if: :all_blank,
    allow_destroy: true

  def editable?
    editable_until > Time.zone.now
  end
end