Class: CarrierWave::Storage::GridFS::File

Inherits:
Object
  • Object
show all
Defined in:
lib/carrierwave/storage/grid_fs.rb

Instance Method Summary collapse

Constructor Details

#initialize(uploader, database, path) ⇒ File

Returns a new instance of File.



15
16
17
18
19
# File 'lib/carrierwave/storage/grid_fs.rb', line 15

def initialize(uploader, database, path)
  @database = database
  @path = path
  @uploader = uploader
end

Instance Method Details

#content_typeObject



41
42
43
# File 'lib/carrierwave/storage/grid_fs.rb', line 41

def content_type
  ::GridFS::GridStore.open(@database, @path, 'r') { |f| return f.content_type }
end

#deleteObject



37
38
39
# File 'lib/carrierwave/storage/grid_fs.rb', line 37

def delete
  ::GridFS::GridStore.unlink(@database, @path)
end

#pathObject



21
22
23
# File 'lib/carrierwave/storage/grid_fs.rb', line 21

def path
  nil
end

#readObject



33
34
35
# File 'lib/carrierwave/storage/grid_fs.rb', line 33

def read
  ::GridFS::GridStore.read(@database, @path)
end

#urlObject



25
26
27
28
29
30
31
# File 'lib/carrierwave/storage/grid_fs.rb', line 25

def url
  unless @uploader.grid_fs_access_url
    nil
  else
    [@uploader.grid_fs_access_url, @path].join("/")
  end
end