Class: Morel::Collection

Inherits:
Object
  • Object
show all
Defined in:
lib/morel/collection.rb,
lib/morel/sorted_window.rb

Constant Summary collapse

OPERATIONS =
[
  :insert,
  :find_one,
  :map_reduce
]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Collection

Returns a new instance of Collection.



8
9
10
11
# File 'lib/morel/collection.rb', line 8

def initialize name
  @name = name
  @collection = db.create_collection(name)
end

Instance Attribute Details

#collectionObject

Returns the value of attribute collection.



6
7
8
# File 'lib/morel/collection.rb', line 6

def collection
  @collection
end

#nameObject

Returns the value of attribute name.



6
7
8
# File 'lib/morel/collection.rb', line 6

def name
  @name
end

Class Method Details

.db=(db) ⇒ Object



16
17
18
# File 'lib/morel/collection.rb', line 16

def self.db= db
  @@db = db
end

Instance Method Details

#dbObject



13
14
15
# File 'lib/morel/collection.rb', line 13

def db
  @@db
end

#deleteObject



20
21
22
# File 'lib/morel/collection.rb', line 20

def delete
  db.drop_collection(name)
end

#firstObject



24
25
26
# File 'lib/morel/collection.rb', line 24

def first
  find_one
end

#sorted_window(size, &block) ⇒ Object



6
7
8
# File 'lib/morel/sorted_window.rb', line 6

def sorted_window size, &block
  SortedWindow.new(:collection => self, :size => size, :block => block)
end