Class: UnzipJob
- Inherits:
-
Object
- Object
- UnzipJob
- Defined in:
- lib/sufia/jobs/unzip_job.rb
Overview
Copyright © 2012 The Pennsylvania State University
Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at
www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Instance Attribute Summary collapse
-
#pid ⇒ Object
Returns the value of attribute pid.
Instance Method Summary collapse
-
#initialize(pid) ⇒ UnzipJob
constructor
A new instance of UnzipJob.
- #queue_name ⇒ Object
- #run ⇒ Object
Constructor Details
#initialize(pid) ⇒ UnzipJob
Returns a new instance of UnzipJob.
22 23 24 |
# File 'lib/sufia/jobs/unzip_job.rb', line 22 def initialize(pid) self.pid = pid end |
Instance Attribute Details
#pid ⇒ Object
Returns the value of attribute pid.
20 21 22 |
# File 'lib/sufia/jobs/unzip_job.rb', line 20 def pid @pid end |
Instance Method Details
#queue_name ⇒ Object
16 17 18 |
# File 'lib/sufia/jobs/unzip_job.rb', line 16 def queue_name :unzip end |
#run ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/sufia/jobs/unzip_job.rb', line 26 def run zip_file = GenericFile.find(pid) Zip::Archive.open_buffer(zip_file.content.content) do |archive| archive.each do |f| @generic_file = GenericFile.new @generic_file.batch_id = zip_file.batch.pid file_name = f.name mime_types = MIME::Types.of(file_name) mime_type = mime_types.empty? ? "application/octet-stream" : mime_types.first.content_type = {:label=>file_name, :dsid=>'content', :mimeType=>mime_type} @generic_file.add_file_datastream(f.read, ) @generic_file.set_title_and_label( file_name, :only_if_blank=>true ) @generic_file.(zip_file.edit_users.first) @generic_file.date_uploaded = Time.now.ctime @generic_file.date_modified = Time.now.ctime @generic_file.save end end end |