mirror of
https://github.com/we-promise/sure.git
synced 2026-04-18 19:44:09 +00:00
Account namespace updates: part 1 (#893)
* Rename accountable types * Merge conflicts * Fix broken tests * Add back sidebar changes
This commit is contained in:
@@ -1,3 +0,0 @@
|
||||
class Account::Credit < ApplicationRecord
|
||||
include Accountable
|
||||
end
|
||||
@@ -1,3 +0,0 @@
|
||||
class Account::Crypto < ApplicationRecord
|
||||
include Accountable
|
||||
end
|
||||
@@ -1,3 +0,0 @@
|
||||
class Account::Depository < ApplicationRecord
|
||||
include Accountable
|
||||
end
|
||||
@@ -1,3 +0,0 @@
|
||||
class Account::Loan < ApplicationRecord
|
||||
include Accountable
|
||||
end
|
||||
@@ -1,3 +0,0 @@
|
||||
class Account::OtherAsset < ApplicationRecord
|
||||
include Accountable
|
||||
end
|
||||
@@ -1,3 +0,0 @@
|
||||
class Account::OtherLiability < ApplicationRecord
|
||||
include Accountable
|
||||
end
|
||||
@@ -1,3 +0,0 @@
|
||||
class Account::Property < ApplicationRecord
|
||||
include Accountable
|
||||
end
|
||||
@@ -1,3 +0,0 @@
|
||||
class Account::Vehicle < ApplicationRecord
|
||||
include Accountable
|
||||
end
|
||||
@@ -1,28 +1,19 @@
|
||||
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 ]
|
||||
ASSET_TYPES = %w[ Depository Investment Crypto Property Vehicle OtherAsset ]
|
||||
LIABILITY_TYPES = %w[ CreditCard Loan OtherLiability ]
|
||||
TYPES = ASSET_TYPES + LIABILITY_TYPES
|
||||
|
||||
def self.from_type(type)
|
||||
return nil unless types.include?(type) || TYPES.include?(type)
|
||||
"Account::#{type.demodulize}".constantize
|
||||
return nil unless TYPES.include?(type)
|
||||
type.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
|
||||
|
||||
3
app/models/credit_card.rb
Normal file
3
app/models/credit_card.rb
Normal file
@@ -0,0 +1,3 @@
|
||||
class CreditCard < ApplicationRecord
|
||||
include Accountable
|
||||
end
|
||||
3
app/models/crypto.rb
Normal file
3
app/models/crypto.rb
Normal file
@@ -0,0 +1,3 @@
|
||||
class Crypto < ApplicationRecord
|
||||
include Accountable
|
||||
end
|
||||
3
app/models/depository.rb
Normal file
3
app/models/depository.rb
Normal file
@@ -0,0 +1,3 @@
|
||||
class Depository < ApplicationRecord
|
||||
include Accountable
|
||||
end
|
||||
@@ -1,4 +1,4 @@
|
||||
class Account::Investment < ApplicationRecord
|
||||
class Investment < ApplicationRecord
|
||||
include Accountable
|
||||
|
||||
SUBTYPES = [
|
||||
3
app/models/loan.rb
Normal file
3
app/models/loan.rb
Normal file
@@ -0,0 +1,3 @@
|
||||
class Loan < ApplicationRecord
|
||||
include Accountable
|
||||
end
|
||||
3
app/models/other_asset.rb
Normal file
3
app/models/other_asset.rb
Normal file
@@ -0,0 +1,3 @@
|
||||
class OtherAsset < ApplicationRecord
|
||||
include Accountable
|
||||
end
|
||||
3
app/models/other_liability.rb
Normal file
3
app/models/other_liability.rb
Normal file
@@ -0,0 +1,3 @@
|
||||
class OtherLiability < ApplicationRecord
|
||||
include Accountable
|
||||
end
|
||||
3
app/models/property.rb
Normal file
3
app/models/property.rb
Normal file
@@ -0,0 +1,3 @@
|
||||
class Property < ApplicationRecord
|
||||
include Accountable
|
||||
end
|
||||
3
app/models/vehicle.rb
Normal file
3
app/models/vehicle.rb
Normal file
@@ -0,0 +1,3 @@
|
||||
class Vehicle < ApplicationRecord
|
||||
include Accountable
|
||||
end
|
||||
Reference in New Issue
Block a user