Class: Capsium::Package
- Inherits:
-
Object
- Object
- Capsium::Package
- Defined in:
- lib/capsium/package.rb,
lib/capsium/package/routes.rb,
lib/capsium/package/dataset.rb,
lib/capsium/package/storage.rb,
lib/capsium/package/manifest.rb,
lib/capsium/package/metadata.rb,
lib/capsium/package/routes_config.rb,
lib/capsium/package/dataset_config.rb,
lib/capsium/package/storage_config.rb,
lib/capsium/package/manifest_config.rb,
lib/capsium/package/metadata_config.rb
Defined Under Namespace
Classes: Dataset, DatasetConfig, Dependency, Manifest, ManifestConfig, ManifestConfigItem, Metadata, MetadataData, Route, RouteTarget, Routes, RoutesConfig, Storage, StorageConfig
Constant Summary collapse
- MANIFEST_FILE =
"manifest.json"
- METADATA_FILE =
"metadata.json"
- PACKAGING_FILE =
"packaging.json"
- SIGNATURE_FILE =
"signature.json"
- STORAGE_FILE =
"storage.json"
- ROUTES_FILE =
"routes.json"
- CONTENT_DIR =
"content"
- DATA_DIR =
"data"
- ENCRYPTED_PACKAGING_FILE =
"package.enc"
Instance Attribute Summary collapse
-
#datasets ⇒ Object
readonly
Returns the value of attribute datasets.
-
#load_type ⇒ Object
readonly
Returns the value of attribute load_type.
-
#manifest ⇒ Object
readonly
Returns the value of attribute manifest.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#routes ⇒ Object
readonly
Returns the value of attribute routes.
-
#storage ⇒ Object
readonly
Returns the value of attribute storage.
Instance Method Summary collapse
- #cleanup ⇒ Object
- #content_files ⇒ Object
- #decompress_cap_file(file_path) ⇒ Object
- #determine_load_type(path) ⇒ Object
-
#initialize(path, load_type: nil) ⇒ Package
constructor
A new instance of Package.
- #load_package ⇒ Object
- #package_files ⇒ Object
- #prepare_package(path) ⇒ Object
- #solidify ⇒ Object
Constructor Details
#initialize(path, load_type: nil) ⇒ Package
Returns a new instance of Package.
32 33 34 35 36 37 38 39 |
# File 'lib/capsium/package.rb', line 32 def initialize(path, load_type: nil) @original_path = Pathname.new(path). @path = prepare_package(@original_path) @load_type = load_type || determine_load_type(path) create_package_structure load_package @name = .name end |
Instance Attribute Details
#datasets ⇒ Object (readonly)
Returns the value of attribute datasets.
19 20 21 |
# File 'lib/capsium/package.rb', line 19 def datasets @datasets end |
#load_type ⇒ Object (readonly)
Returns the value of attribute load_type.
19 20 21 |
# File 'lib/capsium/package.rb', line 19 def load_type @load_type end |
#manifest ⇒ Object (readonly)
Returns the value of attribute manifest.
19 20 21 |
# File 'lib/capsium/package.rb', line 19 def manifest @manifest end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
19 20 21 |
# File 'lib/capsium/package.rb', line 19 def @metadata end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
19 20 21 |
# File 'lib/capsium/package.rb', line 19 def name @name end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
19 20 21 |
# File 'lib/capsium/package.rb', line 19 def path @path end |
#routes ⇒ Object (readonly)
Returns the value of attribute routes.
19 20 21 |
# File 'lib/capsium/package.rb', line 19 def routes @routes end |
#storage ⇒ Object (readonly)
Returns the value of attribute storage.
19 20 21 |
# File 'lib/capsium/package.rb', line 19 def storage @storage end |
Instance Method Details
#cleanup ⇒ Object
99 100 101 102 103 |
# File 'lib/capsium/package.rb', line 99 def cleanup return unless @path != @original_path && File.directory?(@path) FileUtils.remove_entry(@path) end |
#content_files ⇒ Object
109 110 111 112 113 |
# File 'lib/capsium/package.rb', line 109 def content_files Dir.glob(File.join(content_path, "**", "*")).select do |file| File.file?(file) end end |
#decompress_cap_file(file_path) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/capsium/package.rb', line 60 def decompress_cap_file(file_path) temp_dir = Dir.mktmpdir = File.join(temp_dir, METADATA_FILE) # Extract metadata.json first Zip::File.open(file_path) do |zip_file| if entry = zip_file.find_entry(METADATA_FILE) entry.extract() end end = Metadata.new() package_name = .name package_version = .version package_path = File.join(temp_dir, "#{package_name}-#{package_version}") FileUtils.mkdir_p(package_path) Zip::File.open(file_path) do |zip_file| zip_file.each do |entry| entry_path = File.join(package_path, entry.name) FileUtils.mkdir_p(File.dirname(entry_path)) entry.extract(entry_path) end end package_path end |
#determine_load_type(path) ⇒ Object
115 116 117 118 119 120 |
# File 'lib/capsium/package.rb', line 115 def determine_load_type(path) return :directory if File.directory?(path) return :cap_file if File.extname(path) == ".cap" :unsaved end |
#load_package ⇒ Object
89 90 91 92 93 94 95 96 97 |
# File 'lib/capsium/package.rb', line 89 def load_package # Mandatory @metadata = Metadata.new() # Optional @manifest = Manifest.new(manifest_path) @storage = Storage.new(storage_path) @routes = Routes.new(routes_path, @manifest, @storage) end |
#package_files ⇒ Object
105 106 107 |
# File 'lib/capsium/package.rb', line 105 def package_files @packager.package_files end |
#prepare_package(path) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/capsium/package.rb', line 41 def prepare_package(path) return path if File.directory?(path) if File.file?(path) return decompress_cap_file(path) if File.extname(path) == ".cap" raise "Error: The package must have a .cap extension" end raise "Invalid package path: #{path}" end |
#solidify ⇒ Object
53 54 55 56 57 58 |
# File 'lib/capsium/package.rb', line 53 def solidify @manifest.save_to_file @metadata.save_to_file @routes.save_to_file @storage.save_to_file end |