Class: Passifier::Archive

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(path, id, assets) ⇒ Archive

Returns a new instance of Archive.

Parameters:

  • path (String)

    The archive path

  • id (String)

    An ID to represent the 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

#assetsObject (readonly)

Returns the value of attribute assets.



9
10
11
# File 'lib/passifier/archive.rb', line 9

def assets
  @assets
end

#idObject (readonly)

Returns the value of attribute id.



9
10
11
# File 'lib/passifier/archive.rb', line 9

def id
  @id
end

#pathObject (readonly)

Returns the value of attribute path.



9
10
11
# File 'lib/passifier/archive.rb', line 9

def path
  @path
end

Instance Method Details

#dataString

The raw data of this archive file

Returns:

  • (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

#destroyObject



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

Parameters:

  • options (Hash) (defaults to: {})

    The options to store an Archive with.

  • opts (Hash)

    a customizable set of options



38
39
40
41
42
43
44
# File 'lib/passifier/archive.rb', line 38

def store(options = {})
  scratch_dir = options[:scratch_directory] || "/tmp/passkit/#{@id}"
  @storage = Storage.new(scratch_dir, @assets)
  @storage.store
  @storage.zip(@path)
  @storage.cleanup
end