class Paperclip::Tus::Adapter

Constants

REGEXP

Public Class Methods

new(target, _options = {}) click to toggle source
Calls superclass method
# File lib/paperclip/tus/adapter.rb, line 9
def initialize(target, _options = {})
  ensure_tus_filesystem_storage!

  @uid = target
  @file_path = tus_file_path.to_s
  @info = tus_info
  cache_current_values
  # passing options to super for paperclip 5.2.x
  super if Paperclip::VERSION.to_f > 5.1
end

Private Instance Methods

cache_current_values() click to toggle source
# File lib/paperclip/tus/adapter.rb, line 22
def cache_current_values
  self.original_filename = @info.metadata['filename']
  @tempfile = copy_to_tempfile(@file_path)
  @content_type = Paperclip::ContentTypeDetector.new(@file_path).detect
  @size = @info.length
end
copy_to_tempfile(src_path) click to toggle source
# File lib/paperclip/tus/adapter.rb, line 50
def copy_to_tempfile(src_path)
  FileUtils.cp(src_path, destination.path)
  destination
end
ensure_tus_filesystem_storage!() click to toggle source
# File lib/paperclip/tus/adapter.rb, line 42
def ensure_tus_filesystem_storage!
  return if tus_storage.class == ::Tus::Storage::Filesystem

  raise 'Paperclip tus adapter does not support ' \
    "#{tus_storage.class.name}! Please set Tus::Server.opts[:storage] " \
    'to Tus::Storage::Filesystem.new(cache_directory)'
end
tus_file_path() click to toggle source
# File lib/paperclip/tus/adapter.rb, line 33
def tus_file_path
  # FIXME: private method
  tus_storage.send(:file_path, @uid)
end
tus_info() click to toggle source
# File lib/paperclip/tus/adapter.rb, line 29
def tus_info
  ::Tus::Info.new(tus_storage.read_info(@uid))
end
tus_storage() click to toggle source
# File lib/paperclip/tus/adapter.rb, line 38
def tus_storage
  ::Tus::Server.opts[:storage]
end