Class: Account
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Account
show all
- Defined in:
- app/models/account.rb
Class Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Class Attribute Details
.owner_type ⇒ Object
Returns the value of attribute owner_type.
6
7
8
|
# File 'app/models/account.rb', line 6
def owner_type
@owner_type
end
|
Class Method Details
.owned_by(klass) ⇒ Object
9
10
11
12
13
|
# File 'app/models/account.rb', line 9
def self.owned_by(klass)
@owner_type = klass.to_s.classify.constantize
belongs_to :owner, :polymorphic => true
validate :check_owner_type
end
|
Instance Method Details
#balance_at(date) ⇒ Object
15
16
17
18
|
# File 'app/models/account.rb', line 15
def balance_at(date)
balance = balances.where(:evaluated_at => date).first
balance ||= Balance.new(:account => self, :evaluated_at => date)
end
|
#balance_before(date) ⇒ Object
20
21
22
23
|
# File 'app/models/account.rb', line 20
def balance_before(date)
balances.find :first, :conditions => ["evaluated_at < ?", date],
:order => "evaluated_at DESC"
end
|
#current_balance ⇒ Object
25
26
27
|
# File 'app/models/account.rb', line 25
def current_balance
balance_at(Time.now)
end
|