Class: PeaceLove::Collection
- Inherits:
-
Object
- Object
- PeaceLove::Collection
- Defined in:
- lib/peace_love/collection.rb
Instance Attribute Summary collapse
-
#mixin ⇒ Object
readonly
Returns the value of attribute mixin.
-
#mongo_collection ⇒ Object
readonly
Returns the value of attribute mongo_collection.
Instance Method Summary collapse
- #__extend(doc) ⇒ Object
- #__wrap(hash) ⇒ Object
-
#__wrap_cursor(cursor) ⇒ Object
TODO find_and_modify.
- #build(seed = {}) ⇒ Object
- #find(*args, &block) ⇒ Object
- #find_one(*args) ⇒ Object
-
#initialize(collection, mixin) ⇒ Collection
constructor
A new instance of Collection.
Constructor Details
#initialize(collection, mixin) ⇒ Collection
Returns a new instance of Collection.
5 6 7 8 |
# File 'lib/peace_love/collection.rb', line 5 def initialize(collection, mixin) @collection = @mongo_collection = collection @mixin = mixin end |
Instance Attribute Details
#mixin ⇒ Object (readonly)
Returns the value of attribute mixin.
3 4 5 |
# File 'lib/peace_love/collection.rb', line 3 def mixin @mixin end |
#mongo_collection ⇒ Object (readonly)
Returns the value of attribute mongo_collection.
3 4 5 |
# File 'lib/peace_love/collection.rb', line 3 def mongo_collection @mongo_collection end |
Instance Method Details
#__extend(doc) ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/peace_love/collection.rb', line 37 def __extend(doc) if mixin doc.extend mixin doc.__collection = self if doc.respond_to?(:__collection=) end doc end |
#__wrap(hash) ⇒ Object
32 33 34 35 |
# File 'lib/peace_love/collection.rb', line 32 def __wrap(hash) return nil unless hash.respond_to?(:to_hash) __extend( AngryHash[ hash ] ) end |
#__wrap_cursor(cursor) ⇒ Object
TODO find_and_modify
28 29 30 |
# File 'lib/peace_love/collection.rb', line 28 def __wrap_cursor(cursor) PeaceLove::Cursor.new(cursor,self) end |
#build(seed = {}) ⇒ Object
10 11 12 |
# File 'lib/peace_love/collection.rb', line 10 def build(seed={}) __wrap( seed ) end |
#find(*args, &block) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/peace_love/collection.rb', line 18 def find(*args,&block) if block_given? @collection.find(*args) {|cursor| yield __wrap_cursor(cursor)} else __wrap_cursor(@collection.find(*args)) end end |
#find_one(*args) ⇒ Object
14 15 16 |
# File 'lib/peace_love/collection.rb', line 14 def find_one(*args) __wrap( @collection.find_one(*args) ) end |