1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-07-19 13:19:39 +02:00
Maybe/app/models/import/mapping.rb
Zach Gollwitzer 0544089710
Some checks are pending
Publish Docker image / ci (push) Waiting to run
Publish Docker image / Build docker image (push) Blocked by required conditions
Account-level import configuration templates (#1946)
* Account-level import configuration templates

* Default import to family's preferred date format
2025-03-04 13:10:01 -05:00

45 lines
1.3 KiB
Ruby

class Import::Mapping < ApplicationRecord
CREATE_NEW_KEY = "internal_new_resource"
belongs_to :import
belongs_to :mappable, polymorphic: true, optional: true
validates :key, presence: true, uniqueness: { scope: [ :import_id, :type ] }, allow_blank: true
scope :for_import, ->(import) { where(import: import) }
scope :creational, -> { where(create_when_empty: true, mappable: nil) }
scope :categories, -> { where(type: "Import::CategoryMapping") }
scope :tags, -> { where(type: "Import::TagMapping") }
scope :accounts, -> { where(type: "Import::AccountMapping") }
scope :account_types, -> { where(type: "Import::AccountTypeMapping") }
class << self
def mappable_for(key)
find_by(key: key)&.mappable
end
def mappables_by_key(import)
raise NotImplementedError, "Subclass must implement mappables_by_key"
end
end
def selectable_values
raise NotImplementedError, "Subclass must implement selectable_values"
end
def values_count
raise NotImplementedError, "Subclass must implement values_count"
end
def mappable_class
nil
end
def creatable?
mappable.nil? && key.present? && create_when_empty
end
def create_mappable!
raise NotImplementedError, "Subclass must implement create_mappable!"
end
end