dawarich/app/models/export.rb

26 lines
513 B
Ruby
Raw Normal View History

2024-06-12 14:29:38 -04:00
# frozen_string_literal: true
class Export < ApplicationRecord
belongs_to :user
2024-09-05 15:01:59 -04:00
enum :status, { created: 0, processing: 1, completed: 2, failed: 3 }
2025-04-04 14:14:44 -04:00
enum :file_format, { json: 0, gpx: 1 }
2024-06-12 14:29:38 -04:00
validates :name, presence: true
2025-04-04 14:14:44 -04:00
has_one_attached :file
2024-06-12 14:29:38 -04:00
2025-04-04 14:14:44 -04:00
after_commit -> { ExportJob.perform_later(id) }, on: :create
after_commit -> { remove_attached_file }, on: :destroy
def process!
Exports::Create.new(export: self).call
end
2024-06-12 14:29:38 -04:00
2025-04-04 14:14:44 -04:00
private
2024-06-12 14:29:38 -04:00
2025-04-04 14:14:44 -04:00
def remove_attached_file
file.purge_later
2024-06-12 14:29:38 -04:00
end
end