Class: Dpl::Zip
- Inherits:
-
Struct
- Object
- Struct
- Dpl::Zip
- Defined in:
- lib/dpl/helper/zip.rb
Constant Summary collapse
- ZIP_EXT =
%w(.zip .jar)
Instance Attribute Summary collapse
-
#dest ⇒ Object
Returns the value of attribute dest.
-
#opts ⇒ Object
Returns the value of attribute opts.
-
#src ⇒ Object
Returns the value of attribute src.
Instance Method Summary collapse
- #copy ⇒ Object
- #create(files) ⇒ Object
- #dir?(path = src) ⇒ Boolean
- #dot_match? ⇒ Boolean
- #exts ⇒ Object
- #glob ⇒ Object
-
#initialize ⇒ Zip
constructor
A new instance of Zip.
- #zip ⇒ Object
- #zip_dir ⇒ Object
- #zip_file ⇒ Object
- #zip_file? ⇒ Boolean
Constructor Details
#initialize ⇒ Zip
Returns a new instance of Zip.
7 8 9 10 |
# File 'lib/dpl/helper/zip.rb', line 7 def initialize(*) require 'zip' super end |
Instance Attribute Details
#dest ⇒ Object
Returns the value of attribute dest
4 5 6 |
# File 'lib/dpl/helper/zip.rb', line 4 def dest @dest end |
#opts ⇒ Object
Returns the value of attribute opts
4 5 6 |
# File 'lib/dpl/helper/zip.rb', line 4 def opts @opts end |
#src ⇒ Object
Returns the value of attribute src
4 5 6 |
# File 'lib/dpl/helper/zip.rb', line 4 def src @src end |
Instance Method Details
#copy ⇒ Object
47 48 49 |
# File 'lib/dpl/helper/zip.rb', line 47 def copy FileUtils.cp(src, dest) end |
#create(files) ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/dpl/helper/zip.rb', line 30 def create(files) ::Zip::File.open(dest, ::Zip::File::CREATE) do |zip| files.each do |file| zip.add(file.sub("#{src}/", ''), file) end end File.new(dest) end |
#dir?(path = src) ⇒ Boolean
43 44 45 |
# File 'lib/dpl/helper/zip.rb', line 43 def dir?(path = src) File.directory?(path) end |
#dot_match? ⇒ Boolean
57 58 59 |
# File 'lib/dpl/helper/zip.rb', line 57 def dot_match? opts[:dot_match] end |
#exts ⇒ Object
61 62 63 |
# File 'lib/dpl/helper/zip.rb', line 61 def exts opts[:exts] ||= ZIP_EXT end |
#glob ⇒ Object
51 52 53 54 55 |
# File 'lib/dpl/helper/zip.rb', line 51 def glob glob = ["#{src}/**/*"] glob << File::FNM_DOTMATCH if dot_match? glob end |
#zip ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/dpl/helper/zip.rb', line 12 def zip if zip_file? File.new(src) elsif dir? zip_dir else zip_file end end |
#zip_dir ⇒ Object
22 23 24 |
# File 'lib/dpl/helper/zip.rb', line 22 def zip_dir create(Dir.glob(*glob).reject { |path| dir?(path) }) end |
#zip_file ⇒ Object
26 27 28 |
# File 'lib/dpl/helper/zip.rb', line 26 def zip_file create([src]) end |
#zip_file? ⇒ Boolean
39 40 41 |
# File 'lib/dpl/helper/zip.rb', line 39 def zip_file? exts.include?(File.extname(src)) end |