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.



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_typeObject



73
74
75
# File 'lib/carrierwave/storage/grid_fs.rb', line 73

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

#deleteObject



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

def delete
  grid.delete(@path)
end

#file_lengthObject



77
78
79
# File 'lib/carrierwave/storage/grid_fs.rb', line 77

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

#pathObject



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

def path
  nil
end

#readObject



59
60
61
# File 'lib/carrierwave/storage/grid_fs.rb', line 59

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

#urlObject



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