Module: Capsium::Package::Preparation
- Included in:
- Capsium::Package
- Defined in:
- lib/capsium/package/preparation.rb,
sig/capsium/package/preparation.rbs
Overview
Package-source preparation (ARCHITECTURE.md section 1), mixed into Package: directory/.cap/encrypted-cap detection, extraction and decryption into a readable package directory.
Instance Method Summary collapse
- #decompress_cap_file(file_path) ⇒ String
-
#decrypt_cap_file(source_path) ⇒ String
Decrypts an encrypted package (.cap file or uncompressed directory) into a temporary directory and returns its path.
- #determine_load_type(path) ⇒ Symbol
-
#encrypted? ⇒ Boolean
Whether the package was loaded from an encrypted source (ARCHITECTURE.md section 6b layout).
- #prepare_package(path) ⇒ String, Pathname
Instance Method Details
#decompress_cap_file(file_path) ⇒ String
21 22 23 24 25 26 |
# File 'lib/capsium/package/preparation.rb', line 21 def decompress_cap_file(file_path) package_path = File.join(Dir.mktmpdir, package_stem(file_path)) FileUtils.mkdir_p(package_path) Packager.new.unpack(file_path, package_path) package_path end |
#decrypt_cap_file(source_path) ⇒ String
Decrypts an encrypted package (.cap file or uncompressed directory) into a temporary directory and returns its path. Raises Cipher::KeyRequiredError when no decryption_key was given.
32 33 34 35 36 37 38 39 |
# File 'lib/capsium/package/preparation.rb', line 32 def decrypt_cap_file(source_path) unless @decryption_key raise Cipher::KeyRequiredError, "Package is encrypted; provide the private key via decryption_key:" end Cipher.decrypt_to_directory(source_path, @decryption_key) end |
#determine_load_type(path) ⇒ Symbol
41 42 43 44 45 |
# File 'lib/capsium/package/preparation.rb', line 41 def determine_load_type(path) return :directory if File.directory?(path) File.extname(path) == ".cap" ? :cap_file : :unsaved end |
#encrypted? ⇒ Boolean
Whether the package was loaded from an encrypted source (ARCHITECTURE.md section 6b layout).
49 50 51 |
# File 'lib/capsium/package/preparation.rb', line 49 def encrypted? Cipher.encrypted?(@original_path) end |
#prepare_package(path) ⇒ String, Pathname
12 13 14 15 16 17 18 19 |
# File 'lib/capsium/package/preparation.rb', line 12 def prepare_package(path) return decrypt_cap_file(path) if Cipher.encrypted?(path) return path if File.directory?(path) raise Error, "Invalid package path: #{path}" unless File.file?(path) raise Error, "The package must have a .cap extension" unless File.extname(path) == ".cap" decompress_cap_file(path) end |