Module: MongoDoc::Document::ClassMethods

Defined in:
lib/mongo_doc/document.rb

Instance Method Summary collapse

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, options = {})
  allocate.tap do |obj|
    bson_hash.each do |name, value|
      obj.send("#{name}=", MongoDoc::BSON.decode(value, options))
    end
  end
end

#collectionObject



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