2023-03-07 17:35:21 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# Allows to set booking limits on some resources, per plan.
|
|
|
|
class PlanLimitation < ApplicationRecord
|
|
|
|
belongs_to :plan
|
|
|
|
|
|
|
|
belongs_to :limitable, polymorphic: true
|
2023-02-24 17:26:55 +01:00
|
|
|
belongs_to :machine, foreign_key: 'limitable_id', inverse_of: :plan_limitations
|
|
|
|
belongs_to :machine_category, foreign_key: 'limitable_id', inverse_of: :plan_limitations
|
2023-03-07 17:35:21 +01:00
|
|
|
|
2023-07-07 09:14:47 +02:00
|
|
|
validates :limitable_id, :limitable_type, :limit, presence: true
|
2023-03-10 14:13:00 +01:00
|
|
|
validates :limitable_id, uniqueness: { scope: %i[limitable_type plan_id] }
|
2023-03-13 17:29:06 +01:00
|
|
|
|
|
|
|
# @return [Array<Machine,Event,Space,Training>]
|
|
|
|
def reservables
|
|
|
|
return limitable.machines if limitable_type == 'MachineCategory'
|
|
|
|
|
|
|
|
[limitable]
|
|
|
|
end
|
2023-03-07 17:35:21 +01:00
|
|
|
end
|