lib/unpack.rb in unpack-0.2.0 vs lib/unpack.rb in unpack-0.2.1
- old
+ new
@@ -12,10 +12,11 @@
:min_files => 5,
:depth => 2,
:debugger => false,
:force_remove => false,
:remove => false,
+ :to => false,
:absolute_path_to_unrar => "#{File.dirname(__FILE__)}/../bin/unrar"
}
@removeable = {}
@@ -36,11 +37,11 @@
def self.it!(args)
# If no to argument is given, file will be unpacked in the same dir
args[:to] = args[:to].nil? ? File.dirname(args[:file]) : args[:to]
# Adding the options that is being passed to {it!} directly to {Unpack}
- this = self.new(:directory => args[:to], :options => {:min_files => 0}.merge(args))
+ this = self.new(:directory => args[:to], :options => {:min_files => 0, :to => true}.merge(args))
# Is the file path absolute ? good, do nothing : get the absolute path
file = args[:file].match(/^\//) ? args[:file] : File.expand_path(args[:file])
this.files << file
@@ -87,14 +88,15 @@
def unpack!
@files.each do |file|
type = Mimer.identify(file)
- # To what directory want we to unpack the file ? The same as the file : The one that where specified in {initialize}
- path = @directory == File.dirname(file) ? File.dirname(file) : @directory
+ # Have the user specified a destenation folder to where the files are going to be unpacked?
+ # If so, use that, if not use the current location of the archive file
+ path = self.options[:to] ? @directory : File.dirname(file)
before = Dir.new(path).entries
-
+
if type.zip?
@removeable.merge!(path => {:file_type => 'zip'})
self.unzip(:path => path, :file => file)
elsif type.rar?
@removeable.merge!(path => {:file_type => 'rar'})