Class: CarrierWave::Storage::GridFS::File
- Inherits:
-
Object
- Object
- CarrierWave::Storage::GridFS::File
- Defined in:
- lib/carrierwave/storage/grid_fs.rb
Instance Method Summary collapse
- #content_type ⇒ Object
- #delete ⇒ Object
- #file_length ⇒ Object
-
#initialize(uploader, path) ⇒ File
constructor
A new instance of File.
- #path ⇒ Object
- #read ⇒ Object
- #url ⇒ Object
- #write(file) ⇒ Object
Constructor Details
#initialize(uploader, path) ⇒ File
Returns a new instance of File.
42 43 44 45 |
# File 'lib/carrierwave/storage/grid_fs.rb', line 42 def initialize(uploader, path) @path = path @uploader = uploader end |
Instance Method Details
#content_type ⇒ Object
73 74 75 |
# File 'lib/carrierwave/storage/grid_fs.rb', line 73 def content_type grid.open(@path, 'r').content_type end |
#delete ⇒ Object
69 70 71 |
# File 'lib/carrierwave/storage/grid_fs.rb', line 69 def delete grid.delete(@path) end |
#file_length ⇒ Object
77 78 79 |
# File 'lib/carrierwave/storage/grid_fs.rb', line 77 def file_length grid.open(@path, 'r').file_length end |
#path ⇒ Object
47 48 49 |
# File 'lib/carrierwave/storage/grid_fs.rb', line 47 def path nil end |
#read ⇒ Object
59 60 61 |
# File 'lib/carrierwave/storage/grid_fs.rb', line 59 def read grid.open(@path, 'r').data end |
#url ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/carrierwave/storage/grid_fs.rb', line 51 def url unless @uploader.grid_fs_access_url nil else [@uploader.grid_fs_access_url, @path].join("/") end end |
#write(file) ⇒ Object
63 64 65 66 67 |
# File 'lib/carrierwave/storage/grid_fs.rb', line 63 def write(file) grid.open(@uploader.store_path, 'w', :content_type => file.content_type) do |f| f.write(file.read) end end |