attachment_factory.rb 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. module Import
  2. module Zendesk
  3. class Ticket
  4. class Comment
  5. module AttachmentFactory
  6. # we need to loop over each instead of all!
  7. # so we can use the default import factory here
  8. extend Import::Factory
  9. # rubocop:disable Style/ModuleFunction
  10. extend self
  11. private
  12. # special handling which only starts import if needed
  13. # Attention: skip? method can't be used since it (currently)
  14. # only checks for single records - not all
  15. def import_loop(records, *args, &import_block)
  16. local_article = args[0]
  17. local_attachments = local_article.attachments
  18. return if local_attachments.count == records.count
  19. # get a common ground
  20. local_attachments.each(&:delete)
  21. return if records.empty?
  22. records.each(&import_block)
  23. end
  24. def create_instance(record, *args)
  25. local_article = args[0]
  26. backend_class(record).new(record, local_article)
  27. end
  28. end
  29. end
  30. end
  31. end
  32. end