You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1.2 KiB

  1. # frozen_string_literal: true
  2. # == Schema Information
  3. #
  4. # Table name: imports
  5. #
  6. # id :bigint(8) not null, primary key
  7. # type :integer not null
  8. # approved :boolean default(FALSE), not null
  9. # created_at :datetime not null
  10. # updated_at :datetime not null
  11. # data_file_name :string
  12. # data_content_type :string
  13. # data_file_size :integer
  14. # data_updated_at :datetime
  15. # account_id :bigint(8) not null
  16. # overwrite :boolean default(FALSE), not null
  17. #
  18. class Import < ApplicationRecord
  19. FILE_TYPES = %w(text/plain text/csv application/csv).freeze
  20. MODES = %i(merge overwrite).freeze
  21. self.inheritance_column = false
  22. belongs_to :account
  23. enum type: [:following, :blocking, :muting, :domain_blocking, :bookmarks]
  24. validates :type, presence: true
  25. validates_with ImportValidator, on: :create
  26. has_attached_file :data
  27. validates_attachment_content_type :data, content_type: FILE_TYPES
  28. validates_attachment_presence :data
  29. def mode
  30. overwrite? ? :overwrite : :merge
  31. end
  32. def mode=(str)
  33. self.overwrite = str.to_sym == :overwrite
  34. end
  35. end