Class: Passifier::Storage
- Inherits:
-
Object
- Object
- Passifier::Storage
- Defined in:
- lib/passifier/storage.rb
Overview
Disk storage for a pass
Instance Attribute Summary collapse
-
#assets ⇒ Object
readonly
Returns the value of attribute assets.
-
#scratch_directory ⇒ Object
readonly
Returns the value of attribute scratch_directory.
Instance Method Summary collapse
-
#cleanup ⇒ Object
Clean up temp files.
-
#initialize(scratch_directory, assets) ⇒ Storage
constructor
A new instance of Storage.
-
#path(filename) ⇒ String
Path to the stored version.
-
#remove_zip(zip_path) ⇒ Object
Remove a zip archive.
-
#store ⇒ Object
Store the files for a group of pass assets.
-
#zip(zip_path) ⇒ String
Create a zip archive given a filename for the archive and a set of pass assets.
Constructor Details
#initialize(scratch_directory, assets) ⇒ Storage
Returns a new instance of Storage.
12 13 14 15 |
# File 'lib/passifier/storage.rb', line 12 def initialize(scratch_directory, assets) @assets = [assets].flatten @scratch_directory = scratch_directory end |
Instance Attribute Details
#assets ⇒ Object (readonly)
Returns the value of attribute assets.
8 9 10 |
# File 'lib/passifier/storage.rb', line 8 def assets @assets end |
#scratch_directory ⇒ Object (readonly)
Returns the value of attribute scratch_directory.
8 9 10 |
# File 'lib/passifier/storage.rb', line 8 def scratch_directory @scratch_directory end |
Instance Method Details
#cleanup ⇒ Object
Clean up temp files
45 46 47 48 |
# File 'lib/passifier/storage.rb', line 45 def cleanup remove_temp_files remove_directory end |
#path(filename) ⇒ String
Path to the stored version
20 21 22 |
# File 'lib/passifier/storage.rb', line 20 def path(filename) "#{@scratch_directory}/#{filename}" end |
#remove_zip(zip_path) ⇒ Object
Remove a zip archive
52 53 54 |
# File 'lib/passifier/storage.rb', line 52 def remove_zip(zip_path) File.delete(zip_path) if File.exists?(zip_path) end |
#store ⇒ Object
Store the files for a group of pass assets
26 27 28 29 |
# File 'lib/passifier/storage.rb', line 26 def store ensure_directory_exists @assets.each { |asset| write_file(asset) } end |
#zip(zip_path) ⇒ String
Create a zip archive given a filename for the archive and a set of pass assets
34 35 36 37 38 39 40 41 42 |
# File 'lib/passifier/storage.rb', line 34 def zip(zip_path) remove_zip(zip_path) # ensure that older version is deleted if it exists Zip::ZipFile.open(zip_path, Zip::ZipFile::CREATE) do |zipfile| @assets.each do |asset| zipfile.add(asset.filename, path(asset.filename)) end end zip_path end |