Class: Paperclip::FileAdapter
- Inherits:
-
Object
- Object
- Paperclip::FileAdapter
- Defined in:
- lib/paperclip/io_adapters/file_adapter.rb
Instance Method Summary collapse
- #content_type ⇒ Object
- #eof? ⇒ Boolean
- #fingerprint ⇒ Object
-
#initialize(target) ⇒ FileAdapter
constructor
A new instance of FileAdapter.
- #nil? ⇒ Boolean
- #original_filename ⇒ Object
- #path ⇒ Object
- #read(length = nil, buffer = nil) ⇒ Object
-
#rewind ⇒ Object
We don’t use this directly, but aws/sdk does.
- #size ⇒ Object
Constructor Details
#initialize(target) ⇒ FileAdapter
Returns a new instance of FileAdapter.
3 4 5 6 |
# File 'lib/paperclip/io_adapters/file_adapter.rb', line 3 def initialize(target) @target = target @tempfile = copy_to_tempfile(@target) end |
Instance Method Details
#content_type ⇒ Object
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/paperclip/io_adapters/file_adapter.rb', line 16 def content_type types = MIME::Types.type_for(original_filename) if types.length == 0 type_from_file_command elsif types.length == 1 types.first.content_type else best_content_type_option(types) end end |
#eof? ⇒ Boolean
48 49 50 |
# File 'lib/paperclip/io_adapters/file_adapter.rb', line 48 def eof? @tempfile.eof? end |
#fingerprint ⇒ Object
27 28 29 |
# File 'lib/paperclip/io_adapters/file_adapter.rb', line 27 def fingerprint @fingerprint ||= Digest::MD5.file(path).to_s end |
#nil? ⇒ Boolean
35 36 37 |
# File 'lib/paperclip/io_adapters/file_adapter.rb', line 35 def nil? @target.nil? end |
#original_filename ⇒ Object
8 9 10 11 12 13 14 |
# File 'lib/paperclip/io_adapters/file_adapter.rb', line 8 def original_filename if @target.respond_to?(:original_filename) @target.original_filename else File.basename(@target.path) end end |
#path ⇒ Object
52 53 54 |
# File 'lib/paperclip/io_adapters/file_adapter.rb', line 52 def path @tempfile.path end |
#read(length = nil, buffer = nil) ⇒ Object
39 40 41 |
# File 'lib/paperclip/io_adapters/file_adapter.rb', line 39 def read(length = nil, buffer = nil) @tempfile.read(length, buffer) end |
#rewind ⇒ Object
We don’t use this directly, but aws/sdk does.
44 45 46 |
# File 'lib/paperclip/io_adapters/file_adapter.rb', line 44 def rewind @tempfile.rewind end |
#size ⇒ Object
31 32 33 |
# File 'lib/paperclip/io_adapters/file_adapter.rb', line 31 def size File.size(@tempfile) end |