File tree Expand file tree Collapse file tree 5 files changed +35
-6
lines changed
Expand file tree Collapse file tree 5 files changed +35
-6
lines changed Original file line number Diff line number Diff line change 1+ ## 0.0.2
2+
3+ - Support Array
4+
5+ ## 0.0.1
6+
7+ Initial release
8+
Original file line number Diff line number Diff line change 11PATH
22 remote: .
33 specs:
4- gmsc (0.0.1 )
4+ gmsc (0.0.2 )
55
66GEM
77 remote: https://rubygems.org/
Original file line number Diff line number Diff line change 33
44module 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
Original file line number Diff line number Diff line change 11module GMSC
2- VERSION = "0.0.1 "
2+ VERSION = "0.0.2 "
33end
Original file line number Diff line number Diff line change 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
2748end
You can’t perform that action at this time.
0 commit comments