Sha256: 3471717e3221bff128e05a9f5722187fa509d5ff6a3a93b6fbc12e64f7be45f2

Contents?: true

Size: 569 Bytes

Versions: 37

Compression:

Stored size: 569 Bytes

Contents

class Object
  define_method :singleton_class, instance_method(:metaclass) unless respond_to?(:singleton_class)

  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

  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
end

Version data entries

37 entries across 37 versions & 2 rubygems

Version Path
mongo_doc-0.6.34 lib/mongo_doc/ext/object.rb
mongo_doc-0.6.33 lib/mongo_doc/ext/object.rb
mongo_doc-0.6.32 lib/mongo_doc/ext/object.rb
mongo_doc-0.6.31 lib/mongo_doc/ext/object.rb
mongo_doc-0.6.30 lib/mongo_doc/ext/object.rb
mongo_doc-0.6.29 lib/mongo_doc/ext/object.rb
mongo_doc-0.6.28 lib/mongo_doc/ext/object.rb
mongo_doc-0.6.27 lib/mongo_doc/ext/object.rb
mongo_doc-0.6.26 lib/mongo_doc/ext/object.rb
mongo_doc-0.6.25 lib/mongo_doc/ext/object.rb
mongo_doc-0.6.23 lib/mongo_doc/ext/object.rb
mongo_doc-0.6.22 lib/mongo_doc/ext/object.rb
mongo_doc-0.6.21 lib/mongo_doc/ext/object.rb
mongo_doc-0.6.20 lib/mongo_doc/ext/object.rb
mongo_doc-0.6.19 lib/mongo_doc/ext/object.rb
mongo_doc-0.6.18 lib/mongo_doc/ext/object.rb
mongo_doc-0.6.17 lib/mongo_doc/ext/object.rb
mongo_doc-0.6.16 lib/mongo_doc/ext/object.rb
mongo_doc-0.6.15 lib/mongo_doc/ext/object.rb
mongo_doc-0.6.14 lib/mongo_doc/ext/object.rb