Module: MiniMongo::Mapper::ClassMethods
- Defined in:
- lib/mini_mongo/mapper.rb
Instance Method Summary collapse
- #find(id, attrs = {}) ⇒ Object
- #insert(attrs = {}) ⇒ Object
- #maps(name) ⇒ Object
- #remove(id) ⇒ Object
- #update(id, attrs = {}) ⇒ Object
Instance Method Details
#find(id, attrs = {}) ⇒ Object
11 12 13 14 |
# File 'lib/mini_mongo/mapper.rb', line 11 def find(id, attrs={}) doc = @@collection.find("_id" => BSON::ObjectId(id)) self.class_eval("new(#{doc})") end |
#insert(attrs = {}) ⇒ Object
16 17 18 19 |
# File 'lib/mini_mongo/mapper.rb', line 16 def insert(attrs={}) doc = @@collection.insert(attrs) self.class_eval("new(#{doc})") end |
#maps(name) ⇒ Object
30 31 32 33 |
# File 'lib/mini_mongo/mapper.rb', line 30 def maps(name) @@collection_name = name.to_s @@collection = MiniMogo.db_connection.collection(name.to_s) end |
#remove(id) ⇒ Object
26 27 28 |
# File 'lib/mini_mongo/mapper.rb', line 26 def remove(id) @@collection.remove("_id" => BSON::ObjectId(id)) end |
#update(id, attrs = {}) ⇒ Object
21 22 23 24 |
# File 'lib/mini_mongo/mapper.rb', line 21 def update(id, attrs={}) doc = @@collection.update({"_id" => BSON::ObjectId(id)}, attrs) self.class_eval("new(#{doc})") end |