Module: Parse::Importer
- Defined in:
- lib/parse/importer.rb,
lib/parse/importer/store.rb,
lib/parse/importer/version.rb
Defined Under Namespace
Classes: Store
Constant Summary collapse
- VERSION =
"0.0.3"
Class Method Summary collapse
Class Method Details
.import(dirname, credentials = nil) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/parse/importer.rb', line 31 def import dirname, credentials=nil if File.file? dirname unless File.extname(dirname) == '.zip' raise ArgumentError.new('should be a zip file or a directory') end dirname = unzip dirname end Parse.credentials credentials if credentials store = Parse::Importer::Store.new dirname store.save end |
.unzip(zipname) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/parse/importer.rb', line 15 def unzip zipname output = Dir.tmpdir Zip::Archive.open zipname do |archives| archives.each do |archive| filename = File.join output, archive.name FileUtils.mkdir_p File.dirname(filename) unless archive.directory? File.open filename, 'w+b' do |file| file.print archive.read end end end end File.join output, File.dirname(zipname) end |