Class: Object

Inherits:
BasicObject
Defined in:
lib/mongo_doc/ext/object.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

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



12
13
14
15
16
17
18
# File 'lib/mongo_doc/ext/object.rb', line 12

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

Instance Method Details

#to_bson(*args) ⇒ Object



4
5
6
7
8
9
10
# File 'lib/mongo_doc/ext/object.rb', line 4

def to_bson(*args)
  {MongoDoc::BSON::CLASS_KEY => self.class.name}.tap do |bson_hash|
    instance_variables.each do |name|
      bson_hash[name[1..-1]] = instance_variable_get(name).to_bson(args)
    end
  end
end