class ManaPotion::CheckUsage
Attributes
limit[R]
model[R]
owner[R]
period[R]
Public Class Methods
new(model, owner, limit, period)
click to toggle source
# File lib/mana-potion/check_usage.rb, line 5 def initialize(model, owner, limit, period) @model = model @owner = owner @limit = limit @period = period end
Public Instance Methods
association()
click to toggle source
# File lib/mana-potion/check_usage.rb, line 20 def association owner .class .reflect_on_all_associations .detect { |r| r.class_name == model.class.name } end
count()
click to toggle source
# File lib/mana-potion/check_usage.rb, line 27 def count owner .send(association.name) .where(created_at: period.ago..Time.current) .count end
exceeded?()
click to toggle source
# File lib/mana-potion/check_usage.rb, line 12 def exceeded? count >= limit end
remaining()
click to toggle source
# File lib/mana-potion/check_usage.rb, line 16 def remaining limit - count end