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.12.2 app/models/limit.rb
saucy-0.12.1 app/models/limit.rb
saucy-0.12.0 app/models/limit.rb
saucy-0.11.5 app/models/limit.rb
saucy-0.11.3 app/models/limit.rb
saucy-0.11.2 app/models/limit.rb
saucy-0.10.7 app/models/limit.rb
saucy-0.10.6 app/models/limit.rb
saasy-0.0.2.alpha3 app/models/limit.rb
saasy-0.0.2.alpha2 app/models/limit.rb
saasy-0.0.2.alpha1 app/models/limit.rb
saucy-0.10.5 app/models/limit.rb
saucy-0.10.4 app/models/limit.rb
saucy-0.10.3 app/models/limit.rb
saucy-0.10.2 app/models/limit.rb
saucy-0.10.1 app/models/limit.rb
saucy-0.10.0 app/models/limit.rb
saucy-0.9.1 app/models/limit.rb
saucy-0.9.0 app/models/limit.rb
saucy-0.8.5 app/models/limit.rb