Sha256: 385a556e4dc6ff342a3bb1a1eda2669f3c67d1418aaca367c545f18aeb3e1bf0

Contents?: true

Size: 873 Bytes

Versions: 72

Compression:

Stored size: 873 Bytes

Contents

class Limit < ActiveRecord::Base
  belongs_to :plan

  validates_presence_of :name, :value

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

  def self.boolean
    where(:value_type => :boolean)
  end

  def self.named(name)
    where(:name => name).first
  end

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

  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

  def allowed?
    value != 0
  end

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

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

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

Version data entries

72 entries across 72 versions & 2 rubygems

Version Path
saucy-0.16.1 app/models/limit.rb
saucy-0.16.0 app/models/limit.rb
saucy-0.15.2 app/models/limit.rb
saucy-0.15.1 app/models/limit.rb
saucy-0.15.0 app/models/limit.rb
saucy-0.14.5 app/models/limit.rb
saucy-0.14.3 app/models/limit.rb
saucy-0.10.10 app/models/limit.rb
saucy-0.14.2 app/models/limit.rb
saucy-0.14.1 app/models/limit.rb
saucy-0.14.0 app/models/limit.rb
saucy-0.13.3 app/models/limit.rb
saucy-0.13.2 app/models/limit.rb
saucy-0.10.9 app/models/limit.rb
saucy-0.10.8 app/models/limit.rb
saucy-0.13.1 app/models/limit.rb
saucy-0.13.0 app/models/limit.rb
saucy-0.12.5 app/models/limit.rb
saucy-0.12.4 app/models/limit.rb
saucy-0.12.3 app/models/limit.rb