Class: Moped::GridFS::Files

Inherits:
Object
  • Object
show all
Includes:
Enumerable, Bucketable
Defined in:
lib/moped/gridfs/files.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Bucketable

#chunks_collection, #files_collection

Constructor Details

#initialize(bucket) ⇒ Files

Returns a new instance of Files.



12
13
14
# File 'lib/moped/gridfs/files.rb', line 12

def initialize(bucket)
  @bucket = bucket
end

Instance Attribute Details

#bucketObject (readonly)

Returns the value of attribute bucket.



10
11
12
# File 'lib/moped/gridfs/files.rb', line 10

def bucket
  @bucket
end

Instance Method Details

#[](id) ⇒ Object



16
17
18
# File 'lib/moped/gridfs/files.rb', line 16

def [](id)
  bucket.open(id, 'r')
end

#countObject



20
21
22
# File 'lib/moped/gridfs/files.rb', line 20

def count
  files_collection.find.count
end

#each(&block) ⇒ Object



24
25
26
# File 'lib/moped/gridfs/files.rb', line 24

def each(&block)
  files_collection.find.each { |document| yield(self[document['_id']]) }
end