Sha256: 486378737b51415710495c730b81b2f3fdc3f6534bf0f41513c2f15ff3938a71

Contents?: true

Size: 631 Bytes

Versions: 4

Compression:

Stored size: 631 Bytes

Contents

class String
  def to_bson_code
    BSON::Code.new(self)
  end
end

class Symbol
  def to_bson
    BSON::Symbol.new(self.to_s)
  end
end

class Regexp
  def to_bson
    Java::JavaUtilRegex::Pattern.compile(source, options * 2)
  end
end

class Object
  def to_bson
    self
  end
end

class Hash
  def to_bson
    obj = ::JMongo::BasicDBObject.new
    self.each_pair do |key, val|
      obj.put( key.to_s, val.to_bson )
    end
    obj
  end
end

class Array
  def to_bson
    list = Array.new #Java::ComMongodb::DBObject[ary.length].new
    self.each_with_index do |ele, i|
      list[i] = ele.to_bson
    end
    list
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
jmongo-1.1.5 lib/jmongo/mongo/ruby_ext.rb
jmongo-1.1.4 lib/jmongo/mongo/ruby_ext.rb
jmongo-1.1.3 lib/jmongo/mongo/ruby_ext.rb
jmongo-1.1.2 lib/jmongo/mongo/ruby_ext.rb