mongodb/mongo-ruby-driver — pull request #323 by estolfo (2013-12-03 21:33:10+00:00)
Title: RUBY-698 Support optional Regex compilation with pure Ruby de/serialization

DO NOT MERGE YET
I have to follow up on supporting this option with #aggregate

This provides support for a "compile_regex" option to commands and to finds.

If compile_regex => false, a LazyRegexp object will be returned, which wraps the un-compiled Regexp. The LazyRegexp can be compiled with the #compile method (at which point, a core Ruby Regexp object is returned).

A LazyRegexp has a pattern and options. The options can be an integer, array, or a string. For example:

LazyRegexp.new('.*', 'i', 'l')
LazyRegexp.new('.*', 7)
LazyRegexp.new('.*', 'il')

When "compile_regex" is true, a core Ruby Regexp object is returned, which is compiled upon initialization.
The "compile_regex" default value is true.

LazyRegexp can represent options ('l' and 'u') that are not supported by the core Ruby Regexp object. This is to allow for the wrapper to deserialize a BSON Regex and not lose the extra flags.

I will open a separate pull request with the c ext and the java changes to support this.