grip
GridFS attachments for MongoMapper
installation
The grip gem is hosted on gemcutter.org:
gem install miso grip
Usage (See tests for better docs)
class Doc
include MongoMapper::Document
include Grip
has_grid_attachment :image, :versions => {:thumb => {:width=>50,:height=>50}}
end
image = File.open('foo.png', 'r')
@doc = Doc.create(:image => image)
puts @doc.image.name
=> "image"
puts @doc.image.file_size
=> 100
puts @doc.image.file_name
=> "foo.png"
puts @doc.image.grid_key
=> "docs/<id>/image"
# works on nested variants as well
puts @doc.image.thumb.name
=> "thumb"
puts @doc.image.thumb.file_size
=> 50
puts @doc.image.thumb.file_name
=> "foo.png"
puts @doc.image.thumb.grid_key
=> "attachments/<id>/thumb"
@doc.image.file # contents read from gridfs for serving from rack/metal/controller