class CarrierWave::Storage::GridFS::File

Public Instance Methods

content_type() click to toggle source
# File lib/carrierwave/storage/grid_fs.rb, line 44
def content_type
  grid.open(@path, 'r').content_type
end
delete() click to toggle source
# File lib/carrierwave/storage/grid_fs.rb, line 40
def delete
  grid.delete(@path)
end
file_length() click to toggle source
# File lib/carrierwave/storage/grid_fs.rb, line 48
def file_length
  grid.open(@path, 'r').file_length
end
path() click to toggle source
# File lib/carrierwave/storage/grid_fs.rb, line 18
def path
  nil
end
read() click to toggle source
# File lib/carrierwave/storage/grid_fs.rb, line 30
def read
  grid.open(@path, 'r').data
end
url() click to toggle source
# File lib/carrierwave/storage/grid_fs.rb, line 22
def url
  unless @uploader.grid_fs_access_url
    nil
  else
    [@uploader.grid_fs_access_url, @path].join("/")
  end
end
write(file) click to toggle source
# File lib/carrierwave/storage/grid_fs.rb, line 34
def write(file)
  grid.open(@uploader.store_path, 'w', :content_type => file.content_type) do |f| 
    f.write(file.read)
  end
end

Protected Instance Methods

database() click to toggle source
# File lib/carrierwave/storage/grid_fs.rb, line 54
def database
  @connection ||= begin
    host = @uploader.grid_fs_host
    port = @uploader.grid_fs_port
    database = @uploader.grid_fs_database
    username = @uploader.grid_fs_username
    password = @uploader.grid_fs_password
    db = Mongo::Connection.new(host, port).db(database)
    db.authenticate(username, password) if username && password
    db
  end
end
grid() click to toggle source
# File lib/carrierwave/storage/grid_fs.rb, line 67
def grid
  @grid ||= Mongo::GridFileSystem.new(database)
end

Public Class Methods

new(uploader, path) click to toggle source
# File lib/carrierwave/storage/grid_fs.rb, line 13
def initialize(uploader, path)
  @path = path
  @uploader = uploader
end