Sha256: 00288d2526d36fa92449833439edae4b54fc3f6fb5591b93293ae3c7661bcb89

Contents?: true

Size: 818 Bytes

Versions: 1

Compression:

Stored size: 818 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)
    account.send(:"#{name}_count") <= value
  end

  def can_add_one?(account)
    (account.send(:"#{name}_count") + 1) <= value
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
saucy-0.3.2 app/models/limit.rb