Module: BSON::Regexp::ClassMethods

Defined in:
lib/bson/regexp.rb

Overview

Since:

  • 2.0.0

Instance Method Summary collapse

Instance Method Details

#from_bson(buffer) ⇒ Regexp

Deserialize the regular expression from BSON.

Parameters:

Returns:

  • (Regexp)

    The decoded regular expression.

See Also:

Since:

  • 2.0.0



178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
# File 'lib/bson/regexp.rb', line 178

def from_bson(buffer)
  pattern = buffer.get_cstring
  options = 0
  while (option = buffer.get_byte) != NULL_BYTE
    case option
    when IGNORECASE_VALUE
      options |= ::Regexp::IGNORECASE
    when MULTILINE_VALUE, NEWLINE_VALUE
      options |= ::Regexp::MULTILINE
    when EXTENDED_VALUE
      options |= ::Regexp::EXTENDED
    end
  end
  Raw.new(pattern, options)
end