real_zip 0.0.8 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/real_zip/version.rb +1 -1
- data/lib/real_zip.rb +19 -51
- data/real_zip.gemspec +1 -1
- data/spec/examples_spec.rb +31 -29
- data/spec/support/my_temp.rb +26 -0
- data/spec/support/zip_entries.rb.rb +0 -1
- metadata +5 -5
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 63b73f43ac7c4bb579dc6b2860683009ea3864e7
|
|
4
|
+
data.tar.gz: a2949559d538796c35db7fe6428ba4c1ee506c05
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f0f6395e390bcd31826983f7b077cb5304077ee9e2ac17b06f2ea5b4caefd76bd634b03fe82c30a018e5101a0c165e169899a62e8eb23ca22521d8b9a943177e
|
|
7
|
+
data.tar.gz: 151b6c50b9ba744d3756a525bc309cf6aeeab063abd2706fb7f1072e3054f3192d8a963094a29a0b7c86b01972f78cc7f3747e55e542122be4e0b21c7a2021e4
|
data/lib/real_zip/version.rb
CHANGED
data/lib/real_zip.rb
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
require "real_zip/version"
|
|
2
|
+
|
|
2
3
|
require 'yaml'
|
|
3
4
|
require 'forwardable'
|
|
4
5
|
require 'zip/zipfilesystem'
|
|
6
|
+
|
|
5
7
|
def RealZip file, structure
|
|
6
8
|
RealZip.new file, structure
|
|
7
9
|
end
|
|
@@ -32,50 +34,41 @@ module RealZip
|
|
|
32
34
|
traverse given do |x,y| found << [x,y] end
|
|
33
35
|
found
|
|
34
36
|
end
|
|
35
|
-
|
|
36
37
|
def collect_only(given, kind)
|
|
37
38
|
collect_all(given).map { |(name,type)| name if type == kind }.compact
|
|
38
|
-
end
|
|
39
|
-
|
|
39
|
+
end
|
|
40
40
|
def files(given)
|
|
41
41
|
collect_only(given, :file).map { |x| x.join ?/ }
|
|
42
|
-
var = File.open(given)
|
|
43
|
-
|
|
44
42
|
end
|
|
45
|
-
|
|
46
43
|
def dirs(given)
|
|
47
44
|
collect_only(given, :dir).map { |x| x.join ?/ }
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
|
|
45
|
+
end
|
|
46
|
+
end
|
|
52
47
|
|
|
53
48
|
####################
|
|
54
49
|
|
|
55
|
-
class RealZip < Struct.new :file_structure
|
|
50
|
+
class RealZip < Struct.new :file_structure
|
|
56
51
|
def save file
|
|
57
52
|
File.delete file if File.exist? file
|
|
58
53
|
Zip::ZipFile.open file, Zip::ZipFile::CREATE do |z|
|
|
54
|
+
# first_dir = nil
|
|
59
55
|
dirs(struct).each do |dir|
|
|
56
|
+
first_dir = dir
|
|
60
57
|
z.dir.mkdir(dir) unless z.file.exist? dir
|
|
61
58
|
end
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
59
|
+
op1 = struct
|
|
60
|
+
arr = op1.values.first
|
|
61
|
+
# op2 = files(op1)
|
|
62
|
+
# res = op1.to_s + " ==== " + op2.to_s
|
|
63
|
+
files(op1).each_with_index do |file,index|
|
|
64
|
+
file_path = arr[index]
|
|
65
|
+
# FileUtils.cp("/home/raw/Code/prasad/zip.rake", file)
|
|
66
|
+
string = File.open(file_path, 'r'){ |f| f.read }
|
|
67
|
+
z.file.open(file, "w") { |f| f.write string }
|
|
68
|
+
end
|
|
65
69
|
end
|
|
66
70
|
end
|
|
67
71
|
|
|
68
|
-
# def save file
|
|
69
|
-
# File.delete file if File.exist? file
|
|
70
|
-
# Zip::ZipFile.open file, Zip::ZipFile::CREATE do |z|
|
|
71
|
-
# dirs(struct).each do |dir|
|
|
72
|
-
# z.dir.mkdir(dir) unless z.file.exist? dir
|
|
73
|
-
# end
|
|
74
|
-
# files(struct).each do |file|
|
|
75
|
-
# z.file.open(file, "w") { |f| f.write file }
|
|
76
|
-
# end
|
|
77
|
-
# end
|
|
78
|
-
|
|
79
72
|
def struct given=file_structure
|
|
80
73
|
given.is_a?(String) ? YAML.load(given) : given
|
|
81
74
|
end
|
|
@@ -95,14 +88,6 @@ end
|
|
|
95
88
|
|
|
96
89
|
|
|
97
90
|
__END__
|
|
98
|
-
# Zippy.create 'my.zip' do |z|
|
|
99
|
-
# add_dir z, 'my', 'app'
|
|
100
|
-
# add_dir z, 'my', 'config'
|
|
101
|
-
# add_file z, 'my', 'config.ru'
|
|
102
|
-
# add_file z, 'my', 'Gemfile'
|
|
103
|
-
# end
|
|
104
|
-
|
|
105
|
-
|
|
106
91
|
# Other tests...
|
|
107
92
|
|
|
108
93
|
found = []
|
|
@@ -130,21 +115,4 @@ Zip::ZipFile.open file_name do |z|
|
|
|
130
115
|
z.file.exist? 'root_dir/nested_dir/nested_file.any' or raise
|
|
131
116
|
z.file.exist? 'root_dir/empty_dir' or raise # no empty dirs
|
|
132
117
|
end
|
|
133
|
-
File.delete file_name
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
# def add_file( zippyfile, dst_dir, f )
|
|
137
|
-
# zippyfile["#{dst_dir}/#{f}"] = File.open(f)
|
|
138
|
-
# if File.file?(f)
|
|
139
|
-
# FileUtils.copy_file f, dst_dir
|
|
140
|
-
# end
|
|
141
|
-
# end
|
|
142
|
-
|
|
143
|
-
# def add_dir( zippyfile, dst_dir, d )
|
|
144
|
-
# glob = "#{d}/**/*"
|
|
145
|
-
# FileList.new( glob ).each { |f|
|
|
146
|
-
# if (File.file?(f))
|
|
147
|
-
# add_file zippyfile, dst_dir, f
|
|
148
|
-
# end
|
|
149
|
-
# }
|
|
150
|
-
# end
|
|
118
|
+
File.delete file_name
|
data/real_zip.gemspec
CHANGED
data/spec/examples_spec.rb
CHANGED
|
@@ -1,36 +1,38 @@
|
|
|
1
|
-
describe
|
|
1
|
+
describe RealZip do
|
|
2
2
|
extend MyTemp.new(:temp, 'tmp/testing.zip')
|
|
3
3
|
|
|
4
|
-
describe '.new' do
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
it 'takes file name and hash' do
|
|
10
|
-
expect { FakeZip temp, {} }.to change { File.exist? temp }.from(false).to(true)
|
|
11
|
-
end
|
|
4
|
+
# describe '.new' do
|
|
5
|
+
# it 'takes file name and yaml string' do
|
|
6
|
+
# expect { RealZip temp, '{}' }.to change { File.exist? temp }.from(false).to(true)
|
|
7
|
+
# end
|
|
12
8
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
9
|
+
# it 'takes file name and hash' do
|
|
10
|
+
# expect { RealZip temp, {} }.to change { File.exist? temp }.from(false).to(true)
|
|
11
|
+
# end
|
|
12
|
+
it 'displays the transferred file' do
|
|
13
|
+
expect { RealZip temp, {} }.to change { File.open? temp }.from(false).to(true)
|
|
17
14
|
end
|
|
18
|
-
|
|
15
|
+
# it 'recreates file if exist' do
|
|
16
|
+
# RealZip temp, {dir:[:file]}
|
|
17
|
+
# RealZip temp, {other:[:any]}
|
|
18
|
+
# zip_entries(temp).should == %w[ other/ other/any ]
|
|
19
|
+
# end
|
|
20
|
+
# end
|
|
19
21
|
|
|
20
|
-
describe 'examples (given structure --- files in archive)' do
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
22
|
+
# describe 'examples (given structure --- files in archive)' do
|
|
23
|
+
# examples = <<-END.lines.map(&:strip).map { |x| x.split(' --- ',2).map { |x| eval x } }
|
|
24
|
+
# "[]" --- []
|
|
25
|
+
# {} --- []
|
|
26
|
+
# {root: []} --- ['root/']
|
|
27
|
+
# "root: []" --- ['root/']
|
|
28
|
+
# 'root_dir: [file1, file2, nested_dir: [nested_file.any], empty_dir: []]' --- ["root_dir/", "root_dir/nested_dir/", "root_dir/empty_dir/", "root_dir/file1", "root_dir/file2", "root_dir/nested_dir/nested_file.any"]
|
|
29
|
+
# END
|
|
28
30
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
end
|
|
31
|
+
# examples.each do |input,output|
|
|
32
|
+
# specify "#{input.inspect} --- #{output.inspect}" do
|
|
33
|
+
# RealZip temp, input
|
|
34
|
+
# zip_entries(temp).should == output
|
|
35
|
+
# end
|
|
36
|
+
# end
|
|
37
|
+
# end
|
|
36
38
|
end
|
data/spec/support/my_temp.rb
CHANGED
|
@@ -1,3 +1,29 @@
|
|
|
1
|
+
class MetaModule < Module
|
|
2
|
+
# use .new so I don't bother user to use super in #initialize
|
|
3
|
+
def self.new(*)
|
|
4
|
+
super.tap { |x| x.send :include, self::Methods }
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def self.used &block
|
|
8
|
+
define_method :included, &block
|
|
9
|
+
define_method :extended, &block
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class MetaModule2 #< Class
|
|
15
|
+
def self.new *params
|
|
16
|
+
_params = params.join ?,
|
|
17
|
+
a_params = params.map{|x|"@#{x}"}.join ?,
|
|
18
|
+
|
|
19
|
+
Class.new(MetaModule) do
|
|
20
|
+
eval "def initialize(#{_params}); #{a_params} = #{_params} end"
|
|
21
|
+
private; attr_reader *params
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
|
|
1
27
|
class MyTemp < MetaModule2.new :getter, :file
|
|
2
28
|
used do |at|
|
|
3
29
|
at.def_temp_file getter, file
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: real_zip
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Prasad R.
|
|
@@ -56,16 +56,16 @@ dependencies:
|
|
|
56
56
|
name: rubyzip
|
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
|
58
58
|
requirements:
|
|
59
|
-
- - "
|
|
59
|
+
- - "<"
|
|
60
60
|
- !ruby/object:Gem::Version
|
|
61
|
-
version:
|
|
61
|
+
version: 1.0.0
|
|
62
62
|
type: :runtime
|
|
63
63
|
prerelease: false
|
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
|
65
65
|
requirements:
|
|
66
|
-
- - "
|
|
66
|
+
- - "<"
|
|
67
67
|
- !ruby/object:Gem::Version
|
|
68
|
-
version:
|
|
68
|
+
version: 1.0.0
|
|
69
69
|
description: build zip files with given file structure and transfer files to it for
|
|
70
70
|
testing
|
|
71
71
|
email:
|