Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit d76b880

Browse files
authoredMay 8, 2025··
RUBY-3395 Add default value for padding (#347)
1 parent 7e05ab6 commit d76b880

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed
 

‎lib/bson/binary.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ def self.extract_args_for_vector(vector, dtype, padding)
455455
# Validate the arguments for a binary vector.
456456
# @param [ Array ] data The vector data.
457457
# @param [ ::Symbol ] dtype The vector data type.
458-
# @param [ Integer | nil ] padding The padding. Must be 0 if vector is a BSON::Vector.
458+
# @param [ Integer ] padding The padding. Must be 0 if vector is a BSON::Vector.
459459
# @raise [ ArgumentError ] If the arguments are invalid.
460460
def self.validate_args_for_vector!(data, dtype, padding)
461461
raise ArgumentError, "Unknown dtype #{dtype}" unless VECTOR_DATA_TYPES.key?(dtype)

‎lib/bson/vector.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def data
3535
# @param [ Integer ] padding The number of bits in the final byte that are to
3636
# be ignored when a vector element's size is less than a byte
3737
# and the length of the vector is not a multiple of 8.
38-
def initialize(data, dtype, padding)
38+
def initialize(data, dtype, padding = 0)
3939
@dtype = dtype
4040
@padding = padding
4141
super(data.dup)

‎spec/bson/vector_spec.rb

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# frozen_string_literal: true
2+
3+
# Copyright (C) 2025-present MongoDB Inc.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
require 'spec_helper'
18+
19+
describe BSON::Vector do
20+
it 'behaves like an Array' do
21+
expect(described_class.new([ 1, 2, 3 ], :int8)).to be_a(Array)
22+
end
23+
24+
describe '#initialize' do
25+
context 'when padding is not provided' do
26+
let(:vector) { described_class.new([ 1, 2, 3 ], :int8) }
27+
28+
it 'sets the padding to 0' do
29+
expect(vector.padding).to eq(0)
30+
end
31+
end
32+
end
33+
end

0 commit comments

Comments
 (0)
Please sign in to comment.