Module: MongoDoc::Document::ClassMethods
- Defined in:
- lib/mongo_doc/document.rb
Instance Method Summary collapse
- #bson_create(bson_hash, options = {}) ⇒ Object
- #collection ⇒ Object
- #create(attrs = {}) ⇒ Object
- #create!(attrs = {}) ⇒ Object
Instance Method Details
#bson_create(bson_hash, options = {}) ⇒ Object
139 140 141 142 143 144 145 |
# File 'lib/mongo_doc/document.rb', line 139 def bson_create(bson_hash, = {}) allocate.tap do |obj| bson_hash.each do |name, value| obj.send("#{name}=", MongoDoc::BSON.decode(value, )) end end end |
#collection ⇒ Object
147 148 149 |
# File 'lib/mongo_doc/document.rb', line 147 def collection @collection ||= MongoDoc::Collection.new(collection_name) end |
#create(attrs = {}) ⇒ Object
151 152 153 154 155 |
# File 'lib/mongo_doc/document.rb', line 151 def create(attrs = {}) instance = new(attrs) instance.save(true) instance end |
#create!(attrs = {}) ⇒ Object
157 158 159 160 161 |
# File 'lib/mongo_doc/document.rb', line 157 def create!(attrs = {}) instance = new(attrs) instance.save! instance end |