Module: MongoDoc::Document::ClassMethods
- Defined in:
- lib/mongo_doc/document.rb
Instance Method Summary collapse
- #bson_create(bson_hash, options = {}) ⇒ Object
- #collection ⇒ Object
- #collection_name ⇒ Object
- #create(attrs = {}) ⇒ Object
- #create!(attrs = {}) ⇒ Object
Instance Method Details
#bson_create(bson_hash, options = {}) ⇒ Object
114 115 116 117 118 119 120 |
# File 'lib/mongo_doc/document.rb', line 114 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
122 123 124 |
# File 'lib/mongo_doc/document.rb', line 122 def collection @collection ||= MongoDoc::Collection.new(collection_name) end |
#collection_name ⇒ Object
126 127 128 |
# File 'lib/mongo_doc/document.rb', line 126 def collection_name self.to_s.tableize.gsub('/', '.') end |
#create(attrs = {}) ⇒ Object
130 131 132 133 134 |
# File 'lib/mongo_doc/document.rb', line 130 def create(attrs = {}) instance = new(attrs) instance.save(true) instance end |
#create!(attrs = {}) ⇒ Object
136 137 138 139 140 |
# File 'lib/mongo_doc/document.rb', line 136 def create!(attrs = {}) instance = new(attrs) instance.save! instance end |