Sha256: 347ce7136744616f6bb82bbd966aad4e8ddbf5bdc1db77bf26b93cac6b6a0a02

Contents?: true

Size: 1010 Bytes

Versions: 9

Compression:

Stored size: 1010 Bytes

Contents

require 'active_support/core_ext/module/delegation'

module Paperclip
  class AbstractAdapter
    OS_RESTRICTED_CHARACTERS = %r{[/:]}

    attr_reader :content_type, :original_filename, :size
    delegate :binmode, :binmode?, :close, :close!, :closed?, :eof?, :path, :rewind, :unlink, :to => :@tempfile

    def fingerprint
      @fingerprint ||= Digest::MD5.file(path).to_s
    end

    def read(length = nil, buffer = nil)
      @tempfile.read(length, buffer)
    end

    def inspect
      "#{self.class}: #{self.original_filename}"
    end

    def original_filename=(new_filename)
      return unless new_filename
      @original_filename = new_filename.gsub(OS_RESTRICTED_CHARACTERS, "_")
    end

    def nil?
      false
    end

    def assignment?
      true
    end

    private

    def destination
      @destination ||= TempfileFactory.new.generate(@original_filename.to_s)
    end

    def copy_to_tempfile(src)
      FileUtils.cp(src.path, destination.path)
      destination
    end
  end
end

Version data entries

9 entries across 7 versions & 2 rubygems

Version Path
solidus_backend-1.0.0.pre3 vendor/bundle/gems/paperclip-4.2.4/lib/paperclip/io_adapters/abstract_adapter.rb
solidus_backend-1.0.0.pre2 vendor/bundle/gems/paperclip-4.2.4/lib/paperclip/io_adapters/abstract_adapter.rb
solidus_backend-1.0.0.pre vendor/bundle/gems/paperclip-4.2.2/lib/paperclip/io_adapters/abstract_adapter.rb
solidus_backend-1.0.0.pre vendor/bundle/gems/paperclip-4.2.3/lib/paperclip/io_adapters/abstract_adapter.rb
solidus_backend-1.0.0.pre vendor/bundle/gems/paperclip-4.2.4/lib/paperclip/io_adapters/abstract_adapter.rb
paperclip-4.2.4 lib/paperclip/io_adapters/abstract_adapter.rb
paperclip-4.2.3 lib/paperclip/io_adapters/abstract_adapter.rb
paperclip-4.2.2 lib/paperclip/io_adapters/abstract_adapter.rb
paperclip-4.2.1 lib/paperclip/io_adapters/abstract_adapter.rb