Method: Lhbackup::Backup#find_attachments

Defined in:
lib/lhbackup/backup.rb

#find_attachments(data) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/lhbackup/backup.rb', line 69

def find_attachments(data)
  print "- finding #{data.sum(&:attachments_count)} attachments"

  attachment_data = data.map do |obj|
    next if obj.attachments_count.zero?

    # individual tickets respond to attachments, but the listed ones don't
    attachments = Lighthouse::Ticket.find(obj.number, :params => {:project_id => @project.id}).attachments
    putc '.'

    attachments.each do |a|
      if a.respond_to?(:url)
        @attachments << a.url
      elsif a.respond_to?(:image) && a.image.respond_to?(:url)
        @attachments << a.image.url
      else
        puts "Whats the url for this attachment? #{a.to_json}"
      end
    end
    {obj.number => attachments} # ticket to attachments
  end.compact

  store(attachment_data, File.join(@folder, "ticket-attachments.json"))
end