Sha256: 99bdd5a811cfb79daf22ed433d84adfa83ff2ba7ea9a971817e9a29e8d562f81

Contents?: true

Size: 930 Bytes

Versions: 7

Compression:

Stored size: 930 Bytes

Contents

module Paperclip
  class AttachmentAdapter < AbstractAdapter
    def initialize(target)
      @target, @style = case target
      when Paperclip::Attachment
        [target, :original]
      when Paperclip::Style
        [target.attachment, target.name]
      end

      cache_current_values
    end

    private

    def cache_current_values
      self.original_filename = @target.original_filename
      @content_type = @target.content_type
      @tempfile = copy_to_tempfile(@target)
      @size = @tempfile.size || @target.size
    end

    def copy_to_tempfile(src)
      if src.respond_to? :copy_to_local_file
        src.copy_to_local_file(@style, destination.path)
      else
        FileUtils.cp(src.path(@style), destination.path)
      end
      destination
    end
  end
end

Paperclip.io_adapters.register Paperclip::AttachmentAdapter do |target|
  Paperclip::Attachment === target || Paperclip::Style === target
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
paperclip-3.5.4 lib/paperclip/io_adapters/attachment_adapter.rb
paperclip-3.5.3 lib/paperclip/io_adapters/attachment_adapter.rb
paperclip-3.5.2 lib/paperclip/io_adapters/attachment_adapter.rb
paperclip-3.5.1 lib/paperclip/io_adapters/attachment_adapter.rb
paperclip-3.5.0 lib/paperclip/io_adapters/attachment_adapter.rb
paperclip-3.4.2 lib/paperclip/io_adapters/attachment_adapter.rb
paperclip-3.4.1 lib/paperclip/io_adapters/attachment_adapter.rb