Class: Gridfs
Instance Method Summary collapse
- #flush_delete(queued_for_delete = nil) ⇒ Object
- #flush_write(image_options = nil) ⇒ Object
-
#initialize ⇒ Gridfs
constructor
A new instance of Gridfs.
- #read(id = nil) ⇒ Object
Methods inherited from Storage
Constructor Details
#initialize ⇒ Gridfs
Returns a new instance of Gridfs.
3 4 5 |
# File 'lib/attach_it/storage/gridfs.rb', line 3 def initialize @grid ||= Mongo::Grid.new(MongoMapper.database) end |
Instance Method Details
#flush_delete(queued_for_delete = nil) ⇒ Object
24 25 26 27 28 |
# File 'lib/attach_it/storage/gridfs.rb', line 24 def flush_delete(queued_for_delete = nil) queued_for_delete.each do |id| @grid.delete(id) end end |
#flush_write(image_options = nil) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/attach_it/storage/gridfs.rb', line 7 def flush_write( = nil) .styles.each do |style_name, style_value| begin gridfs_id = @grid.put(transform(style_value, .assigned_file.path).to_blob, :filename => style_name.to_s + '_' + .file_name, :_id => "#{.object_id}_#{.name}_#{style_name}") rescue Exception => exception .add_error(exception.to_s) end end begin gridfs_id = @grid.put(.assigned_file, :filename => 'original_' + .file_name, :_id => "#{.object_id}_#{.name}_original") rescue Exception => exception .add_error(exception.to_s) end end |
#read(id = nil) ⇒ Object
30 31 32 |
# File 'lib/attach_it/storage/gridfs.rb', line 30 def read(id = nil) @grid.get(id) unless id.nil? end |