Class: Plum::SiteArchive::Exporter
- Inherits:
-
Object
- Object
- Plum::SiteArchive::Exporter
- Defined in:
- app/services/plum/site_archive.rb
Instance Method Summary collapse
-
#initialize(site) ⇒ Exporter
constructor
A new instance of Exporter.
- #write(path) ⇒ Object
Constructor Details
#initialize(site) ⇒ Exporter
Returns a new instance of Exporter.
25 26 27 |
# File 'app/services/plum/site_archive.rb', line 25 def initialize(site) @site = site end |
Instance Method Details
#write(path) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'app/services/plum/site_archive.rb', line 29 def write(path) destination = Pathname(path). destination.dirname.mkpath FileUtils.rm_f(destination) Zip::File.open(destination, create: true) do |zip| zip.get_output_stream("manifest.json") { |stream| stream.write(JSON.pretty_generate(manifest)) } site.assets.with_attached_file.find_each do |asset| next unless asset.file.attached? zip.get_output_stream(asset_path(asset)) do |stream| asset.file.blob.open { |file| IO.copy_stream(file, stream) } end end end destination end |