Module: Everywhere::Platform::Snapshot
- Defined in:
- lib/everywhere/platform/snapshot.rb
Overview
Packs the app's source into a .tar.gz for a Platform build, honoring
.everywhereignore (so dist/, node_modules, .git, secrets never ship). Pure
Ruby — no tar dependency — and streams file-by-file so a large tree
doesn't blow up memory.
Class Method Summary collapse
- .add(tar, root, rel) ⇒ Object
-
.create(root, out_path) ⇒ Object
Writes root's non-ignored files to out_path (a .tar.gz).
-
.md5_base64(path) ⇒ Object
base64 MD5 of a file (what Active Storage's direct upload verifies), computed in chunks so large snapshots don't load into memory.
Class Method Details
.add(tar, root, rel) ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/everywhere/platform/snapshot.rb', line 39 def add(tar, root, rel) abs = File.join(root, rel) stat = File.stat(abs) tar.add_file_simple(rel, stat.mode & 0o777, stat.size) do |io| File.open(abs, "rb") { |f| IO.copy_stream(f, io) } end end |
.create(root, out_path) ⇒ Object
Writes root's non-ignored files to out_path (a .tar.gz). Returns the file count.
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/everywhere/platform/snapshot.rb', line 19 def create(root, out_path) files = Everywhere::Ignore.for(root).files(root) File.open(out_path, "wb") do |dest| Zlib::GzipWriter.wrap(dest) do |gz| Gem::Package::TarWriter.new(gz) do |tar| files.each { |rel| add(tar, root, rel) } end end end files.size end |
.md5_base64(path) ⇒ Object
base64 MD5 of a file (what Active Storage's direct upload verifies), computed in chunks so large snapshots don't load into memory.
33 34 35 36 37 |
# File 'lib/everywhere/platform/snapshot.rb', line 33 def md5_base64(path) digest = Digest::MD5.new File.open(path, "rb") { |f| digest << f.read(1 << 20) until f.eof? } digest.base64digest end |