Module: MongoDoc::Document::ClassMethods

Defined in:
lib/mongodoc/document.rb

Instance Method Summary collapse

Instance Method Details

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



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

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



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

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

#collection_nameObject



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

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

#create(attrs = {}) ⇒ Object



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

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

#create!(attrs = {}) ⇒ Object



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

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