Class: PhotoExporter

Inherits:
Object
  • Object
show all
Defined in:
lib/photo_exporter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user) ⇒ PhotoExporter

Returns a new instance of PhotoExporter.


6
7
8
# File 'lib/photo_exporter.rb', line 6

def initialize(user)
  @user = user
end

Instance Attribute Details

#userObject (readonly)

Returns the value of attribute user


4
5
6
# File 'lib/photo_exporter.rb', line 4

def user
  @user
end

Instance Method Details

#performObject


10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/photo_exporter.rb', line 10

def perform
  temp_zip = Tempfile.new([user.username, "_photos.zip"])
  begin
    Zip::OutputStream.open(temp_zip.path) do |zip_output_stream|
      user.photos.each do |photo|
        export_photo(zip_output_stream, photo)
      end
    end
  ensure
    temp_zip.close
  end

  update_exported_photos_at(temp_zip)
end