import.rb 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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).freeze
  20. MODES = %i(merge overwrite).freeze
  21. self.inheritance_column = false
  22. belongs_to :account
  23. enum type: [:following, :blocking, :muting, :domain_blocking]
  24. validates :type, presence: true
  25. has_attached_file :data
  26. validates_attachment_content_type :data, content_type: FILE_TYPES
  27. validates_attachment_presence :data
  28. def mode
  29. overwrite? ? :overwrite : :merge
  30. end
  31. def mode=(str)
  32. self.overwrite = str.to_sym == :overwrite
  33. end
  34. end