unpack 0.1.4 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
data/lib/unpack.rb CHANGED
@@ -3,7 +3,7 @@ require 'unpack/container'
3
3
  require 'fileutils'
4
4
 
5
5
  class Unpack
6
- attr_accessor :files, :options
6
+ attr_accessor :files, :options, :directory, :removeable
7
7
 
8
8
  def initialize(args)
9
9
  args.keys.each { |name| instance_variable_set "@" + name.to_s, args[name] }
@@ -29,6 +29,26 @@ class Unpack
29
29
 
30
30
  raise Exception.new("You need to specify a valid path") if @directory.nil? or not Dir.exist?(@directory)
31
31
  raise Exception.new("You need unzip to keep going") if %x{whereis unzip}.empty?
32
+
33
+ @files = []
34
+ end
35
+
36
+ def self.it!(args)
37
+ # If no to argument is given, file will be unpacked in the same dir
38
+ args[:to] = args[:to].nil? ? File.dirname(args[:file]) : args[:to]
39
+
40
+ # Adding the options that is being passed to {it!} directly to {Unpack}
41
+ this = self.new(directory: args[:to], options: {min_files: 0}.merge(args))
42
+
43
+ # Is the file path absolute ? good, do nothing : get the absolute path
44
+ file = args[:file].match(/^\//) ? args[:file] : File.expand_path(args[:file])
45
+
46
+ this.files << file
47
+ this.unpack!
48
+ this.wipe! if this.options[:remove]
49
+
50
+ # Only one files has been unpacked, that is why we select the first object in the list
51
+ this.diff.first
32
52
  end
33
53
 
34
54
  def self.runner!(directory = '.', options = {})
@@ -69,7 +89,10 @@ class Unpack
69
89
  def unpack!
70
90
  @files.each do |file|
71
91
  type = Mimer.identify(file)
72
- path = File.dirname(file)
92
+
93
+ # To what directory want we to unpack the file ? The same as the file : The one that where specified in {initialize}
94
+ path = @directory == File.dirname(file) ? File.dirname(file) : @directory
95
+
73
96
  before = Dir.new(path).entries
74
97
 
75
98
  if type.zip?
File without changes
File without changes
File without changes
File without changes
File without changes
Binary file
Binary file
Binary file
data/spec/unpack_spec.rb CHANGED
@@ -2,6 +2,14 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper.rb')
2
2
 
3
3
  # Preparing the file structure
4
4
  def clear!
5
+
6
+ # Removes old files in the test directory
7
+ ['to', 'from'].each do |folder|
8
+ Dir.glob(File.expand_path(File.dirname(__FILE__) + "/data/#{folder}/*")).each do |file|
9
+ FileUtils.rm(file)
10
+ end
11
+ end
12
+
5
13
  {'some_zip_files.zip' => 'zip_real', 'test_package.rar' => 'rar_real'}.each_pair do |taget|
6
14
 
7
15
  # Removes old files in the test directory
@@ -18,8 +26,15 @@ def clear!
18
26
  Dir.glob(File.expand_path(File.dirname(__FILE__) + "/data/movie_to/*")).each do |file|
19
27
  FileUtils.rm(file) if Mimer.identify(file).text?
20
28
  end
29
+
30
+ {'test_package.rar' => 'to', 'some_zip_files.zip' => 'to'}.each_pair do |taget|
31
+ src = File.expand_path(File.dirname(__FILE__) + "/data/o_files/#{taget.first}")
32
+ dest = File.expand_path(File.dirname(__FILE__) + "/data/from/#{taget.first}")
33
+ FileUtils.copy_file(src, dest)
34
+ end
21
35
  end
22
36
 
37
+
23
38
  describe Unpack, "should work with the runner" do
24
39
  before(:each) do
25
40
  clear!
@@ -258,4 +273,54 @@ describe Unpack, "should work with all kind of paths" do
258
273
  Unpack.new(directory: "spec/random")
259
274
  }.should raise_error(Exception)
260
275
  end
276
+ end
277
+
278
+ describe Unpack, "should be able to unpack" do
279
+ before(:each) do
280
+ clear!
281
+ @path = File.expand_path('spec/data/to/')
282
+ @from = File.expand_path('spec/data/from/')
283
+ end
284
+
285
+ it "should be able to unpack an unknown file from one dir to a nother" do
286
+ ['some_zip_files.zip', "test_package.rar"].each do |inner|
287
+ files = %x{cd #{@path} && ls}.split(/\n/).count
288
+ Unpack.it!(file: File.expand_path("spec/data/from/#{inner}"), to: @path)
289
+ %x{cd #{@path} && ls}.split(/\n/).count.should_not eq(files)
290
+ clear!
291
+ end
292
+ end
293
+
294
+ it "should be able to unpack relative files" do
295
+ ['some_zip_files.zip', "test_package.rar"].each do |inner|
296
+ files = %x{cd #{@path} && ls}.split(/\n/).count
297
+ Unpack.it!(file: "spec/data/from/#{inner}", to: 'spec/data/to')
298
+ %x{cd #{@path} && ls}.split(/\n/).count.should_not eq(files)
299
+ clear!
300
+ end
301
+ end
302
+
303
+ it "should be able to unpack to the same folder" do
304
+ ['some_zip_files.zip', "test_package.rar"].each do |inner|
305
+ files = %x{cd #{@from} && ls}.split(/\n/).count
306
+ Unpack.it!(file: "spec/data/from/#{inner}")
307
+ %x{cd #{@from} && ls}.split(/\n/).count.should_not eq(files)
308
+ clear!
309
+ end
310
+ end
311
+
312
+ it "should raise an error when the path does not exist" do
313
+ lambda{
314
+ Unpack.it!(file: "some/random/folder")
315
+ }.should raise_error(Exception)
316
+ end
317
+
318
+ it "should remove the old archive files" do
319
+ Unpack.it!(file: "spec/data/from/test_package.rar", remove: true)
320
+ %x{cd #{@from} && ls | grep test_package.rar}.should be_empty
321
+ end
322
+
323
+ it "should have some unarchived files" do
324
+ Unpack.it!(file: "spec/data/from/test_package.rar").should have(5).files
325
+ end
261
326
  end
data/unpack.gemspec CHANGED
@@ -3,13 +3,13 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "unpack"
6
- s.version = "0.1.4"
6
+ s.version = "0.1.6"
7
7
  s.platform = Gem::Platform::RUBY
8
8
  s.authors = ["Linus Oleander"]
9
9
  s.email = ["linus@oleander.nu"]
10
10
  s.homepage = "https://github.com/oleander/Unpack"
11
11
  s.summary = %q{An automated unrar gem}
12
- s.description = %q{An automated unpacking tool for Mac OS X, using Ruby 1.9.2}
12
+ s.description = %q{An automated unpacking tool for *nix, using Ruby 1.9.2}
13
13
 
14
14
  s.files = `git ls-files`.split("\n")
15
15
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 4
9
- version: 0.1.4
8
+ - 6
9
+ version: 0.1.6
10
10
  platform: ruby
11
11
  authors:
12
12
  - Linus Oleander
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-01-29 00:00:00 +01:00
17
+ date: 2011-01-30 00:00:00 +01:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -45,7 +45,7 @@ dependencies:
45
45
  version: 0.0.4
46
46
  type: :runtime
47
47
  version_requirements: *id002
48
- description: An automated unpacking tool for Mac OS X, using Ruby 1.9.2
48
+ description: An automated unpacking tool for *nix, using Ruby 1.9.2
49
49
  email:
50
50
  - linus@oleander.nu
51
51
  executables:
@@ -63,6 +63,13 @@ files:
63
63
  - bin/unrar
64
64
  - lib/unpack.rb
65
65
  - lib/unpack/container.rb
66
+ - spec/data/from/110_real_.file.rar
67
+ - spec/data/from/120_real_.file.rar
68
+ - spec/data/from/167_real_.file.rar
69
+ - spec/data/from/777_real_.file.rar
70
+ - spec/data/from/918_real_.file.rar
71
+ - spec/data/from/some_zip_files.zip
72
+ - spec/data/from/test_package.rar
66
73
  - spec/data/o_files/some_zip_files.zip
67
74
  - spec/data/o_files/test_package.rar
68
75
  - spec/data/rar/110_accessible_.rar
@@ -166,11 +173,7 @@ files:
166
173
  - spec/data/rar/subdir/22_subtitle_.rar
167
174
  - spec/data/rar/subdir/483_subtitle_.rar
168
175
  - spec/data/rar/subdir/639_subtitle_.rar
169
- - spec/data/rar_real/110_real_.file.rar
170
- - spec/data/rar_real/120_real_.file.rar
171
- - spec/data/rar_real/167_real_.file.rar
172
- - spec/data/rar_real/777_real_.file.rar
173
- - spec/data/rar_real/918_real_.file.rar
176
+ - spec/data/rar_real/test_package.rar
174
177
  - spec/data/zip_real/some_zip_files.zip
175
178
  - spec/spec_helper.rb
176
179
  - spec/unpack_spec.rb
@@ -208,6 +211,13 @@ signing_key:
208
211
  specification_version: 3
209
212
  summary: An automated unrar gem
210
213
  test_files:
214
+ - spec/data/from/110_real_.file.rar
215
+ - spec/data/from/120_real_.file.rar
216
+ - spec/data/from/167_real_.file.rar
217
+ - spec/data/from/777_real_.file.rar
218
+ - spec/data/from/918_real_.file.rar
219
+ - spec/data/from/some_zip_files.zip
220
+ - spec/data/from/test_package.rar
211
221
  - spec/data/o_files/some_zip_files.zip
212
222
  - spec/data/o_files/test_package.rar
213
223
  - spec/data/rar/110_accessible_.rar
@@ -311,11 +321,7 @@ test_files:
311
321
  - spec/data/rar/subdir/22_subtitle_.rar
312
322
  - spec/data/rar/subdir/483_subtitle_.rar
313
323
  - spec/data/rar/subdir/639_subtitle_.rar
314
- - spec/data/rar_real/110_real_.file.rar
315
- - spec/data/rar_real/120_real_.file.rar
316
- - spec/data/rar_real/167_real_.file.rar
317
- - spec/data/rar_real/777_real_.file.rar
318
- - spec/data/rar_real/918_real_.file.rar
324
+ - spec/data/rar_real/test_package.rar
319
325
  - spec/data/zip_real/some_zip_files.zip
320
326
  - spec/spec_helper.rb
321
327
  - spec/unpack_spec.rb