Class: Kaui::Account
- Inherits:
-
KillBillClient::Model::Account
- Object
- KillBillClient::Model::Account
- Kaui::Account
- Defined in:
- app/models/kaui/account.rb
Class Method Summary collapse
- .find_by_id_or_key(account_id_or_key, with_balance = false, with_balance_and_cba = false, options = {}) ⇒ Object
- .list_or_search(search_key = nil, offset = 0, limit = 10, options = {}) ⇒ Object
Instance Method Summary collapse
Class Method Details
.find_by_id_or_key(account_id_or_key, with_balance = false, with_balance_and_cba = false, options = {}) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'app/models/kaui/account.rb', line 3 def self.find_by_id_or_key(account_id_or_key, with_balance = false, with_balance_and_cba = false, = {}) if account_id_or_key =~ /[A-Fa-f0-9]{8}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{12}/ begin find_by_id(account_id_or_key, with_balance, with_balance_and_cba, ) rescue => e begin # account_id_or_key looked like an id, but maybe it's an external key (this will happen in tests)? find_by_external_key(account_id_or_key, with_balance, with_balance_and_cba, ) rescue => _ # Nope - raise the initial exception raise e end end else find_by_external_key(account_id_or_key, with_balance, with_balance_and_cba, ) end end |
.list_or_search(search_key = nil, offset = 0, limit = 10, options = {}) ⇒ Object
21 22 23 24 25 26 27 |
# File 'app/models/kaui/account.rb', line 21 def self.list_or_search(search_key = nil, offset = 0, limit = 10, = {}) if search_key.present? find_in_batches_by_search_key(search_key, offset, limit, true, false, ) else find_in_batches(offset, limit, true, false, ) end end |
Instance Method Details
#balance_to_money ⇒ Object
29 30 31 |
# File 'app/models/kaui/account.rb', line 29 def balance_to_money Kaui::Base.to_money(account_balance.abs, currency) end |
#cba_to_money ⇒ Object
33 34 35 |
# File 'app/models/kaui/account.rb', line 33 def cba_to_money Kaui::Base.to_money(account_cba.abs, currency) end |
#persisted? ⇒ Boolean
37 38 39 |
# File 'app/models/kaui/account.rb', line 37 def persisted? !account_id.blank? end |