lib/real_zip.rb in real_zip-1.0.1 vs lib/real_zip.rb in real_zip-1.1.6
- old
+ new
@@ -1,10 +1,12 @@
require "real_zip/version"
require 'yaml'
require 'forwardable'
require 'zip/zipfilesystem'
+require 'fileutils'
+require 'pry'
def RealZip file, structure
RealZip.new file, structure
end
@@ -40,10 +42,14 @@
def files(given)
collect_only(given, :file).map { |x| x.join ?/ }
end
def dirs(given)
collect_only(given, :dir).map { |x| x.join ?/ }
+ end
+
+ def is_file(file)
+ File.file?(file)
end
end
####################
@@ -58,26 +64,52 @@
end
hash = struct
# puts "hash => #{hash}"
hash.each do |dir,file_arr|
+
# puts "directory ======> #{dir}"
# puts "file_array ======> #{file_arr.to_s}"
new_files = files({dir => file_arr})
# puts "new files ======> #{new_files.to_s}"
new_files.each_with_index do |file, index|
# puts "file ======> #{file} index => #{index}"
orignal_file_path = file_arr[index]
# puts "orignal_file_path ==========> #{orignal_file_path}"
- string = File.open(orignal_file_path, 'r'){ |f| f.read }
- file_name = file.split('/').last
- new_file_name = ( files( {dir => [ "#{file_name}" ] } ) ).first
- puts "file_name ========> #{file_name}"
- z.file.open(new_file_name, "w") { |f| f.write string }
- end
+
+ # unless File.file?(orignal_file_path)
+ # if dir.to_s == 'home'
+ # source = "#{orignal_file_path}"
+ # puts " Not a file #{source}"
+ # puts "directory =====> #{dir}"
+ # directory = source
+
+ # Dir.foreach(source).each do | file_or_dir|
+
+ # if File.file?(file_or_dir)
+
+ # z.add(new_file_name, )
+ # end
+ # end
+
+
+
+
+ # # binding.pry
+ # #
+ # else
+ string = File.open(orignal_file_path, 'r'){ |f| f.read }
+ file_name = file.split('/').last
+ new_file_name = ( files( {dir => [ "#{file_name}" ] } ) ).first
+ # puts "file_name ========> #{file_name}"
+ z.file.open(new_file_name, "w") { |f| f.write string }
+ # end
+
+ end
+ # binding.pry
end
-
+ # binding.pry
end
end
def struct given=file_structure
given.is_a?(String) ? YAML.load(given) : given
\ No newline at end of file