Skip to content

Commit 7d4f483

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

File tree

12 files changed

+200
-36
lines changed

12 files changed

+200
-36
lines changed

stdlib/cgi/0/core.rbs

Lines changed: 7 additions & 1 deletion
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

Lines changed: 36 additions & 4 deletions
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/date/0/date.rbs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@
7171
# * Other non-numeric: raises TypeError.
7272
#
7373
class Date
74+
type date_record = { mday: Integer, mon: Integer, year: Integer }
75+
76+
type datetime_with_timezone_record = { wday: Integer, mday: Integer, mon: Integer, year: Integer, hour: Integer, min: Integer, sec: Integer, zone: String, offset: Integer}
77+
7478
# <!--
7579
# rdoc-file=ext/date/date_core.c
7680
# - Date.new(year = -4712, month = 1, mday = 1, start = Date::ITALY) -> date
@@ -112,7 +116,7 @@ class Date
112116
#
113117
# Related: Date.httpdate (returns a Date object).
114118
#
115-
def self._httpdate: (String str) -> Hash[Symbol, Integer]
119+
def self._httpdate: (String str, ?limit: Integer) -> datetime_with_timezone_record
116120

117121
# <!--
118122
# rdoc-file=ext/date/date_core.c
@@ -130,7 +134,7 @@ class Date
130134
#
131135
# Related: Date.iso8601 (returns a Date object).
132136
#
133-
def self._iso8601: (String str) -> Hash[Symbol, Integer]
137+
def self._iso8601: (String str, ?limit: Integer) -> date_record
134138

135139
# <!--
136140
# rdoc-file=ext/date/date_core.c
@@ -147,7 +151,7 @@ class Date
147151
#
148152
# Related: Date.jisx0301 (returns a Date object).
149153
#
150-
def self._jisx0301: (String str) -> Hash[Symbol, Integer]
154+
def self._jisx0301: (String str, ?limit: Integer) -> date_record
151155

152156
# <!--
153157
# rdoc-file=ext/date/date_core.c
@@ -192,7 +196,7 @@ class Date
192196
#
193197
# Related: Date.rfc2822 (returns a Date object).
194198
#
195-
def self._rfc2822: (String str) -> Hash[Symbol, Integer | String]
199+
def self._rfc2822: (String str, ?limit: Integer) -> datetime_with_timezone_record
196200

197201
# <!--
198202
# rdoc-file=ext/date/date_core.c
@@ -210,7 +214,7 @@ class Date
210214
#
211215
# Related: Date.rfc3339 (returns a Date object).
212216
#
213-
def self._rfc3339: (String str) -> Hash[Symbol, Integer | String]
217+
def self._rfc3339: (String str, ?limit: Integer) -> datetime_with_timezone_record
214218

215219
# <!--
216220
# rdoc-file=ext/date/date_core.c
@@ -228,7 +232,7 @@ class Date
228232
#
229233
# Related: Date.rfc2822 (returns a Date object).
230234
#
231-
def self._rfc822: (String str) -> Hash[Symbol, Integer | String]
235+
def self._rfc822: (String str, ?limit: Integer) -> datetime_with_timezone_record
232236

233237
# <!--
234238
# rdoc-file=ext/date/date_core.c

stdlib/json/0/json.rbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ interface _JsonRead
1818
def read: () -> string
1919
end
2020

21-
type json_options = Hash[Symbol, untyped]
21+
type json_options = { ?max_nesting: bool, ?allow_nan: bool, ?script_safe: bool }
2222

2323
# <!-- rdoc-file=ext/json/lib/json/common.rb -->
2424
# The base exception for JSON errors.

stdlib/net-http/0/net-http.rbs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -913,6 +913,27 @@ module Net
913913
#
914914
def self.https_default_port: () -> Integer
915915

916+
type start_options = {
917+
?ca_file: String,
918+
?ca_path: String,
919+
?cert: OpenSSL::X509::Certificate,
920+
?cert_store: X509::Store,
921+
?ciphers: Array[String],
922+
?close_on_empty_response: bool,
923+
?ipaddr: String,
924+
?keep_alive_timeout: Numeric,
925+
?key: OpenSSL::PKey::PKey,
926+
?open_timeout: Numeric,
927+
?read_timeout: Numeric,
928+
?ssl_timeout: Numeric,
929+
?ssl_version: OpenSSL::SSL::tls_version,
930+
?use_ssl: bool,
931+
?verify_callback: ^(bool preverify_ok, StoreContext store_ctx) -> boolish,
932+
?verify_depth: Integer,
933+
?verify_mode: OpenSSL::SSL::verify_mode,
934+
?write_timeout: Numeric
935+
}
936+
916937
# <!--
917938
# rdoc-file=lib/net/http.rb
918939
# - HTTP.start(address, port = nil, p_addr = :ENV, p_port = nil, p_user = nil, p_pass = nil, opts) -> http
@@ -1003,8 +1024,8 @@ module Net
10031024
# Note: If `port` is `nil` and `opts[:use_ssl]` is a truthy value, the value
10041025
# passed to `new` is Net::HTTP.https_default_port, not `port`.
10051026
#
1006-
def self.start: (String address, ?Integer? port, ?String | :ENV | nil p_addr, ?Integer? p_port, ?String? p_user, ?String? p_pass, ?Hash[Symbol, untyped]? opt) -> Net::HTTP
1007-
| [T] (String address, ?Integer? port, ?String | :ENV | nil p_addr, ?Integer? p_port, ?String? p_user, ?String? p_pass, ?Hash[Symbol, untyped]? opt) { (Net::HTTP) -> T } -> T
1027+
def self.start: (String address, ?Integer? port, ?String | :ENV | nil p_addr, ?Integer? p_port, ?String? p_user, ?String? p_pass, ?start_options opt) -> Net::HTTP
1028+
| [T] (String address, ?Integer? port, ?String | :ENV | nil p_addr, ?Integer? p_port, ?String? p_user, ?String? p_pass, ?start_options opt) { (Net::HTTP) -> T } -> T
10081029

10091030
# <!--
10101031
# rdoc-file=lib/net/http.rb

stdlib/openssl/0/openssl.rbs

Lines changed: 60 additions & 7 deletions
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
@@ -8414,7 +8454,20 @@ module OpenSSL
84148454
# : Number of sessions proposed by clients that were found in the cache but
84158455
# had expired due to timeouts
84168456
#
8417-
def session_cache_stats: () -> Hash[Symbol, Integer]
8457+
def session_cache_stats: () -> {
8458+
accept: Integer,
8459+
accept_good: Integer,
8460+
accept_renegotiate: Integer,
8461+
cache_full: Integer,
8462+
cache_hits: Integer,
8463+
cache_misses: Integer,
8464+
cache_num: Integer,
8465+
cb_hits: Integer,
8466+
connect: Integer,
8467+
connect_good: Integer,
8468+
connect_renegotiate: Integer,
8469+
timeouts: Integer
8470+
}
84188471

84198472
# <!-- rdoc-file=ext/openssl/ossl_ssl.c -->
84208473
# A callback invoked on a server when a session is proposed by the client but
@@ -8504,7 +8557,7 @@ module OpenSSL
85048557
# If the verify_mode is not VERIFY_NONE and ca_file, ca_path and cert_store are
85058558
# not set then the system default certificate store is used.
85068559
#
8507-
def set_params: (?untyped params) -> untyped
8560+
def set_params: (context_params params) -> untyped
85088561

85098562
# <!--
85108563
# rdoc-file=ext/openssl/ossl_ssl.c
@@ -8689,7 +8742,7 @@ module OpenSSL
86898742

86908743
DEFAULT_CERT_STORE: X509::Store
86918744

8692-
DEFAULT_PARAMS: Hash[Symbol, untyped]
8745+
DEFAULT_PARAMS: context_params
86938746

86948747
DEFAULT_TMP_DH_CALLBACK: Proc
86958748

stdlib/resolv/0/resolv.rbs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,14 @@ class Resolv::DNS
335335

336336
private
337337

338+
type dns_config_options = {
339+
nameserver: String | Array[String],
340+
search: String | Array[String],
341+
ndots: Integer,
342+
?nameserver_port: Array[[String, Integer]],
343+
?raise_timeout_errors: bool
344+
}
345+
338346
# <!--
339347
# rdoc-file=lib/resolv.rb
340348
# - new(config_info=nil)
@@ -371,7 +379,7 @@ class Resolv::DNS
371379
# :search => ['ruby-lang.org'],
372380
# :ndots => 1)
373381
#
374-
def initialize: (?String | Hash[Symbol, untyped] config_info) -> untyped
382+
def initialize: (?String | dns_config_options config_info) -> untyped
375383

376384
def use_ipv6?: () -> untyped
377385
end
@@ -391,9 +399,9 @@ Resolv::DNS::RequestIDMutex: Thread::Mutex
391399
Resolv::DNS::UDPSize: Integer
392400

393401
class Resolv::DNS::Config
394-
def self.default_config_hash: (?String filename) -> Hash[Symbol, untyped]
402+
def self.default_config_hash: (?String filename) -> dns_config_options
395403

396-
def self.parse_resolv_conf: (String filename) -> Hash[Symbol, untyped]
404+
def self.parse_resolv_conf: (String filename) -> dns_config_options
397405

398406
public
399407

@@ -413,7 +421,7 @@ class Resolv::DNS::Config
413421

414422
private
415423

416-
def initialize: (?String | Hash[Symbol, untyped] config_info) -> untyped
424+
def initialize: (?String | dns_config_options config_info) -> untyped
417425
end
418426

419427
Resolv::DNS::Config::InitialTimeout: Integer
@@ -1859,7 +1867,7 @@ class Resolv::MDNS < Resolv::DNS
18591867
# Hash
18601868
# : Must contain :nameserver or :nameserver_port like Resolv::DNS#initialize.
18611869
#
1862-
def initialize: (?String | Hash[Symbol, untyped] config_info) -> untyped
1870+
def initialize: (?String | DNS::dns_config_options config_info) -> untyped
18631871
end
18641872

18651873
# <!-- rdoc-file=lib/resolv.rb -->

0 commit comments

Comments
 (0)