Class: Mongoo::GridFs::File
- Inherits:
-
Object
- Object
- Mongoo::GridFs::File
- Defined in:
- lib/mongoo/grid_fs/file.rb
Instance Method Summary collapse
- #delete(*args) ⇒ Object
- #get(*args) ⇒ Object
- #grid ⇒ Object
-
#initialize(container_hash, db_lambda) ⇒ File
constructor
A new instance of File.
- #put(*args) ⇒ Object
Constructor Details
#initialize(container_hash, db_lambda) ⇒ File
Returns a new instance of File.
5 6 7 8 |
# File 'lib/mongoo/grid_fs/file.rb', line 5 def initialize(container_hash, db_lambda) @db_lambda = db_lambda @container_hash = container_hash end |
Instance Method Details
#delete(*args) ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/mongoo/grid_fs/file.rb', line 18 def delete(*args) if file_id = @container_hash["_id"] args ||= [] args.unshift file_id res = grid.delete(*args) @container_hash.clear res end end |
#get(*args) ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/mongoo/grid_fs/file.rb', line 28 def get(*args) if file_id = @container_hash["_id"] args ||= [] args.unshift file_id if io = grid.get(*args) io.read end end end |
#grid ⇒ Object
10 11 12 |
# File 'lib/mongoo/grid_fs/file.rb', line 10 def grid @grid ||= Mongo::Grid.new(@db_lambda.call) end |
#put(*args) ⇒ Object
14 15 16 |
# File 'lib/mongoo/grid_fs/file.rb', line 14 def put(*args) @container_hash["_id"] = grid.put(*args) end |