Module: MongoDoc::Document::ClassMethods

Defined in:
lib/mongodoc/document.rb

Instance Method Summary collapse

Instance Method Details

#bson_create(bson_hash, options = {}) ⇒ Object



117
118
119
120
121
122
123
# File 'lib/mongodoc/document.rb', line 117

def bson_create(bson_hash, options = {})
  new.tap do |obj|
    bson_hash.each do |name, value|
      obj.send("#{name}=", MongoDoc::BSON.decode(value, options))
    end
  end
end

#collectionObject



125
126
127
# File 'lib/mongodoc/document.rb', line 125

def collection
  @collection ||= MongoDoc::Collection.new(collection_name)
end

#collection_nameObject



129
130
131
# File 'lib/mongodoc/document.rb', line 129

def collection_name
  self.to_s.tableize.gsub('/', '.')
end

#create(attrs = {}) ⇒ Object



133
134
135
136
137
# File 'lib/mongodoc/document.rb', line 133

def create(attrs = {})
  instance = new(attrs)
  instance.save(false)
  instance
end

#create!(attrs = {}) ⇒ Object



139
140
141
142
143
# File 'lib/mongodoc/document.rb', line 139

def create!(attrs = {})
  instance = new(attrs)
  instance.save!(true)
  instance
end