Sha256: 6bf0cb805846a8565acd804bd74d5f5ccfa2c5a3bface8eb63e1ef05b19860fa

Contents?: true

Size: 1.01 KB

Versions: 14

Compression:

Stored size: 1.01 KB

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
    alias :length :size

    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

14 entries across 14 versions & 4 rubygems

Version Path
kt-paperclip-4.4.0 lib/paperclip/io_adapters/abstract_adapter.rb
paperclip-5.0.0 lib/paperclip/io_adapters/abstract_adapter.rb
paperclip-4.3.7 lib/paperclip/io_adapters/abstract_adapter.rb
paperclip_jk-5.0.0.beta2 lib/paperclip/io_adapters/abstract_adapter.rb
ish_lib_manager-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/paperclip-4.3.6/lib/paperclip/io_adapters/abstract_adapter.rb
paperclip-5.0.0.beta2 lib/paperclip/io_adapters/abstract_adapter.rb
paperclip-5.0.0.beta1 lib/paperclip/io_adapters/abstract_adapter.rb
paperclip-4.3.6 lib/paperclip/io_adapters/abstract_adapter.rb
paperclip-4.3.5 lib/paperclip/io_adapters/abstract_adapter.rb
paperclip-4.3.4 lib/paperclip/io_adapters/abstract_adapter.rb
paperclip-4.3.3 lib/paperclip/io_adapters/abstract_adapter.rb
paperclip-4.3.2 lib/paperclip/io_adapters/abstract_adapter.rb
paperclip-4.3.1 lib/paperclip/io_adapters/abstract_adapter.rb
paperclip-4.3.0 lib/paperclip/io_adapters/abstract_adapter.rb