lib/paperclip/io_adapters/file_adapter.rb in kt-paperclip-4.4.0 vs lib/paperclip/io_adapters/file_adapter.rb in kt-paperclip-5.4.0
- old
+ new
@@ -1,22 +1,28 @@
module Paperclip
class FileAdapter < AbstractAdapter
- def initialize(target)
- @target = target
+ def self.register
+ Paperclip.io_adapters.register self do |target|
+ File === target || ::Tempfile === target
+ end
+ end
+
+ def initialize(target, options = {})
+ super
cache_current_values
end
private
def cache_current_values
- self.original_filename = @target.original_filename if @target.respond_to?(:original_filename)
+ if @target.respond_to?(:original_filename)
+ self.original_filename = @target.original_filename
+ end
self.original_filename ||= File.basename(@target.path)
@tempfile = copy_to_tempfile(@target)
@content_type = ContentTypeDetector.new(@target.path).detect
@size = File.size(@target)
end
end
end
-Paperclip.io_adapters.register Paperclip::FileAdapter do |target|
- File === target || Tempfile === target
-end
+Paperclip::FileAdapter.register