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.4.8 app/models/limit.rb
saucy-0.4.7 app/models/limit.rb
saucy-0.4.6 app/models/limit.rb
saucy-0.4.5 app/models/limit.rb
saucy-0.4.4 app/models/limit.rb
saucy-0.4.3 app/models/limit.rb
saucy-0.4.2 app/models/limit.rb
saucy-0.4.1 app/models/limit.rb
saucy-0.3.4.1 app/models/limit.rb
saucy-0.4.0 app/models/limit.rb
saucy-0.3.4 app/models/limit.rb
saucy-0.3.3 app/models/limit.rb