Class: Passkit::Generator

Inherits:
Object
  • Object
show all
Defined in:
lib/passkit/generator.rb,
sig/lib/passkit/generator.rbs

Constant Summary collapse

TMP_FOLDER =

Returns:

  • (String)
Rails.root.join("tmp/passkit").freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pass) ⇒ Generator

Returns a new instance of Generator.

Parameters:



7
8
9
10
# File 'lib/passkit/generator.rb', line 7

def initialize(pass)
  @pass = pass
  @generator = pass.generator
end

Class Method Details

.compress_passes_files(files) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/passkit/generator.rb', line 26

def self.compress_passes_files(files)
  zip_path = TMP_FOLDER.join("#{SecureRandom.uuid}.pkpasses")
  zipped_file = File.open(zip_path, "w")

  Zip::OutputStream.open(zipped_file.path) do |z|
    files.each do |file|
      z.put_next_entry(File.basename(file))
      z.print File.read(file)
    end
  end
  zip_path
end

Instance Method Details

#generate_and_signString

Returns:

  • (String)


12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/passkit/generator.rb', line 12

def generate_and_sign
  check_necessary_files
  create_temporary_directory
  copy_pass_to_tmp_location
  @pass.instance.add_other_files(@temporary_path)
  clean_ds_store_files
  I18n.with_locale(@pass.language) do
    generate_json_pass
  end
  generate_json_manifest
  sign_manifest
  compress_pass_file
end