atk_toolbox 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/atk/zip.rb +54 -0
- data/lib/atk_toolbox/version.rb +1 -1
- metadata +23 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 83c904fd5954d29df2f5bf67dcb63122d2e0b39b5bbc215642757ccac53b462a
|
4
|
+
data.tar.gz: 0b80500fc3a019a1973ae1cbccb8d940797fbbb1f5e5ac30f22b1b20f087b310
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 519280dc2415995524f68c6079c20d8f464f8e8b6adf0d4d1d26b630a6efd8f6802dfb06aef30f814e4114d0bb4b0b148150847ce1ea4fc67cf9dc8eae4d0c9e
|
7
|
+
data.tar.gz: 165adb9a2f4e1c647dced4fb0f25560800cf0629e900c2931e4bd7fe80fb106696e9e21d9b08c51dcce0170b897079ab739785ad9a6d12aab9652f6c956ef0b8
|
data/lib/atk/zip.rb
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'zip'
|
2
|
+
|
3
|
+
class ZipFileGenerator
|
4
|
+
# Initialize with the directory to zip and the location of the output archive.
|
5
|
+
def initialize(input_dir, output_file)
|
6
|
+
@input_dir = input_dir
|
7
|
+
@output_file = output_file
|
8
|
+
end
|
9
|
+
|
10
|
+
# Zip the input directory.
|
11
|
+
def write
|
12
|
+
entries = Dir.entries(@input_dir) - %w[. ..]
|
13
|
+
|
14
|
+
Zip::ZipFile.open(@output_file, Zip::ZipFile::CREATE) do |zipfile|
|
15
|
+
write_entries entries, '', zipfile
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
# A helper method to make the recursion work.
|
22
|
+
def write_entries(entries, path, zipfile)
|
23
|
+
entries.each do |e|
|
24
|
+
zipfile_path = path == '' ? e : File.join(path, e)
|
25
|
+
disk_file_path = File.join(@input_dir, zipfile_path)
|
26
|
+
|
27
|
+
if File.directory? disk_file_path
|
28
|
+
recursively_deflate_directory(disk_file_path, zipfile, zipfile_path)
|
29
|
+
else
|
30
|
+
put_into_archive(disk_file_path, zipfile, zipfile_path)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def recursively_deflate_directory(disk_file_path, zipfile, zipfile_path)
|
36
|
+
zipfile.mkdir zipfile_path
|
37
|
+
subdir = Dir.entries(disk_file_path) - %w[. ..]
|
38
|
+
write_entries subdir, zipfile_path, zipfile
|
39
|
+
end
|
40
|
+
|
41
|
+
def put_into_archive(disk_file_path, zipfile, zipfile_path)
|
42
|
+
zipfile.add(zipfile_path, disk_file_path)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
|
47
|
+
def zip(source, destination=nil)
|
48
|
+
if destination == nil
|
49
|
+
destination = source + ".zip"
|
50
|
+
end
|
51
|
+
|
52
|
+
zip_helper = ZipFileGenerator.new(source, destination)
|
53
|
+
zip_helper.write()
|
54
|
+
end
|
data/lib/atk_toolbox/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: atk_toolbox
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeff Hykin
|
@@ -9,7 +9,27 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
date: 2019-06-07 00:00:00.000000000 Z
|
12
|
-
dependencies:
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: zip
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.0'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 2.0.2
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '2.0'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 2.0.2
|
13
33
|
description: ''
|
14
34
|
email: jeff.hykin@gmail.com
|
15
35
|
executables: []
|
@@ -24,6 +44,7 @@ files:
|
|
24
44
|
- lib/atk/package_managers.rb
|
25
45
|
- lib/atk/remove_indent.rb
|
26
46
|
- lib/atk/yaml_info_parser.rb
|
47
|
+
- lib/atk/zip.rb
|
27
48
|
- lib/atk_toolbox.rb
|
28
49
|
- lib/atk_toolbox/version.rb
|
29
50
|
- lib/yaml_edit/remove_key.py
|