Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions lib/bson/dbref.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,6 @@ module BSON
class DBRef < Document
include JSON

# The constant for the collection reference field.
#
# @deprecated
COLLECTION = '$ref'.freeze

# The constant for the id field.
#
# @deprecated
ID = '$id'.freeze

# The constant for the database field.
#
# @deprecated
DATABASE = '$db'.freeze

# @return [ String ] collection The collection name.
def collection
self['$ref']
Expand Down
13 changes: 0 additions & 13 deletions lib/bson/environment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,5 @@ module Environment
def jruby?
@jruby ||= defined?(JRUBY_VERSION)
end

# Determine if we are using Ruby version 1.9.
#
# @example Are we running with Ruby version 1.9?
# Environment.ruby_1_9?
#
# @return [ true, false ] If the Ruby version is 1.9.
#
# @since 4.2.0
# @deprecated
def ruby_1_9?
@ruby_1_9 ||= RUBY_VERSION < '2.0.0'
end
end
end
23 changes: 0 additions & 23 deletions lib/bson/error/illegal_key.rb

This file was deleted.

3 changes: 3 additions & 0 deletions lib/bson/float.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ module Float
# The pack directive is for 8 byte floating points.
#
# @since 2.0.0
# @deprecated No longer used internally; retained for backward
# compatibility and slated for removal in a future major version.
PACK = "E"
deprecate_constant :PACK

# Get the floating point as encoded BSON.
#
Expand Down
6 changes: 6 additions & 0 deletions lib/bson/int32.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,18 @@ class Int32
# The number of bytes constant.
#
# @since 4.0.0
# @deprecated No longer used internally; retained for backward
# compatibility and slated for removal in a future major version.
BYTES_LENGTH = 4
deprecate_constant :BYTES_LENGTH

# Constant for the int 32 pack directive.
#
# @since 2.0.0
# @deprecated No longer used internally; retained for backward
# compatibility and slated for removal in a future major version.
PACK = "l<"
deprecate_constant :PACK

# Deserialize an Integer from BSON.
#
Expand Down
3 changes: 3 additions & 0 deletions lib/bson/int64.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ class Int64
# Constant for the int 64 pack directive.
#
# @since 2.0.0
# @deprecated No longer used internally; retained for backward
# compatibility and slated for removal in a future major version.
PACK = "q<"
deprecate_constant :PACK

# Deserialize an Integer from BSON.
#
Expand Down
9 changes: 9 additions & 0 deletions lib/bson/integer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,24 @@ module Integer
# The BSON index size.
#
# @since 2.0.0
# @deprecated No longer used internally; retained for backward
# compatibility and slated for removal in a future major version.
BSON_INDEX_SIZE = 1024

# A hash of index values for array optimization.
#
# @since 2.0.0
# @deprecated No longer used internally; retained for backward
# compatibility and slated for removal in a future major version.
BSON_ARRAY_INDEXES = ::Array.new(BSON_INDEX_SIZE) do |i|
(i.to_s.b << NULL_BYTE).freeze
end.freeze

# Deprecated after BSON_ARRAY_INDEXES is built, since that (also
# deprecated) constant references BSON_INDEX_SIZE at load time.
deprecate_constant :BSON_INDEX_SIZE
deprecate_constant :BSON_ARRAY_INDEXES

# Is this integer a valid BSON 32 bit value?
#
# @example Is the integer a valid 32 bit value?
Expand Down
6 changes: 1 addition & 5 deletions lib/bson/open_struct.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,7 @@ module OpenStruct
#
# @since 4.2.0
def to_bson(buffer = ByteBuffer.new)
if Environment.ruby_1_9?
marshal_dump.dup
else
to_h
end.to_bson(buffer)
to_h.to_bson(buffer)
end

# The BSON type for OpenStruct objects is the Hash type of 0x03.
Expand Down
7 changes: 0 additions & 7 deletions lib/bson/regexp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,6 @@ module Regexp
# @since 3.2.6
NEWLINE_VALUE = 's'

# Ruby multiline constant.
#
# @since 3.2.6
#
# @deprecated Will be removed in 5.0
RUBY_MULTILINE_VALUE = 'ms'

# Get the regexp as JSON hash data.
#
# @example Get the regexp as a JSON hash.
Expand Down
5 changes: 0 additions & 5 deletions lib/bson/string.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,6 @@ module String
# @since 2.0.0
BSON_TYPE = ::String.new(2.chr, encoding: BINARY).freeze

# Regex for matching illegal BSON keys.
#
# @since 4.1.0
ILLEGAL_KEY = /(\A[$])|(\.)/

# Get the string as encoded BSON.
#
# @example Get the string as encoded BSON.
Expand Down
1 change: 0 additions & 1 deletion lib/bson/timestamp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ def <=>(other)
# @return [ Hash ] The timestamp as a JSON hash.
#
# @since 2.0.0
# @deprecated Use as_extended_json instead.
def as_json(*args)
as_extended_json
end
Expand Down
28 changes: 14 additions & 14 deletions spec/bson/byte_buffer_write_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@

it 'appends the string to the byte buffer' do
expect(modified.to_s).to eq(
"#{[ 4 ].pack(BSON::Int32::PACK)}#{(string.bytesize + 1).to_bson.to_s}#{string}#{BSON::NULL_BYTE}"
"#{[ 4 ].pack(PackDirectives::INT32)}#{(string.bytesize + 1).to_bson.to_s}#{string}#{BSON::NULL_BYTE}"
)
end

Expand Down Expand Up @@ -457,7 +457,7 @@
end

it 'appends the double to the buffer' do
expect(modified.to_s).to eq([ 1.2332 ].pack(Float::PACK))
expect(modified.to_s).to eq([ 1.2332 ].pack(PackDirectives::FLOAT))
end

it 'increments the write position by 8' do
Expand All @@ -471,7 +471,7 @@
end

it 'writes a double' do
expect(modified.to_s).to eq([ 3 ].pack(Float::PACK))
expect(modified.to_s).to eq([ 3 ].pack(PackDirectives::FLOAT))
end

it 'increments the write position by 8' do
Expand Down Expand Up @@ -525,7 +525,7 @@
end

let(:expected) do
[ Integer::MAX_32BIT - 1 ].pack(BSON::Int32::PACK)
[ Integer::MAX_32BIT - 1 ].pack(PackDirectives::INT32)
end

it 'appends the int32 to the byte buffer' do
Expand All @@ -544,7 +544,7 @@
end

let(:expected) do
[ Integer::MIN_32BIT + 1 ].pack(BSON::Int32::PACK)
[ Integer::MIN_32BIT + 1 ].pack(PackDirectives::INT32)
end

it 'appends the int32 to the byte buffer' do
Expand Down Expand Up @@ -573,7 +573,7 @@
end

let(:expected) do
[ 4 ].pack(BSON::Int32::PACK)
[ 4 ].pack(PackDirectives::INT32)
end

it 'appends the int32 to the byte buffer' do
Expand Down Expand Up @@ -627,7 +627,7 @@
end

let(:expected) do
[ 4294967295 ].pack(BSON::Int32::PACK)
[ 4294967295 ].pack(PackDirectives::INT32)
end

it 'appends the int32 to the byte buffer' do
Expand Down Expand Up @@ -693,7 +693,7 @@
end

let(:expected) do
[ Integer::MAX_64BIT - 1 ].pack(BSON::Int64::PACK)
[ Integer::MAX_64BIT - 1 ].pack(PackDirectives::INT64)
end

it 'appends the int64 to the byte buffer' do
Expand All @@ -712,7 +712,7 @@
end

let(:expected) do
[ Integer::MIN_64BIT + 1 ].pack(BSON::Int64::PACK)
[ Integer::MIN_64BIT + 1 ].pack(PackDirectives::INT64)
end

it 'appends the int64 to the byte buffer' do
Expand Down Expand Up @@ -751,7 +751,7 @@
end

let(:expected) do
[ 4 ].pack(BSON::Int64::PACK)
[ 4 ].pack(PackDirectives::INT64)
end

it 'appends the int64 to the byte buffer' do
Expand All @@ -767,19 +767,19 @@
describe '#replace_int32' do

let(:exp_0) do
[ 0 ].pack(BSON::Int32::PACK)
[ 0 ].pack(PackDirectives::INT32)
end

let(:exp_first) do
[ 5 ].pack(BSON::Int32::PACK)
[ 5 ].pack(PackDirectives::INT32)
end

let(:exp_second) do
[ 4 ].pack(BSON::Int32::PACK)
[ 4 ].pack(PackDirectives::INT32)
end

let(:exp_42) do
[ 42 ].pack(BSON::Int32::PACK)
[ 42 ].pack(PackDirectives::INT32)
end

let(:modified) do
Expand Down
4 changes: 2 additions & 2 deletions spec/bson/date_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

let(:obj) { Date.new(2012, 1, 1) }
let(:time) { Time.utc(2012, 1, 1) }
let(:bson) { [ (time.to_f * 1000).to_i ].pack(BSON::Int64::PACK) }
let(:bson) { [ (time.to_f * 1000).to_i ].pack(PackDirectives::INT64) }

it_behaves_like "a serializable bson element"
end
Expand All @@ -34,7 +34,7 @@

let(:obj) { Date.new(1969, 1, 1) }
let(:time) { Time.utc(1969, 1, 1) }
let(:bson) { [ (time.to_f * 1000).to_i ].pack(BSON::Int64::PACK) }
let(:bson) { [ (time.to_f * 1000).to_i ].pack(PackDirectives::INT64) }

it_behaves_like "a serializable bson element"
end
Expand Down
4 changes: 2 additions & 2 deletions spec/bson/date_time_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@
context "when the date time is post epoch" do

let(:obj) { DateTime.new(2012, 1, 1, 0, 0, 0) }
let(:bson) { [ (obj.to_time.to_f * 1000).to_i ].pack(BSON::Int64::PACK) }
let(:bson) { [ (obj.to_time.to_f * 1000).to_i ].pack(PackDirectives::INT64) }

it_behaves_like "a serializable bson element"
end

context "when the date time is pre epoch" do

let(:obj) { DateTime.new(1969, 1, 1, 0, 0, 0) }
let(:bson) { [ (obj.to_time.to_f * 1000).to_i ].pack(BSON::Int64::PACK) }
let(:bson) { [ (obj.to_time.to_f * 1000).to_i ].pack(PackDirectives::INT64) }

it_behaves_like "a serializable bson element"
end
Expand Down
2 changes: 1 addition & 1 deletion spec/bson/decimal128_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
end

let(:expected_bson) do
[expected_low_bits].pack(BSON::Int64::PACK) + [expected_high_bits].pack(BSON::Int64::PACK)
[expected_low_bits].pack(PackDirectives::INT64) + [expected_high_bits].pack(PackDirectives::INT64)
end

it 'sets the correct high order bits' do
Expand Down
2 changes: 1 addition & 1 deletion spec/bson/float_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

let(:type) { 1.chr }
let(:obj) { 1.2332 }
let(:bson) { [ obj ].pack(Float::PACK) }
let(:bson) { [ obj ].pack(PackDirectives::FLOAT) }

it_behaves_like "a bson element"
it_behaves_like "a serializable bson element"
Expand Down
8 changes: 4 additions & 4 deletions spec/bson/int32_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@

let(:type) { 16.chr }
let(:obj) { 123 }
let(:bson) { [ obj ].pack(BSON::Int32::PACK) }
let(:bson) { [ obj ].pack(PackDirectives::INT32) }

it_behaves_like "a bson element"
it_behaves_like "a deserializable bson element"
Expand All @@ -76,9 +76,9 @@
describe "when the integer is negative" do

let(:decoded) { -1 }
let(:encoded) { BSON::ByteBuffer.new([ -1 ].pack(BSON::Int32::PACK)) }
let(:encoded) { BSON::ByteBuffer.new([ -1 ].pack(PackDirectives::INT32)) }
let(:decoded_2) { -50 }
let(:encoded_2) { BSON::ByteBuffer.new([ -50 ].pack(BSON::Int32::PACK)) }
let(:encoded_2) { BSON::ByteBuffer.new([ -50 ].pack(PackDirectives::INT32)) }

it "decodes a -1 correctly" do
expect(BSON::Int32.from_bson(encoded)).to eq(decoded)
Expand All @@ -95,7 +95,7 @@

let(:type) { 16.chr }
let(:obj) { BSON::Int32.new(Integer::MAX_32BIT - 1) }
let(:bson) { [ Integer::MAX_32BIT - 1 ].pack(BSON::Int32::PACK) }
let(:bson) { [ Integer::MAX_32BIT - 1 ].pack(PackDirectives::INT32) }

it_behaves_like "a serializable bson element"
end
Expand Down
4 changes: 2 additions & 2 deletions spec/bson/int64_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@

let(:type) { 18.chr }
let(:obj) { 1325376000000 }
let(:bson) { [ obj ].pack(BSON::Int64::PACK) }
let(:bson) { [ obj ].pack(PackDirectives::INT64) }

it_behaves_like "a bson element"
it_behaves_like "a deserializable bson element"
Expand Down Expand Up @@ -139,7 +139,7 @@

let(:type) { 18.chr }
let(:obj) { BSON::Int64.new(Integer::MAX_64BIT - 1) }
let(:bson) { [ Integer::MAX_64BIT - 1 ].pack(BSON::Int64::PACK) }
let(:bson) { [ Integer::MAX_64BIT - 1 ].pack(PackDirectives::INT64) }

it_behaves_like "a serializable bson element"
end
Expand Down
Loading
Loading