Sha256: 05305cdce53e1ac11c9cf34f74c89563d32a1e0e6dda2ae2259fc9b684460db1

Contents?: true

Size: 957 Bytes

Versions: 31

Compression:

Stored size: 957 Bytes

Contents

require 'open-uri'

module Paperclip
  class UriAdapter < AbstractAdapter
    def initialize(target)
      @target = target
      @content = download_content
      cache_current_values
      @tempfile = copy_to_tempfile(@content)
    end

    attr_writer :content_type

    private

    def download_content
      open(@target)
    end

    def cache_current_values
      @original_filename = @target.path.split("/").last
      @original_filename ||= "index.html"
      self.original_filename = @original_filename.strip

      @content_type = @content.content_type if @content.respond_to?(:content_type)
      @content_type ||= "text/html"

      @size = @content.size
    end

    def copy_to_tempfile(src)
      while data = src.read(16*1024)
        destination.write(data)
      end
      src.close
      destination.rewind
      destination
    end
  end
end

Paperclip.io_adapters.register Paperclip::UriAdapter do |target|
  target.kind_of?(URI)
end

Version data entries

31 entries across 29 versions & 4 rubygems

Version Path
paperclip_jk-5.0.0.beta2 lib/paperclip/io_adapters/uri_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/uri_adapter.rb
paperclip-5.0.0.beta2 lib/paperclip/io_adapters/uri_adapter.rb
paperclip-5.0.0.beta1 lib/paperclip/io_adapters/uri_adapter.rb
paperclip-4.3.6 lib/paperclip/io_adapters/uri_adapter.rb
paperclip-4.3.5 lib/paperclip/io_adapters/uri_adapter.rb
paperclip-4.3.4 lib/paperclip/io_adapters/uri_adapter.rb
paperclip-4.3.3 lib/paperclip/io_adapters/uri_adapter.rb
paperclip-4.3.2 lib/paperclip/io_adapters/uri_adapter.rb
paperclip-4.3.1 lib/paperclip/io_adapters/uri_adapter.rb
solidus_backend-1.0.0.pre3 vendor/bundle/gems/paperclip-4.2.4/lib/paperclip/io_adapters/uri_adapter.rb
solidus_backend-1.0.0.pre2 vendor/bundle/gems/paperclip-4.2.4/lib/paperclip/io_adapters/uri_adapter.rb
solidus_backend-1.0.0.pre vendor/bundle/gems/paperclip-4.2.2/lib/paperclip/io_adapters/uri_adapter.rb
solidus_backend-1.0.0.pre vendor/bundle/gems/paperclip-4.2.4/lib/paperclip/io_adapters/uri_adapter.rb
solidus_backend-1.0.0.pre vendor/bundle/gems/paperclip-4.2.3/lib/paperclip/io_adapters/uri_adapter.rb
paperclip-4.3.0 lib/paperclip/io_adapters/uri_adapter.rb
paperclip-4.2.4 lib/paperclip/io_adapters/uri_adapter.rb
paperclip-4.2.3 lib/paperclip/io_adapters/uri_adapter.rb
paperclip-4.2.2 lib/paperclip/io_adapters/uri_adapter.rb
paperclip-4.2.1 lib/paperclip/io_adapters/uri_adapter.rb