Created
February 17, 2009 04:58
-
-
Save sprite2005/65585 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TransactionAccount < ActiveRecord::Base | |
composed_of :balance, :class_name => "Money", :mapping => [%w(cents account_balance_cents), %w(currency currency) ] | |
belongs_to :user | |
has_many :sent_transactions, :class_name => "TransactionItem", | |
:foreign_key => "transaction_sender_account_id" | |
has_many :received_transactions, :class_name => "TransactionItem", | |
:foreign_key => "transaction_receiver_account_id" | |
end | |
class TransactionItem < ActiveRecord::Base | |
composed_of :amount, :class_name => "Money", :mapping => [%w(cents cents), %w(currency currency) ] | |
belongs_to :sender, | |
:class_name => "TransactionAccount", | |
:foreign_key => "transaction_sender_account_id" | |
belongs_to :receiver, | |
:class_name => "TransactionAccount", | |
:foreign_key => "transaction_receiver_account_id" | |
belongs_to :transaction_object, | |
:polymorphic => true | |
validates_presence_of :sender | |
validates_presence_of :receiver | |
validates_presence_of :description | |
def update | |
end | |
def finalize | |
end | |
def receiver_amount | |
amount | |
end | |
def sender_amount | |
amount * -1 | |
end | |
private | |
validate :cents_not_zero | |
def cents_not_zero | |
errors.add("cents", "cannot be zero or less") unless cents > 0 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment