2024-02-02 23:09:35 +00:00
|
|
|
module Accountable
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
2024-03-19 14:34:35 -05:00
|
|
|
ASSET_TYPES = %w[ Account::Depository Account::Investment Account::Crypto Account::OtherAsset Account::Property Account::Vehicle ]
|
2024-03-19 09:10:40 -04:00
|
|
|
LIABILITY_TYPES = %w[ Account::Credit Account::Loan Account::OtherLiability ]
|
|
|
|
TYPES = ASSET_TYPES + LIABILITY_TYPES
|
2024-02-09 14:26:54 +00:00
|
|
|
|
|
|
|
def self.from_type(type)
|
|
|
|
return nil unless types.include?(type) || TYPES.include?(type)
|
|
|
|
"Account::#{type.demodulize}".constantize
|
|
|
|
end
|
|
|
|
|
2024-03-19 09:10:40 -04:00
|
|
|
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
|
2024-02-09 14:26:54 +00:00
|
|
|
end
|
|
|
|
|
2024-02-02 23:09:35 +00:00
|
|
|
included do
|
|
|
|
has_one :account, as: :accountable, touch: true
|
|
|
|
end
|
|
|
|
end
|