Class: Omnizip::Archive::Builder
- Inherits:
-
Object
- Object
- Omnizip::Archive::Builder
- Defined in:
- lib/omnizip/archive/builder.rb
Overview
Block argument of Archive.create. Translates the documented
+add_file+/+add_directory+/+add_data+ vocabulary onto the
handler proxy's add(name, source_path) / add_data calls.
Instance Method Summary collapse
-
#add_data(archive_path, data) ⇒ Object
Add in-memory content at
archive_path. -
#add_directory(dir_path) ⇒ Object
Add a directory tree under its own name:
add_directory('photos/')storesphotos/x.jpg. -
#add_file(file_path, archive_path = nil) ⇒ Object
Add a file from disk, optionally under a different archive path:
add_file('report.pdf', 'reports/report.pdf'). -
#initialize(proxy) ⇒ Builder
constructor
A new instance of Builder.
Constructor Details
#initialize(proxy) ⇒ Builder
Returns a new instance of Builder.
9 10 11 |
# File 'lib/omnizip/archive/builder.rb', line 9 def initialize(proxy) @proxy = proxy end |
Instance Method Details
#add_data(archive_path, data) ⇒ Object
Add in-memory content at archive_path.
28 29 30 |
# File 'lib/omnizip/archive/builder.rb', line 28 def add_data(archive_path, data) @proxy.add_data(archive_path, data) end |
#add_directory(dir_path) ⇒ Object
Add a directory tree under its own name:
add_directory('photos/') stores photos/x.jpg.
21 22 23 24 25 |
# File 'lib/omnizip/archive/builder.rb', line 21 def add_directory(dir_path) prefix = ::File.basename(::File.(dir_path)) @proxy.add("#{prefix}/") walk(dir_path, prefix) end |
#add_file(file_path, archive_path = nil) ⇒ Object
Add a file from disk, optionally under a different archive
path: add_file('report.pdf', 'reports/report.pdf').
15 16 17 |
# File 'lib/omnizip/archive/builder.rb', line 15 def add_file(file_path, archive_path = nil) @proxy.add(archive_path || ::File.basename(file_path), file_path) end |