Skip to content

Commit eaf2497

Browse files
use optional record keys for several API options
1 parent 0e66e1e commit eaf2497

File tree

8 files changed

+138
-20
lines changed

8 files changed

+138
-20
lines changed

stdlib/cgi/0/core.rbs

+7-1
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,12 @@ class CGI
273273

274274
extend CGI::Util
275275

276+
type options_hash = {
277+
?accept_charset: String,
278+
?tag_maker: String,
279+
?max_multipart_length: Integer | ^() -> Integer
280+
}
281+
276282
# <!--
277283
# rdoc-file=lib/cgi/core.rb
278284
# - CGI.new(tag_maker) { block }
@@ -352,7 +358,7 @@ class CGI
352358
# varies according to the REQUEST_METHOD.
353359
#
354360
def initialize: (?String tag_maker) ?{ (String name, String value) -> void } -> void
355-
| (Hash[Symbol, untyped] options_hash) ?{ (String name, String value) -> void } -> void
361+
| (options_hash options_hash) ?{ (String name, String value) -> void } -> void
356362

357363
# <!--
358364
# rdoc-file=lib/cgi/core.rb

stdlib/csv/0/csv.rbs

+36-4
Original file line numberDiff line numberDiff line change
@@ -1635,6 +1635,38 @@ class CSV < Object
16351635
include Enumerable[untyped]
16361636
extend Forwardable
16371637

1638+
type parsing_options = {
1639+
?row_sep: String | :auto,
1640+
?col_sep: String,
1641+
?quote_char: String,
1642+
?field_size_limit: Integer,
1643+
?converters: Symbol,
1644+
?unconverted_fields: bool,
1645+
?headers: bool | Symbol | String | Array[String],
1646+
?return_headers: bool,
1647+
?header_converters: Symbol,
1648+
?skip_blanks: bool,
1649+
?skip_lines: Regexp | String | nil,
1650+
?strip: bool,
1651+
?liberal_parsing: bool,
1652+
?nil_value: untyped,
1653+
?empty_value: untyped
1654+
}
1655+
1656+
type write_converter = ^(String field) -> String
1657+
1658+
type generating_options: {
1659+
?row_sep: String | :auto,
1660+
?col_sep: String,
1661+
?quote_char: String,
1662+
?write_headers: bool,
1663+
?force_quotes: bool,
1664+
?quote_empty: bool:
1665+
?write_converters: write_converter | Array[write_converter],
1666+
?write_nil_value: string,
1667+
?write_empty_value: string
1668+
}
1669+
16381670
# <!--
16391671
# rdoc-file=lib/csv.rb
16401672
# - foreach(path_or_io, mode='r', **options) {|row| ... )
@@ -1773,7 +1805,7 @@ class CSV < Object
17731805
# # Raises ArgumentError (Cannot parse nil as CSV):
17741806
# CSV.new(nil)
17751807
#
1776-
def initialize: (?String | IO | StringIO io, ?::Hash[Symbol, untyped] options) -> void
1808+
def initialize: (?String | IO | StringIO io, ?(parsing_options | generating_options) options) -> void
17771809

17781810
# <!--
17791811
# rdoc-file=lib/csv.rb
@@ -1895,7 +1927,7 @@ class CSV < Object
18951927
# # Raises NoMethodError (undefined method `close' for :foo:Symbol)
18961928
# CSV.parse(:foo)
18971929
#
1898-
def self.parse: (String str, ?::Hash[Symbol, untyped] options) ?{ (::Array[String?] arg0) -> void } -> ::Array[::Array[String?]]?
1930+
def self.parse: (String str, ?(parsing_options | generating_options) options) ?{ (::Array[String?] arg0) -> void } -> ::Array[::Array[String?]]?
18991931

19001932
# <!--
19011933
# rdoc-file=lib/csv.rb
@@ -1965,7 +1997,7 @@ class CSV < Object
19651997
# # Raises ArgumentError (Cannot parse nil as CSV):
19661998
# CSV.parse_line(nil)
19671999
#
1968-
def self.parse_line: (String str, ?::Hash[Symbol, untyped] options) -> ::Array[String?]?
2000+
def self.parse_line: (String str, ?(parsing_options | generating_options) options) -> ::Array[String?]?
19692001

19702002
# <!--
19712003
# rdoc-file=lib/csv.rb
@@ -2031,7 +2063,7 @@ class CSV < Object
20312063
# File.write(path, string)
20322064
# CSV.read(path, headers: true) # => #<CSV::Table mode:col_or_row row_count:4>
20332065
#
2034-
def self.read: (String path, ?::Hash[Symbol, untyped] options) -> ::Array[::Array[String?]]
2066+
def self.read: (String path, ?(parsing_options | generating_options) options) -> ::Array[::Array[String?]]
20352067

20362068
# <!--
20372069
# rdoc-file=lib/csv.rb

stdlib/openssl/0/openssl.rbs

+45-5
Original file line numberDiff line numberDiff line change
@@ -7856,6 +7856,46 @@ module OpenSSL
78567856
# be frozen afterward.
78577857
#
78587858
class SSLContext
7859+
type context_params = {
7860+
?alpn_protocols=: Array[String]?,
7861+
?alpn_select_cb=: (^(Array[String]) -> String?)?,
7862+
?keylog_cb=,
7863+
?ssl_timeout=: timeout?,
7864+
?ciphers=: Array[String]?,
7865+
?ciphersuites=,
7866+
?tmp_dh=: (^(Session, Integer, Integer) -> PKey::DH)?,
7867+
?tmp_dh_callback=(^(Session, Integer, Integer) -> PKey::DH)?,
7868+
?ecdh_curves=: String?,
7869+
?security_level=: Integer?,
7870+
?key=: PKey::PKey?,
7871+
?session_cache_mode=: Integer?,
7872+
?session_cache_size=: Integer?,
7873+
?timeout=: Integer?,
7874+
?options=: Integer?,
7875+
?servername_cb=: (^(SSLSocket, String) -> SSLContext?)?,
7876+
?min_version=: tls_version?,
7877+
?max_version=: tls_version?,
7878+
?cert=: X509::Certificate?,
7879+
?client_ca=: Array[X509::Certificate] | X509::Certificate | nil,
7880+
?ca_file=: String?,
7881+
?ca_path=: String?,
7882+
?verify_mode=: verify_mode?,
7883+
?verify_depth=: Integer?,
7884+
?verify_callback=: (^(bool preverify_ok, StoreContext store_ctx) -> boolish)?,
7885+
?ssl_version=: tls_version?,
7886+
?verify_hostname=: boolish?,
7887+
?cert_store=: X509::Store?,
7888+
?extra_chain_cert=: Array[X509::Certificate]?,
7889+
?client_cert_cb=: (^(Session) -> [ X509::Certificate, PKey::PKey ]??,
7890+
?session_id_context=: Integer?,
7891+
?session_get_cb=: (^(SSLSocket, Integer) -> Session?)?,
7892+
?session_new_cb=: (^(SSLSocket) -> untyped)?,
7893+
?session_remove_cb=: (^(SSLContext, Session) -> void)?,
7894+
?renegotiation_cb=: (^(SSLSocket) -> void)?,
7895+
?npn_protocols=: Array[String]?,
7896+
?npn_select_cb=: (^(Array[String]) -> String?)?
7897+
}
7898+
78597899
public
78607900

78617901
# <!--
@@ -8183,7 +8223,7 @@ module OpenSSL
81838223
#
81848224
# ctx.npn_protocols = ["http/1.1", "spdy/2"]
81858225
#
8186-
def npn_protocols: () -> untyped
8226+
def npn_protocols: () -> Array[String]?
81878227

81888228
# <!-- rdoc-file=ext/openssl/ossl_ssl.c -->
81898229
# An Enumerable of Strings. Each String represents a protocol to be advertised
@@ -8195,7 +8235,7 @@ module OpenSSL
81958235
#
81968236
# ctx.npn_protocols = ["http/1.1", "spdy/2"]
81978237
#
8198-
def npn_protocols=: (untyped) -> untyped
8238+
def npn_protocols=: (Array[String]? protos) -> Array[String]
81998239

82008240
# <!-- rdoc-file=ext/openssl/ossl_ssl.c -->
82018241
# A callback invoked on the client side when the client needs to select a
@@ -8213,7 +8253,7 @@ module OpenSSL
82138253
# protocols.first
82148254
# end
82158255
#
8216-
def npn_select_cb: () -> untyped
8256+
def npn_select_cb: () -> (^(Array[String]) -> String? | nil)
82178257

82188258
# <!-- rdoc-file=ext/openssl/ossl_ssl.c -->
82198259
# A callback invoked on the client side when the client needs to select a
@@ -8231,7 +8271,7 @@ module OpenSSL
82318271
# protocols.first
82328272
# end
82338273
#
8234-
def npn_select_cb=: (untyped) -> untyped
8274+
def npn_select_cb=: (^(Array[String]) -> String? alpn_select_callback) -> void
82358275

82368276
# <!--
82378277
# rdoc-file=ext/openssl/ossl_ssl.c
@@ -8504,7 +8544,7 @@ module OpenSSL
85048544
# If the verify_mode is not VERIFY_NONE and ca_file, ca_path and cert_store are
85058545
# not set then the system default certificate store is used.
85068546
#
8507-
def set_params: (?untyped params) -> untyped
8547+
def set_params: (context_params params) -> untyped
85088548

85098549
# <!--
85108550
# rdoc-file=ext/openssl/ossl_ssl.c

stdlib/uri/0/file.rbs

+5-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ module URI
44
# The "file" URI is defined by RFC8089.
55
#
66
class File < Generic
7+
type build_opts = {
8+
?host: String?,
9+
?path: String?
10+
}
711
# <!-- rdoc-file=lib/uri/file.rb -->
812
# A Default port of nil for URI::File.
913
#
@@ -47,7 +51,7 @@ module URI
4751
# uri3.to_s # => "file:///path/my%20file.txt"
4852
#
4953
def self.build: (Array[String] args) -> URI::File
50-
| ({ host: String?, path: String? }) -> URI::File
54+
| (build_opts args) -> URI::File
5155

5256
# <!--
5357
# rdoc-file=lib/uri/file.rb

stdlib/uri/0/generic.rbs

+16-4
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,18 @@ module URI
101101
class Generic
102102
include URI
103103

104+
type build_opts = {
105+
?scheme: String?,
106+
?userinfo: String?,
107+
?host: String?,
108+
?port: Integer?,
109+
?registry: String?,
110+
?path: String?,
111+
?opaque: String?,
112+
?query: String?,
113+
?fragment: String?
114+
}
115+
104116
# <!-- rdoc-file=lib/uri/generic.rb -->
105117
# A Default port of nil for URI::Generic.
106118
#
@@ -153,8 +165,8 @@ module URI
153165
# URI::Generic::build. But, if exception URI::InvalidComponentError is raised,
154166
# then it does URI::Escape.escape all URI components and tries again.
155167
#
156-
def self.build2: (Array[nil | String | Integer]) -> URI::Generic
157-
| ({ scheme: String?, userinfo: String?, host: String?, port: Integer?, registry: String?, path: String?, opaque: String?, query: String?, fragment: String? }) -> instance
168+
def self.build2: (Array[nil | String | Integer] args) -> URI::Generic
169+
| (build_opts args) -> instance
158170

159171
# <!--
160172
# rdoc-file=lib/uri/generic.rb
@@ -171,8 +183,8 @@ module URI
171183
# query, and fragment. You can provide arguments either by an Array or a Hash.
172184
# See ::new for hash keys to use or for order of array items.
173185
#
174-
def self.build: (Array[nil | String | Integer]) -> URI::Generic
175-
| ({ scheme: String?, userinfo: String?, host: String?, port: Integer?, registry: String?, path: String?, opaque: String?, query: String?, fragment: String? }) -> instance
186+
def self.build: (Array[nil | String | Integer] args) -> URI::Generic
187+
| (build_opts args) -> instance
176188

177189
# <!--
178190
# rdoc-file=lib/uri/generic.rb

stdlib/uri/0/http.rbs

+10-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@ module URI
99
# <URL:http://support.microsoft.com/kb/834489>.
1010
#
1111
class HTTP < Generic
12+
13+
type build_opts = {
14+
?userinfo: String?,
15+
?host: String?,
16+
?port: Integer?,
17+
?path: String?,
18+
?query: String?,
19+
?fragment: String?
20+
}
1221
# <!-- rdoc-file=lib/uri/http.rb -->
1322
# A Default port of 80 for URI::HTTP.
1423
#
@@ -46,7 +55,7 @@ module URI
4655
# URIs as per RFC 1738.
4756
#
4857
def self.build: (Array[String | Integer] args) -> instance
49-
| ({ userinfo: String?, host: String?, port: Integer?, path: String?, query: String?, fragment: String? }) -> instance
58+
| (build_opts args) -> instance
5059

5160
# <!--
5261
# rdoc-file=lib/uri/http.rb

stdlib/uri/0/ldap.rbs

+11-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@ module URI
44
# LDAP URI SCHEMA (described in RFC2255).
55
#
66
class LDAP < Generic
7+
type build_opts = {
8+
?host: String?,
9+
?port: Integer?,
10+
?dn: String?,
11+
?attributes: String?,
12+
?scope: String?,
13+
?filter: String?,
14+
?extensions: String?
15+
}
16+
717
# <!-- rdoc-file=lib/uri/ldap.rb -->
818
# A Default port of 389 for URI::LDAP.
919
#
@@ -50,7 +60,7 @@ module URI
5060
# "/dc=example;dc=com", "query", nil, nil, nil])
5161
#
5262
def self.build: (Array[nil | String | Integer] args) -> URI::LDAP
53-
| ({ host: String?, port: Integer?, dn: String?, attributes: String?, scope: String?, filter: String?, extensions: String? }) -> URI::LDAP
63+
| (build_opts args) -> URI::LDAP
5464

5565
# <!--
5666
# rdoc-file=lib/uri/ldap.rb

stdlib/uri/0/mailto.rbs

+8-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ module URI
44
# RFC6068, the mailto URL scheme.
55
#
66
class MailTo < Generic
7+
type build_opts: {
8+
?headers:, Array[Array[String]]?
9+
?to: String?
10+
}
11+
712
EMAIL_REGEXP: Regexp
813

914
# <!--
@@ -36,9 +41,9 @@ module URI
3641
# m3 = URI::MailTo.build({:to => '[email protected]', :headers => [['subject', 'subscribe']]})
3742
# m3.to_s # => "mailto:[email protected]?subject=subscribe"
3843
#
39-
def self.build: (Array[String]) -> instance
40-
| ([String, Array[Array[String]]]) -> instance
41-
| (Hash[Symbol, String | Array[Array[String]]]) -> instance
44+
def self.build: (Array[String] args) -> instance
45+
| ([String, Array[Array[String]]] args) -> instance
46+
| (build_opts args) -> instance
4247

4348
# <!-- rdoc-file=lib/uri/mailto.rb -->
4449
# E-mail headers set by the URL, as an Array of Arrays.

0 commit comments

Comments
 (0)