This repository has been archived on 2020-05-27. You can view files and clone it, but cannot push or open issues/pull-requests.
grindable/app/models/fund.rb

24 lines
519 B
Ruby

class Fund < ActiveRecord::Base
validates_numericality_of :balance, :contribution
validates_uniqueness_of :name
has_many :baristas
has_many :ledgers, :dependent => true
def make_contribution(amount)
self[:balance] += amount
end
def make_purchase(amount)
self[:balance] -= amount
end
def self.for_select
self.find(:all, :select => 'id, name').collect { |f| [ f.name, f.id.to_s ] }
end
def before_destroy
raise "Fund still has baristas!" unless self.baristas.empty?
end
end