Skip to content
This repository has been archived by the owner on Apr 22, 2021. It is now read-only.

Commit

Permalink
Fix #to_utf8_binary conflicts with bson gem
Browse files Browse the repository at this point in the history
We rename Moped::BSON::Extensions::String#to_utf8_binary and
Moped::BSON::Extensions::Symbol#to_utf8_binary in order to avoid
conflicts with bson 2.x and later.

Fixes mongoid#381.
  • Loading branch information
agis committed Jul 21, 2015
1 parent e4b591f commit 16e2a7c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions lib/moped/bson/code.rb
Expand Up @@ -21,7 +21,7 @@ def __bson_dump__(io, key)
io << key.to_bson_cstring
code_start = io.bytesize
io << START_LENGTH
data = code.to_utf8_binary
data = code.to_utf8_binary_moped
io << [data.bytesize+1].pack(INT32_PACK)
io << data
io << NULL_BYTE
Expand All @@ -30,7 +30,7 @@ def __bson_dump__(io, key)
else
io << Types::CODE
io << key.to_bson_cstring
data = code.to_utf8_binary
data = code.to_utf8_binary_moped
io << [data.bytesize+1].pack(INT32_PACK)
io << data
io << NULL_BYTE
Expand Down
6 changes: 3 additions & 3 deletions lib/moped/bson/extensions/string.rb
Expand Up @@ -7,7 +7,7 @@ module String
def __bson_dump__(io, key)
io << Types::STRING
io << key.to_bson_cstring
data = to_utf8_binary
data = to_utf8_binary_moped
io << [ data.bytesize + 1 ].pack(INT32_PACK)
io << data
io << NULL_BYTE
Expand All @@ -18,10 +18,10 @@ def to_bson_cstring
raise EncodingError, "#{inspect} cannot be converted to a BSON " \
"cstring because it contains a null byte"
end
to_utf8_binary << NULL_BYTE
to_utf8_binary_moped << NULL_BYTE
end

def to_utf8_binary
def to_utf8_binary_moped
encode(Moped::BSON::UTF8_ENCODING).force_encoding(Moped::BSON::BINARY_ENCODING)
rescue EncodingError
data = dup.force_encoding(Moped::BSON::UTF8_ENCODING)
Expand Down
6 changes: 3 additions & 3 deletions lib/moped/bson/extensions/symbol.rb
Expand Up @@ -7,7 +7,7 @@ module Symbol
def __bson_dump__(io, key)
io << Types::SYMBOL
io << key.to_bson_cstring
data = to_utf8_binary
data = to_utf8_binary_moped
io << [ data.bytesize + 1 ].pack(INT32_PACK)
io << data
io << NULL_BYTE
Expand All @@ -17,8 +17,8 @@ def to_bson_cstring
to_s.to_bson_cstring
end

def to_utf8_binary
to_s.to_utf8_binary
def to_utf8_binary_moped
to_s.to_utf8_binary_moped
end

module ClassMethods
Expand Down

0 comments on commit 16e2a7c

Please sign in to comment.