Class: Limit

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/limit.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.booleanObject



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

Returns:

  • (Boolean)


26
27
28
29
30
31
32
# File 'app/models/limit.rb', line 26

def self.can_add_one?(limit_name, )
  if .plan.limit(limit_name)
    .plan.limit(limit_name).can_add_one?()
  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

.numberedObject



6
7
8
# File 'app/models/limit.rb', line 6

def self.numbered
  where(:value_type => :number)
end

.within?(limit_name, account) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
21
22
23
24
# File 'app/models/limit.rb', line 18

def self.within?(limit_name, )
  if .plan.limit(limit_name)
    .plan.limit(limit_name).within?()
  else
    true
  end
end

Instance Method Details

#allowed?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'app/models/limit.rb', line 34

def allowed?
  value != 0
end

#can_add_one?(account) ⇒ Boolean

Returns:

  • (Boolean)


42
43
44
# File 'app/models/limit.rb', line 42

def can_add_one?()
  (current_count() + 1) <= value
end

#current_count(account) ⇒ Object



46
47
48
# File 'app/models/limit.rb', line 46

def current_count()
  .send(:"#{name}_count")
end

#within?(account) ⇒ Boolean

Returns:

  • (Boolean)


38
39
40
# File 'app/models/limit.rb', line 38

def within?()
  current_count() <= value
end