Class: Passifier::Archive
- Inherits:
-
Object
- Object
- Passifier::Archive
- Defined in:
- lib/passifier/archive.rb
Overview
Represents the .pkpass archive file for the pass. Despite the extension, a .pkpass file is actually a zip archive.
Instance Attribute Summary collapse
-
#assets ⇒ Object
readonly
Returns the value of attribute assets.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
-
#data ⇒ String
The raw data of this archive file.
- #destroy ⇒ Object
-
#initialize(path, id, assets) ⇒ Archive
constructor
A new instance of Archive.
-
#store(options = {}) ⇒ Object
(also: #save)
Write the zip archive to disk.
Constructor Details
#initialize(path, id, assets) ⇒ Archive
Returns a new instance of Archive.
15 16 17 18 19 |
# File 'lib/passifier/archive.rb', line 15 def initialize(path, id, assets) @assets = assets @path = path @id = id end |
Instance Attribute Details
#assets ⇒ Object (readonly)
Returns the value of attribute assets.
9 10 11 |
# File 'lib/passifier/archive.rb', line 9 def assets @assets end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
9 10 11 |
# File 'lib/passifier/archive.rb', line 9 def id @id end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
9 10 11 |
# File 'lib/passifier/archive.rb', line 9 def path @path end |
Instance Method Details
#data ⇒ String
The raw data of this archive file
23 24 25 |
# File 'lib/passifier/archive.rb', line 23 def data File.open(@path, 'rb') {|file| file.read } unless @path.nil? end |
#destroy ⇒ Object
27 28 29 30 31 32 |
# File 'lib/passifier/archive.rb', line 27 def destroy unless @storage.nil? @storage.cleanup @storage.remove_zip(@path) end end |
#store(options = {}) ⇒ Object Also known as: save
Write the zip archive to disk
38 39 40 41 42 43 44 |
# File 'lib/passifier/archive.rb', line 38 def store( = {}) scratch_dir = [:scratch_directory] || "/tmp/passkit/#{@id}" @storage = Storage.new(scratch_dir, @assets) @storage.store @storage.zip(@path) @storage.cleanup end |