Skip to content

Commit ed13d51

Browse files
authored
Merge pull request #8 from wantedly/qnighy/array
Support Array
2 parents 3be23fd + 5b76569 commit ed13d51

File tree

5 files changed

+35
-6
lines changed

5 files changed

+35
-6
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
## 0.0.2
2+
3+
- Support Array
4+
5+
## 0.0.1
6+
7+
Initial release
8+

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
gmsc (0.0.1)
4+
gmsc (0.0.2)
55

66
GEM
77
remote: https://rubygems.org/

lib/gmsc.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@
33

44
module GMSC
55
class << self
6-
# @param [{ String => String }] metadata
7-
# @return [{ String => String }]
6+
# @param [{ String => String, Array<String> }] metadata
7+
# @return [{ String => String, Array<String> }]
88
def safe_convert(metadata)
99
h = {}
1010
metadata.each do |k, v|
1111
if k.match?(/-bin$/)
1212
# If the value is binary, encode with Base64
13-
h[k] = Base64.strict_encode64(v)
13+
h[k] = v.is_a?(Array) ? v.map { |e| Base64.strict_encode64(e) } : Base64.strict_encode64(v)
1414
else
15-
h[k] = v.encode(Encoding::UTF_8)
15+
h[k] = v.is_a?(Array) ? v.map { |e| e.encode(Encoding::UTF_8) } : v.encode(Encoding::UTF_8)
1616
end
1717
end
1818
h

lib/gmsc/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module GMSC
2-
VERSION = "0.0.1"
2+
VERSION = "0.0.2"
33
end

spec/gmsc_spec.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,26 @@
2323
})
2424
expect(hash.to_json).to eq("{\"user-agent\":\"grpc-node/1.19.0 grpc-c/7.0.0 (linux; chttp2; gold)\",\"binary-data-bin\":\"AAEC6g==\"}")
2525
end
26+
27+
context "when metadata contains arrays" do
28+
let(:metadata) {
29+
{
30+
"foo" => ["foo", "bar"],
31+
"binfoo-bin" => ["\x00\x01\x02\xEA".b, "\x01\x02\x03\xFF".b],
32+
}
33+
}
34+
35+
it "converts array" do
36+
hash = GMSC.safe_convert(metadata)
37+
expect(hash).to(
38+
eq(
39+
{
40+
"foo" => ["foo", "bar"],
41+
"binfoo-bin" => ["AAEC6g==", "AQID/w=="],
42+
}
43+
)
44+
)
45+
end
46+
end
2647
end
2748
end

0 commit comments

Comments
 (0)