class Capsium::Packager
Constants
- DOT_ENTRIES
- DRIVE_LETTER_PATTERN
Public Instance Methods
(Package package, String cap_file) → void
Source
# File lib/capsium/packager.rb, line 45 def compress_package(package, cap_file) entries = Dir.glob(File.join(package.path, "**", "**"), File::FNM_DOTMATCH).reject do |file| File.expand_path(file) == File.expand_path(cap_file) || DOT_ENTRIES.include?(File.basename(file)) end Zip::File.open(cap_file, create: true) do |zipfile| entries.each do |file| zipfile.add(file.sub("#{package.path}/", ""), file) end end end
(Package package, ?Hash[Symbol, untyped] options) → String
Source
# File lib/capsium/packager.rb, line 21 def pack(package, options = {}) output_file_name = "#{package.metadata.name}-#{package.metadata.version}.cap" cap_file_path = File.join(File.dirname(package.path), output_file_name) check_target(cap_file_path, options) Dir.mktmpdir do |dir| build_cap(package, dir, output_file_name, options) FileUtils.mv(File.join(dir, output_file_name), cap_file_path) puts "Package created: #{relative_path_current(cap_file_path)}" return cap_file_path end end
(String absolute_path) → String
Source
# File lib/capsium/packager.rb, line 82 def relative_path_current(absolute_path) Pathname.new(absolute_path).relative_path_from(Dir.pwd).to_s end
(String cap_path) { (String dir) → untyped } → String
Source
# File lib/capsium/packager.rb, line 70 def transform_cap(cap_path) with_unpacked_cap(cap_path) do |dir| yield dir Dir.mktmpdir do |tmp| tmp_cap = File.join(tmp, File.basename(cap_path)) compress_package(Package.new(dir), tmp_cap) FileUtils.mv(tmp_cap, cap_path) end end cap_path end
Unpacks a .cap into a temporary directory, yields it for modification, then recompresses the result back over cap_path. The modified package is loaded (verifying integrity and any declared signature) before recompressing.
(String cap_file_path, String destination) → void
Source
# File lib/capsium/packager.rb, line 34 def unpack(cap_file_path, destination) destination = File.expand_path(destination) Zip::File.open(cap_file_path) do |zip_file| zip_file.each do |entry| entry_path = safe_entry_path(destination, entry.name) FileUtils.mkdir_p(File.dirname(entry_path)) entry.extract(entry_path) end end end
(String cap_path) { (String dir) → untyped } → untyped
Source
# File lib/capsium/packager.rb, line 59 def with_unpacked_cap(cap_path) Dir.mktmpdir do |dir| unpack(cap_path, dir) yield dir end end
Unpacks a .cap into a temporary directory, yields it for read-only inspection and returns the block’s value.