diff --git a/contrib/ruby/lib/trilogy.rb b/contrib/ruby/lib/trilogy.rb index bde8a033..cee8b673 100644 --- a/contrib/ruby/lib/trilogy.rb +++ b/contrib/ruby/lib/trilogy.rb @@ -7,7 +7,18 @@ require "trilogy/encoding" class Trilogy + VALID_OPTIONS = %i[ + host port path database username password encoding + ssl ssl_mode ssl_cipher ssl_ca ssl_capath ssl_key ssl_cert + tls_min_version tls_max_version tls_ciphersuites + read_timeout write_timeout connect_timeout + multi_statement + ].freeze + def initialize(options = {}) + invalid_keys = options.keys - VALID_OPTIONS + $stderr.puts "[WARNING] Unknown Trilogy options: #{invalid_keys.map(&:inspect).join(", ")}" unless invalid_keys.empty? + options[:port] = options[:port].to_i if options[:port] mysql_encoding = options[:encoding] || "utf8mb4" encoding = Trilogy::Encoding.find(mysql_encoding) diff --git a/contrib/ruby/test/client_test.rb b/contrib/ruby/test/client_test.rb index 269e2269..0874e382 100644 --- a/contrib/ruby/test/client_test.rb +++ b/contrib/ruby/test/client_test.rb @@ -71,6 +71,8 @@ def test_trilogy_connection_options tls_min_version: 3, } assert_equal expected_connection_options, client.connection_options + + assert_output('', /\[WARNING\] Unknown Trilogy options: :foo, "bar"/) { new_tcp_client({ foo: "", "bar" => "" }) } end def test_trilogy_ping