Class: NdrImport::File::Zip
Overview
This class is a zip file handler that returns tables from the extracted files.
Instance Method Summary collapse
- #files(&block) ⇒ Object
-
#initialize(filename, format, options = {}) ⇒ Zip
constructor
A new instance of Zip.
-
#tables ⇒ Object
Zip files produce files, never tables.
Constructor Details
#initialize(filename, format, options = {}) ⇒ Zip
Returns a new instance of Zip.
11 12 13 14 15 16 17 |
# File 'lib/ndr_import/file/zip.rb', line 11 def initialize(filename, format, = {}) super @pattern = ['pattern'] || // @unzip_path = ['unzip_path'] validate_unzip_path_is_safe! end |
Instance Method Details
#files(&block) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/ndr_import/file/zip.rb', line 19 def files(&block) fail 'Not allowed in external environment' if defined?(::Rails) && ::Rails.env.external? return enum_for(:files) unless block destination = @unzip_path.join(Time.current.strftime('%H%M%S%L')) FileUtils.mkdir_p(SafeFile.safepath_to_string(destination)) ::Zip::File.open(SafeFile.safepath_to_string(@filename)) do |zipfile| unzip_entries(zipfile, destination, &block) end end |
#tables ⇒ Object
Zip files produce files, never tables.
33 34 35 |
# File 'lib/ndr_import/file/zip.rb', line 33 def tables fail 'Zip#tables should never be called' end |