Module: Aloe::AccountRepository
- Included in:
- Account
- Defined in:
- lib/aloe/account_repository.rb
Instance Method Summary collapse
-
#closed ⇒ ActiveRecord::Relation
Scope to closed accounts.
-
#currency(currency) ⇒ ActiveRecord::Relation
Scope by currency.
-
#default_scope ⇒ Object
Default scope excludes closed accounts.
-
#owner(owner) ⇒ ActiveRecord::Relation
Scope by owner.
-
#trial_balance(currency) ⇒ Fixnum
Return the trial balance.
Instance Method Details
#closed ⇒ ActiveRecord::Relation
Scope to closed accounts.
20 21 22 |
# File 'lib/aloe/account_repository.rb', line 20 def closed unscoped.with_state('closed') end |
#currency(currency) ⇒ ActiveRecord::Relation
Scope by currency.
8 9 10 |
# File 'lib/aloe/account_repository.rb', line 8 def currency(currency) where(currency: currency) end |
#default_scope ⇒ Object
Default scope excludes closed accounts.
13 14 15 |
# File 'lib/aloe/account_repository.rb', line 13 def default_scope where('state != ?', 'closed') end |
#owner(owner) ⇒ ActiveRecord::Relation
Scope by owner.
28 29 30 |
# File 'lib/aloe/account_repository.rb', line 28 def owner(owner) where(owner_type: owner.class.model_name.to_s, owner_id: owner.id) end |
#trial_balance(currency) ⇒ Fixnum
Return the trial balance.
Trial balance is balance of all accounts in the system combined. It should at all times be 0. If it’s not, there is an error in accounts somewhere.
40 41 42 |
# File 'lib/aloe/account_repository.rb', line 40 def trial_balance(currency) currency(currency).sum :balance end |