unpack 0.1.8 → 0.1.9
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.
- data/README.markdown +1 -2
- data/lib/unpack.rb +10 -8
- data/spec/unpack_spec.rb +33 -32
- data/unpack.gemspec +1 -1
- metadata +4 -18
data/README.markdown
CHANGED
@@ -107,8 +107,7 @@ These are the accessors of the `Container` class.
|
|
107
107
|
|
108
108
|
## Requirements
|
109
109
|
|
110
|
-
The gem is tested in OS X 10.6.6 using Ruby 1.9.2.
|
111
|
-
It will not work in 1.8, due to the [new hash syntax](http://blog.peepcode.com/tutorials/2011/rip-ruby-hash-rocket-syntax).
|
110
|
+
The gem is tested in OS X 10.6.6 using Ruby 1.9.2 and 1.8.7.
|
112
111
|
|
113
112
|
## Thanks to ...
|
114
113
|
|
data/lib/unpack.rb
CHANGED
@@ -27,7 +27,7 @@ class Unpack
|
|
27
27
|
# Makes shure that every directory structure looks the same
|
28
28
|
@directory = Dir.new(@directory).path rescue nil
|
29
29
|
|
30
|
-
raise Exception.new("You need to specify a valid path") if @directory.nil? or
|
30
|
+
raise Exception.new("You need to specify a valid path") if @directory.nil? or Dir[@directory].empty?
|
31
31
|
raise Exception.new("You need unzip to keep going") if %x{whereis unzip}.empty?
|
32
32
|
|
33
33
|
@files = []
|
@@ -38,7 +38,7 @@ class Unpack
|
|
38
38
|
args[:to] = args[:to].nil? ? File.dirname(args[:file]) : args[:to]
|
39
39
|
|
40
40
|
# Adding the options that is being passed to {it!} directly to {Unpack}
|
41
|
-
this = self.new(directory
|
41
|
+
this = self.new(:directory => args[:to], :options => {:min_files => 0}.merge(args))
|
42
42
|
|
43
43
|
# Is the file path absolute ? good, do nothing : get the absolute path
|
44
44
|
file = args[:file].match(/^\//) ? args[:file] : File.expand_path(args[:file])
|
@@ -52,7 +52,7 @@ class Unpack
|
|
52
52
|
end
|
53
53
|
|
54
54
|
def self.runner!(directory = '.', options = {})
|
55
|
-
unpack = Unpack.new(directory
|
55
|
+
unpack = Unpack.new(:directory => directory, :options => options) rescue nil
|
56
56
|
|
57
57
|
# If the initializer raised any excetions
|
58
58
|
return [] if unpack.nil?
|
@@ -70,7 +70,7 @@ class Unpack
|
|
70
70
|
@files << find_file_type(type)
|
71
71
|
end
|
72
72
|
|
73
|
-
@files.flatten!.map! {|file| File.
|
73
|
+
@files.flatten!.map! {|file| File.expand_path(file, Dir.pwd)}
|
74
74
|
end
|
75
75
|
|
76
76
|
def clean!
|
@@ -96,10 +96,10 @@ class Unpack
|
|
96
96
|
|
97
97
|
if type.zip?
|
98
98
|
@removeable.merge!(path => {:file_type => 'zip'})
|
99
|
-
self.unzip(path
|
99
|
+
self.unzip(:path => path, :file => file)
|
100
100
|
elsif type.rar?
|
101
101
|
@removeable.merge!(path => {:file_type => 'rar'})
|
102
|
-
self.unrar(path
|
102
|
+
self.unrar(:path => path, :file => file)
|
103
103
|
else
|
104
104
|
puts "Something went wrong, the mime type does not match zip or rar" if @options[:debugger]
|
105
105
|
end
|
@@ -144,10 +144,12 @@ class Unpack
|
|
144
144
|
return @removeable if @removeable.first.class == Container
|
145
145
|
|
146
146
|
# Removing some non welcome data
|
147
|
-
@removeable.reject!
|
147
|
+
@removeable.reject! do |item,_|
|
148
|
+
@removeable[item][:diff].nil? or @removeable[item][:diff].empty?
|
149
|
+
end
|
148
150
|
|
149
151
|
@removeable = @removeable.map do |value|
|
150
|
-
Container.new(files
|
152
|
+
Container.new(:files => value.last[:diff], :directory => value.first)
|
151
153
|
end
|
152
154
|
|
153
155
|
# Never return the hash
|
data/spec/unpack_spec.rb
CHANGED
@@ -10,15 +10,15 @@ def clear!
|
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
-
{'some_zip_files.zip' => 'zip_real', 'test_package.rar' => 'rar_real'}.each_pair do |
|
13
|
+
{'some_zip_files.zip' => 'zip_real', 'test_package.rar' => 'rar_real'}.each_pair do |first, last|
|
14
14
|
|
15
15
|
# Removes old files in the test directory
|
16
|
-
Dir.glob(File.expand_path(File.dirname(__FILE__) + "/data/#{
|
16
|
+
Dir.glob(File.expand_path(File.dirname(__FILE__) + "/data/#{last}/*")).each do |file|
|
17
17
|
FileUtils.rm(file) if Mimer.identify(file).text?
|
18
18
|
end
|
19
19
|
|
20
|
-
src = File.expand_path(File.dirname(__FILE__) + "/data/o_files/#{
|
21
|
-
dest = File.expand_path(File.dirname(__FILE__) + "/data/#{
|
20
|
+
src = File.expand_path(File.dirname(__FILE__) + "/data/o_files/#{first}")
|
21
|
+
dest = File.expand_path(File.dirname(__FILE__) + "/data/#{last}/#{first}")
|
22
22
|
FileUtils.copy_file(src, dest)
|
23
23
|
end
|
24
24
|
|
@@ -27,9 +27,9 @@ def clear!
|
|
27
27
|
FileUtils.rm(file) if Mimer.identify(file).text?
|
28
28
|
end
|
29
29
|
|
30
|
-
{'test_package.rar' => 'to', 'some_zip_files.zip' => 'to'}.
|
31
|
-
src = File.expand_path(File.dirname(__FILE__) + "/data/o_files/#{
|
32
|
-
dest = File.expand_path(File.dirname(__FILE__) + "/data/from/#{
|
30
|
+
{'test_package.rar' => 'to', 'some_zip_files.zip' => 'to'}.each do |first,last|
|
31
|
+
src = File.expand_path(File.dirname(__FILE__) + "/data/o_files/#{first}")
|
32
|
+
dest = File.expand_path(File.dirname(__FILE__) + "/data/from/#{first}")
|
33
33
|
FileUtils.copy_file(src, dest)
|
34
34
|
end
|
35
35
|
end
|
@@ -39,20 +39,20 @@ describe Unpack, "should work with the runner" do
|
|
39
39
|
before(:each) do
|
40
40
|
clear!
|
41
41
|
@path = File.expand_path('spec/data/rar_real')
|
42
|
-
@unpack = Unpack.runner!('spec/data/rar_real', remove
|
42
|
+
@unpack = Unpack.runner!('spec/data/rar_real', :remove => true, :min_files => 0)
|
43
43
|
end
|
44
44
|
|
45
45
|
it "should unpack some files" do
|
46
46
|
clear!
|
47
47
|
files = %x{cd #{@path} && ls}.split(/\n/).count
|
48
|
-
Unpack.runner!('spec/data/rar_real', remove
|
48
|
+
Unpack.runner!('spec/data/rar_real', :remove => true, :min_files => 0)
|
49
49
|
%x{cd #{@path} && ls}.split(/\n/).count.should_not eq(files)
|
50
50
|
end
|
51
51
|
|
52
52
|
it "should have 1 directory" do
|
53
53
|
@unpack.count.should eq(1)
|
54
54
|
end
|
55
|
-
|
55
|
+
|
56
56
|
it "should have 5 new files" do
|
57
57
|
@unpack.first.should have(5).files
|
58
58
|
end
|
@@ -65,23 +65,23 @@ describe Unpack, "should work with the runner" do
|
|
65
65
|
|
66
66
|
it "should only contain an existsing directory" do
|
67
67
|
directory = @unpack.first.directory
|
68
|
-
Dir
|
68
|
+
Dir[directory].should_not be_empty
|
69
69
|
end
|
70
70
|
|
71
71
|
it "should not remove old files when the remove param isn't present" do
|
72
72
|
clear!
|
73
|
-
Unpack.runner!('spec/data/rar_real', min_files
|
73
|
+
Unpack.runner!('spec/data/rar_real', :min_files => 0)
|
74
74
|
%x{cd #{@path} && ls}.should have(6).split(/\n/)
|
75
75
|
end
|
76
76
|
|
77
77
|
it "should remove old files if the remove param is present" do
|
78
78
|
clear!
|
79
|
-
Unpack.runner!('spec/data/rar_real', min_files
|
79
|
+
Unpack.runner!('spec/data/rar_real', :min_files => 0, :remove => true)
|
80
80
|
%x{cd #{@path} && ls}.should have(5).split(/\n/)
|
81
81
|
end
|
82
82
|
|
83
83
|
it "should not find any files if the {min_files} param is very large" do
|
84
|
-
Unpack.runner!('spec/data/rar_real', min_files
|
84
|
+
Unpack.runner!('spec/data/rar_real', :min_files => 100).should be_empty
|
85
85
|
end
|
86
86
|
|
87
87
|
it "should return an Exception (not in production) if the path to Unpack.runner! does not exist" do
|
@@ -97,14 +97,15 @@ describe Unpack, "should work with the runner" do
|
|
97
97
|
end
|
98
98
|
|
99
99
|
it "should allways return an array" do
|
100
|
-
Unpack.runner!('spec/data/rar_real', depth
|
100
|
+
Unpack.runner!('spec/data/rar_real', :depth => 0).should be_instance_of(Array)
|
101
101
|
end
|
102
|
+
|
102
103
|
end
|
103
104
|
|
104
105
|
describe Unpack do
|
105
106
|
before(:each) do
|
106
107
|
clear!
|
107
|
-
@unpack = Unpack.new(directory
|
108
|
+
@unpack = Unpack.new(:directory => File.expand_path('spec/data/rar'))
|
108
109
|
@unpack.prepare!
|
109
110
|
end
|
110
111
|
|
@@ -157,7 +158,7 @@ describe Unpack do
|
|
157
158
|
end
|
158
159
|
|
159
160
|
it "should be possible to set and read options" do
|
160
|
-
@unpack = Unpack.new(directory
|
161
|
+
@unpack = Unpack.new(:directory => File.expand_path('spec/data/rar'), :options => {:debugger => true})
|
161
162
|
@unpack.options[:debugger].should be_true
|
162
163
|
end
|
163
164
|
end
|
@@ -168,20 +169,20 @@ describe Unpack, "should work with options" do
|
|
168
169
|
end
|
169
170
|
|
170
171
|
it "should not return any files when min is set to 0" do
|
171
|
-
@unpack = Unpack.new(directory
|
172
|
+
@unpack = Unpack.new(:directory => File.expand_path('spec/data/rar'), :options => {:depth => 0})
|
172
173
|
@unpack.prepare!
|
173
174
|
@unpack.should have(0).files
|
174
175
|
end
|
175
176
|
|
176
177
|
it "should return subtitles rar files when min files is set to o" do
|
177
|
-
@unpack = Unpack.new(directory
|
178
|
+
@unpack = Unpack.new(:directory => File.expand_path('spec/data/rar'), :options => {:min_files => 0})
|
178
179
|
@unpack.prepare!
|
179
180
|
@unpack.clean!
|
180
181
|
@unpack.files.reject {|file| ! file.match(/\_subtitle\_/) }.count.should > 0
|
181
182
|
end
|
182
183
|
|
183
184
|
it "should access some really deep files" do
|
184
|
-
@unpack = Unpack.new(directory
|
185
|
+
@unpack = Unpack.new(:directory =>File.expand_path('spec/data/rar'), :options => {:depth => 100})
|
185
186
|
@unpack.prepare!
|
186
187
|
@unpack.clean!
|
187
188
|
@unpack.files.reject {|file| ! file.match(/\_not\_/) }.count.should > 0
|
@@ -192,7 +193,7 @@ describe Unpack,"should work with zip files" do
|
|
192
193
|
before(:all) do
|
193
194
|
clear!
|
194
195
|
@path = File.expand_path('spec/data/zip_real')
|
195
|
-
@unpack = Unpack.new(directory
|
196
|
+
@unpack = Unpack.new(:directory => @path, :options => {:min_files => 1})
|
196
197
|
@unpack.prepare!
|
197
198
|
@unpack.clean!
|
198
199
|
end
|
@@ -238,7 +239,7 @@ describe Unpack, "should work on real files" do
|
|
238
239
|
before(:each) do
|
239
240
|
clear!
|
240
241
|
@path = File.expand_path('spec/data/rar_real')
|
241
|
-
@unpack = Unpack.new(directory
|
242
|
+
@unpack = Unpack.new(:directory => @path, :options => {:min_files => 0})
|
242
243
|
@unpack.prepare!
|
243
244
|
@unpack.clean!
|
244
245
|
@unpack.unpack!
|
@@ -258,19 +259,19 @@ end
|
|
258
259
|
describe Unpack, "should work with all kind of paths" do
|
259
260
|
it "should raise an exception if an invalid path is being used" do
|
260
261
|
lambda{
|
261
|
-
Unpack.new(directory
|
262
|
+
Unpack.new(:directory => "/some/non/existing/dir")
|
262
263
|
}.should raise_error(Exception)
|
263
264
|
end
|
264
265
|
|
265
266
|
it "should work with a relative path" do
|
266
267
|
lambda{
|
267
|
-
Unpack.new(directory
|
268
|
+
Unpack.new(:directory => "spec")
|
268
269
|
}.should_not raise_error(Exception)
|
269
270
|
end
|
270
271
|
|
271
272
|
it "should not work with an incorect relative path" do
|
272
273
|
lambda{
|
273
|
-
Unpack.new(directory
|
274
|
+
Unpack.new(:directory => "spec/random")
|
274
275
|
}.should raise_error(Exception)
|
275
276
|
end
|
276
277
|
end
|
@@ -285,7 +286,7 @@ describe Unpack, "should be able to unpack" do
|
|
285
286
|
it "should be able to unpack an unknown file from one dir to a nother" do
|
286
287
|
['some_zip_files.zip', "test_package.rar"].each do |inner|
|
287
288
|
files = %x{cd #{@path} && ls}.split(/\n/).count
|
288
|
-
Unpack.it!(file
|
289
|
+
Unpack.it!(:file => File.expand_path("spec/data/from/#{inner}"), :to => @path)
|
289
290
|
%x{cd #{@path} && ls}.split(/\n/).count.should_not eq(files)
|
290
291
|
clear!
|
291
292
|
end
|
@@ -294,7 +295,7 @@ describe Unpack, "should be able to unpack" do
|
|
294
295
|
it "should be able to unpack relative files" do
|
295
296
|
['some_zip_files.zip', "test_package.rar"].each do |inner|
|
296
297
|
files = %x{cd #{@path} && ls}.split(/\n/).count
|
297
|
-
Unpack.it!(file
|
298
|
+
Unpack.it!(:file => "spec/data/from/#{inner}", :to => 'spec/data/to')
|
298
299
|
%x{cd #{@path} && ls}.split(/\n/).count.should_not eq(files)
|
299
300
|
clear!
|
300
301
|
end
|
@@ -303,7 +304,7 @@ describe Unpack, "should be able to unpack" do
|
|
303
304
|
it "should be able to unpack to the same folder" do
|
304
305
|
['some_zip_files.zip', "test_package.rar"].each do |inner|
|
305
306
|
files = %x{cd #{@from} && ls}.split(/\n/).count
|
306
|
-
Unpack.it!(file
|
307
|
+
Unpack.it!(:file => "spec/data/from/#{inner}")
|
307
308
|
%x{cd #{@from} && ls}.split(/\n/).count.should_not eq(files)
|
308
309
|
clear!
|
309
310
|
end
|
@@ -311,20 +312,20 @@ describe Unpack, "should be able to unpack" do
|
|
311
312
|
|
312
313
|
it "should raise an error when the path does not exist" do
|
313
314
|
lambda{
|
314
|
-
Unpack.it!(file
|
315
|
+
Unpack.it!(:file => "some/random/folder")
|
315
316
|
}.should raise_error(Exception)
|
316
317
|
end
|
317
318
|
|
318
319
|
it "should remove the old archive files" do
|
319
|
-
Unpack.it!(file
|
320
|
+
Unpack.it!(:file => "spec/data/from/test_package.rar", :remove => true)
|
320
321
|
%x{cd #{@from} && ls | grep test_package.rar}.should be_empty
|
321
322
|
end
|
322
323
|
|
323
324
|
it "should have some unarchived files" do
|
324
|
-
Unpack.it!(file
|
325
|
+
Unpack.it!(:file => "spec/data/from/test_package.rar").should have(5).files
|
325
326
|
end
|
326
327
|
|
327
328
|
it "should contain the right directory when defining a destination path" do
|
328
|
-
Unpack.it!(file
|
329
|
+
Unpack.it!(:file => "spec/data/from/test_package.rar", :to => 'spec/data/to').directory.should match(/spec\/data\/to/)
|
329
330
|
end
|
330
331
|
end
|
data/unpack.gemspec
CHANGED
metadata
CHANGED
@@ -1,12 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: unpack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
prerelease:
|
5
|
-
|
6
|
-
- 0
|
7
|
-
- 1
|
8
|
-
- 8
|
9
|
-
version: 0.1.8
|
4
|
+
prerelease:
|
5
|
+
version: 0.1.9
|
10
6
|
platform: ruby
|
11
7
|
authors:
|
12
8
|
- Linus Oleander
|
@@ -14,7 +10,7 @@ autorequire:
|
|
14
10
|
bindir: bin
|
15
11
|
cert_chain: []
|
16
12
|
|
17
|
-
date: 2011-02-
|
13
|
+
date: 2011-02-05 00:00:00 +01:00
|
18
14
|
default_executable:
|
19
15
|
dependencies:
|
20
16
|
- !ruby/object:Gem::Dependency
|
@@ -25,8 +21,6 @@ dependencies:
|
|
25
21
|
requirements:
|
26
22
|
- - ">="
|
27
23
|
- !ruby/object:Gem::Version
|
28
|
-
segments:
|
29
|
-
- 0
|
30
24
|
version: "0"
|
31
25
|
type: :development
|
32
26
|
version_requirements: *id001
|
@@ -38,10 +32,6 @@ dependencies:
|
|
38
32
|
requirements:
|
39
33
|
- - ~>
|
40
34
|
- !ruby/object:Gem::Version
|
41
|
-
segments:
|
42
|
-
- 0
|
43
|
-
- 0
|
44
|
-
- 4
|
45
35
|
version: 0.0.4
|
46
36
|
type: :runtime
|
47
37
|
version_requirements: *id002
|
@@ -192,21 +182,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
192
182
|
requirements:
|
193
183
|
- - ">="
|
194
184
|
- !ruby/object:Gem::Version
|
195
|
-
segments:
|
196
|
-
- 0
|
197
185
|
version: "0"
|
198
186
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
199
187
|
none: false
|
200
188
|
requirements:
|
201
189
|
- - ">="
|
202
190
|
- !ruby/object:Gem::Version
|
203
|
-
segments:
|
204
|
-
- 0
|
205
191
|
version: "0"
|
206
192
|
requirements: []
|
207
193
|
|
208
194
|
rubyforge_project:
|
209
|
-
rubygems_version: 1.
|
195
|
+
rubygems_version: 1.5.0
|
210
196
|
signing_key:
|
211
197
|
specification_version: 3
|
212
198
|
summary: An automated unrar gem
|