blob: 575105cfd794741c57965c6177991d4d42c65762 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
# frozen_string_literal: true
class PlanLimits < ApplicationRecord
belongs_to :plan
def exceeded?(limit_name, object)
return false unless enabled?(limit_name)
if object.is_a?(Integer)
object >= read_attribute(limit_name)
else
# object.count >= limit value is slower than checking
# if a record exists at the limit value - 1 position.
object.offset(read_attribute(limit_name) - 1).exists?
end
end
private
def enabled?(limit_name)
read_attribute(limit_name) > 0
end
end
|