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
-
#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.
14 15 16 17 |
# File 'lib/carrierwave/storage/grid_fs.rb', line 14 def initialize(uploader, path) @path = path @uploader = uploader end |
Instance Method Details
#content_type ⇒ Object
45 46 47 |
# File 'lib/carrierwave/storage/grid_fs.rb', line 45 def content_type grid.open(@path, 'r').content_type end |
#delete ⇒ Object
41 42 43 |
# File 'lib/carrierwave/storage/grid_fs.rb', line 41 def delete grid.delete(@path) end |
#path ⇒ Object
19 20 21 |
# File 'lib/carrierwave/storage/grid_fs.rb', line 19 def path nil end |
#read ⇒ Object
31 32 33 |
# File 'lib/carrierwave/storage/grid_fs.rb', line 31 def read grid.open(@path, 'r').data end |
#url ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/carrierwave/storage/grid_fs.rb', line 23 def url unless @uploader.grid_fs_access_url nil else [@uploader.grid_fs_access_url, @path].join("/") end end |
#write(file) ⇒ Object
35 36 37 38 39 |
# File 'lib/carrierwave/storage/grid_fs.rb', line 35 def write(file) grid.open(@uploader.store_path, 'w', :content_type => file.content_type) do |f| f.write(file.read) end end |