1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-07-23 15:19:38 +02:00
Maybe/app/models/concerns/accountable.rb
Juan B. Rodriguez 49d1fe0e11
feat: add crypto account type to demo data (#555)
* feat: add crypto account type to demo data

* fix: set currency to BTC, revert schema migration change and fix tests

* fix: update dates in time_series tests
2024-03-19 15:34:35 -04:00

29 lines
905 B
Ruby

module Accountable
extend ActiveSupport::Concern
ASSET_TYPES = %w[ Account::Depository Account::Investment Account::Crypto Account::OtherAsset Account::Property Account::Vehicle ]
LIABILITY_TYPES = %w[ Account::Credit Account::Loan Account::OtherLiability ]
TYPES = ASSET_TYPES + LIABILITY_TYPES
def self.from_type(type)
return nil unless types.include?(type) || TYPES.include?(type)
"Account::#{type.demodulize}".constantize
end
def self.by_classification
{ assets: ASSET_TYPES, liabilities: LIABILITY_TYPES }
end
def self.types(classification = nil)
types = classification ? (classification.to_sym == :asset ? ASSET_TYPES : LIABILITY_TYPES) : TYPES
types.map { |type| type.demodulize }
end
def self.classification(type)
ASSET_TYPES.include?(type) ? :asset : :liability
end
included do
has_one :account, as: :accountable, touch: true
end
end