Class: PaperclipArchiveProcessor::Processor::S3

Inherits:
Object
  • Object
show all
Defined in:
lib/paperclip_archive_processor/processor.rb

Class Method Summary collapse

Class Method Details

.extract(attachment, extractor) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/paperclip_archive_processor/processor.rb', line 33

def self.extract(attachment, extractor)
  extract_path    = Dir.mktmpdir
  s3_path_prefix  = File.dirname(attachment.path)
  bucket_name     = attachment.instance_variable_get(:@options)[:bucket]
  options         = options_for(attachment)

  extractor.extract(attachment.to_file.path, extract_path).each do |name|
    file = File.join(extract_path, name)
    write(File.join(s3_path_prefix, name), File.new(file), bucket_name, options) if File.file?(file)
  end
end

.options_for(attachment) ⇒ Object



45
46
47
48
49
# File 'lib/paperclip_archive_processor/processor.rb', line 45

def self.options_for(attachment)
  { :content_type => attachment.content_type,
    :access => attachment.instance_variable_get(:@s3_permissions)
  }.merge(attachment.instance_variable_get(:@s3_headers))
end

.write(path, file, bucket_name, options) ⇒ Object



51
52
53
54
55
56
57
# File 'lib/paperclip_archive_processor/processor.rb', line 51

def self.write(path, file, bucket_name, options)
  begin
    AWS::S3::S3Object.store(path, file, bucket_name, options)
  rescue AWS::S3::ResponseError
    raise
  end
end