Class: Raykit::Zip
- Inherits:
-
Object
- Object
- Raykit::Zip
- Defined in:
- lib/raykit/zip.rb
Instance Method Summary collapse
- #exclude_glob(glob) ⇒ Object
- #include_glob(glob) ⇒ Object
-
#initialize(filename) ⇒ Zip
constructor
A new instance of Zip.
- #source_dir(dir) ⇒ Object
- #zip ⇒ Object
Constructor Details
Instance Method Details
#exclude_glob(glob) ⇒ Object
29 30 31 32 |
# File 'lib/raykit/zip.rb', line 29 def exclude_glob(glob) @exclude_globs << glob self end |
#include_glob(glob) ⇒ Object
24 25 26 27 |
# File 'lib/raykit/zip.rb', line 24 def include_glob(glob) @include_globs << glob self end |
#source_dir(dir) ⇒ Object
19 20 21 22 |
# File 'lib/raykit/zip.rb', line 19 def source_dir(dir) @source_dir = dir self end |
#zip ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/raykit/zip.rb', line 34 def zip path = File.dirname(@filename) FileUtils.mkdir_p(path) unless Dir.exist?(path) files_to_archive = Array::new() Dir.chdir(@source_dir) do #include_files = [] @include_globs.each do |include_glob| Dir.glob(include_glob) { |f| #puts "\n" + f files_to_archive << f } end end ::Zip::File::open(@filename, ::Zip::File::CREATE) { |zipfile| count = 0 files_to_archive.each do |file| zipfile.get_output_stream(file) { |f| fr = ::File.open("#{@source_dir}/#{file}", "rb") #f.puts(fr.read) fr.close() f.close() count=count+1 } end zipfile.close puts " added " << count << " files to " << @filename } end |