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, 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_typeObject



45
46
47
# File 'lib/carrierwave/storage/grid_fs.rb', line 45

def content_type
  grid.open(@path, 'r').content_type
end

#deleteObject



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

def delete
  grid.delete(@path)
end

#pathObject



19
20
21
# File 'lib/carrierwave/storage/grid_fs.rb', line 19

def path
  nil
end

#readObject



31
32
33
# File 'lib/carrierwave/storage/grid_fs.rb', line 31

def read
  grid.open(@path, 'r').data
end

#urlObject



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