Sha256: f721c8c571e7b25a511d7e5f45d24a8458715682a4b1a40e4ad18551e5669ccb

Contents?: true

Size: 980 Bytes

Versions: 5

Compression:

Stored size: 980 Bytes

Contents

require 'zip'
require 'paperclip'

module Pageflow
  module Panorama
    class ZipEntryPaperclipIOAdapter < Paperclip::AbstractAdapter
      # Paperclip < 3.3.1 compatibility
      unless Paperclip::AbstractAdapter.instance_methods.include?(:original_filename=)
        attr_writer(:original_filename)
      end

      def initialize(entry, options = {})
        @entry = entry
        cache_current_values
      end

      private

      def cache_current_values
        self.original_filename = @entry.name
        @tempfile = copy_to_tempfile(@entry)
        @content_type = Paperclip::ContentTypeDetector.new(@tempfile.path).detect
        @size = @entry.size
      end

      def copy_to_tempfile(entry)
        override_existing_file = proc { true }
        @entry.extract(destination.path, &override_existing_file)
        destination
      end
    end

    Paperclip.io_adapters.register(ZipEntryPaperclipIOAdapter) do |entry|
      Zip::Entry === entry
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
pageflow-panorama-2.4.0 lib/pageflow/panorama/zip_entry_paperclip_io_adapter.rb
pageflow-panorama-2.3.0 lib/pageflow/panorama/zip_entry_paperclip_io_adapter.rb
pageflow-panorama-2.2.0 lib/pageflow/panorama/zip_entry_paperclip_io_adapter.rb
pageflow-panorama-2.1.0 lib/pageflow/panorama/zip_entry_paperclip_io_adapter.rb
pageflow-panorama-2.0.0 lib/pageflow/panorama/zip_entry_paperclip_io_adapter.rb