Class: Limit
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Limit
- Defined in:
- app/models/limit.rb
Class Method Summary collapse
- .boolean ⇒ Object
- .can_add_one?(limit_name, account) ⇒ Boolean
- .named(name) ⇒ Object
- .numbered ⇒ Object
- .within?(limit_name, account) ⇒ Boolean
Instance Method Summary collapse
- #allowed? ⇒ Boolean
- #can_add_one?(account) ⇒ Boolean
- #current_count(account) ⇒ Object
- #within?(account) ⇒ Boolean
Class Method Details
.boolean ⇒ Object
10 11 12 |
# File 'app/models/limit.rb', line 10 def self.boolean where(:value_type => :boolean) end |
.can_add_one?(limit_name, account) ⇒ Boolean
26 27 28 29 30 31 32 |
# File 'app/models/limit.rb', line 26 def self.can_add_one?(limit_name, account) if account.plan.limit(limit_name) account.plan.limit(limit_name).can_add_one?(account) else true end end |
.named(name) ⇒ Object
14 15 16 |
# File 'app/models/limit.rb', line 14 def self.named(name) where(:name => name).first end |
.numbered ⇒ Object
6 7 8 |
# File 'app/models/limit.rb', line 6 def self.numbered where(:value_type => :number) end |
.within?(limit_name, account) ⇒ Boolean
18 19 20 21 22 23 24 |
# File 'app/models/limit.rb', line 18 def self.within?(limit_name, account) if account.plan.limit(limit_name) account.plan.limit(limit_name).within?(account) else true end end |
Instance Method Details
#allowed? ⇒ Boolean
34 35 36 |
# File 'app/models/limit.rb', line 34 def allowed? value != 0 end |
#can_add_one?(account) ⇒ Boolean
42 43 44 |
# File 'app/models/limit.rb', line 42 def can_add_one?(account) (current_count(account) + 1) <= value end |
#current_count(account) ⇒ Object
46 47 48 |
# File 'app/models/limit.rb', line 46 def current_count(account) account.send(:"#{name}_count") end |
#within?(account) ⇒ Boolean
38 39 40 |
# File 'app/models/limit.rb', line 38 def within?(account) current_count(account) <= value end |