Class: Dpl::Zip
- Inherits:
-
Struct
- Object
- Struct
- Dpl::Zip
- Defined in:
- lib/dpl/helper/zip.rb
Constant Summary collapse
- ZIP_EXT =
%w[.zip .jar].freeze
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.
9 10 11 12 |
# File 'lib/dpl/helper/zip.rb', line 9 def initialize(*) require 'zip' super end |
Instance Attribute Details
#dest ⇒ Object
Returns the value of attribute dest
6 7 8 |
# File 'lib/dpl/helper/zip.rb', line 6 def dest @dest end |
#opts ⇒ Object
Returns the value of attribute opts
6 7 8 |
# File 'lib/dpl/helper/zip.rb', line 6 def opts @opts end |
#src ⇒ Object
Returns the value of attribute src
6 7 8 |
# File 'lib/dpl/helper/zip.rb', line 6 def src @src end |
Instance Method Details
#copy ⇒ Object
49 50 51 |
# File 'lib/dpl/helper/zip.rb', line 49 def copy FileUtils.cp(src, dest) end |
#create(files) ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/dpl/helper/zip.rb', line 32 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
45 46 47 |
# File 'lib/dpl/helper/zip.rb', line 45 def dir?(path = src) File.directory?(path) end |
#dot_match? ⇒ Boolean
59 60 61 |
# File 'lib/dpl/helper/zip.rb', line 59 def dot_match? opts[:dot_match] end |
#exts ⇒ Object
63 64 65 |
# File 'lib/dpl/helper/zip.rb', line 63 def exts opts[:exts] ||= ZIP_EXT end |
#glob ⇒ Object
53 54 55 56 57 |
# File 'lib/dpl/helper/zip.rb', line 53 def glob glob = ["#{src}/**/*"] glob << File::FNM_DOTMATCH if dot_match? glob end |
#zip ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/dpl/helper/zip.rb', line 14 def zip if zip_file? File.new(src) elsif dir? zip_dir else zip_file end end |
#zip_dir ⇒ Object
24 25 26 |
# File 'lib/dpl/helper/zip.rb', line 24 def zip_dir create(Dir.glob(*glob).reject { |path| dir?(path) }) end |
#zip_file ⇒ Object
28 29 30 |
# File 'lib/dpl/helper/zip.rb', line 28 def zip_file create([src]) end |
#zip_file? ⇒ Boolean
41 42 43 |
# File 'lib/dpl/helper/zip.rb', line 41 def zip_file? exts.include?(File.extname(src)) end |