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

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

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uploader, path) ⇒ File

Returns a new instance of File.



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

def initialize(uploader, path)
  @path = path
  @uploader = uploader
  @grid_file = nil
end

Class Attribute Details

.gridObject

Returns the value of attribute grid.



70
71
72
# File 'lib/carrierwave/storage/grid_fs.rb', line 70

def grid
  @grid
end

Instance Attribute Details

#grid_file(&block) ⇒ Object (readonly)

Returns the value of attribute grid_file.



26
27
28
# File 'lib/carrierwave/storage/grid_fs.rb', line 26

def grid_file
  @grid_file
end

#pathObject (readonly)

Returns the value of attribute path.



24
25
26
# File 'lib/carrierwave/storage/grid_fs.rb', line 24

def path
  @path
end

#uploaderObject (readonly)

Returns the value of attribute uploader.



25
26
27
# File 'lib/carrierwave/storage/grid_fs.rb', line 25

def uploader
  @uploader
end

Instance Method Details

#readObject



52
53
54
# File 'lib/carrierwave/storage/grid_fs.rb', line 52

def read
  grid_file.data if grid_file
end

#urlObject



34
35
36
37
38
39
40
# File 'lib/carrierwave/storage/grid_fs.rb', line 34

def url
  unless @uploader.grid_fs_access_url
    nil
  else
    ::File.join(@uploader.grid_fs_access_url, path)
  end
end

#write(file) ⇒ Object



46
47
48
49
50
# File 'lib/carrierwave/storage/grid_fs.rb', line 46

def write(file)
  grid[path] = file
ensure
  @grid_file = nil
end