Skip to content

Commit

Permalink
use optional record keys for several API options
Browse files Browse the repository at this point in the history
  • Loading branch information
HoneyryderChuck committed Jun 20, 2024
1 parent 0e66e1e commit eaf2497
Show file tree
Hide file tree
Showing 8 changed files with 138 additions and 20 deletions.
8 changes: 7 additions & 1 deletion stdlib/cgi/0/core.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,12 @@ class CGI

extend CGI::Util

type options_hash = {
?accept_charset: String,
?tag_maker: String,
?max_multipart_length: Integer | ^() -> Integer
}

# <!--
# rdoc-file=lib/cgi/core.rb
# - CGI.new(tag_maker) { block }
Expand Down Expand Up @@ -352,7 +358,7 @@ class CGI
# varies according to the REQUEST_METHOD.
#
def initialize: (?String tag_maker) ?{ (String name, String value) -> void } -> void
| (Hash[Symbol, untyped] options_hash) ?{ (String name, String value) -> void } -> void
| (options_hash options_hash) ?{ (String name, String value) -> void } -> void

# <!--
# rdoc-file=lib/cgi/core.rb
Expand Down
40 changes: 36 additions & 4 deletions stdlib/csv/0/csv.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -1635,6 +1635,38 @@ class CSV < Object
include Enumerable[untyped]
extend Forwardable

type parsing_options = {
?row_sep: String | :auto,
?col_sep: String,
?quote_char: String,
?field_size_limit: Integer,
?converters: Symbol,
?unconverted_fields: bool,
?headers: bool | Symbol | String | Array[String],
?return_headers: bool,
?header_converters: Symbol,
?skip_blanks: bool,
?skip_lines: Regexp | String | nil,
?strip: bool,
?liberal_parsing: bool,
?nil_value: untyped,
?empty_value: untyped
}

type write_converter = ^(String field) -> String

type generating_options: {
?row_sep: String | :auto,
?col_sep: String,
?quote_char: String,
?write_headers: bool,
?force_quotes: bool,
?quote_empty: bool:
?write_converters: write_converter | Array[write_converter],
?write_nil_value: string,
?write_empty_value: string
}

# <!--
# rdoc-file=lib/csv.rb
# - foreach(path_or_io, mode='r', **options) {|row| ... )
Expand Down Expand Up @@ -1773,7 +1805,7 @@ class CSV < Object
# # Raises ArgumentError (Cannot parse nil as CSV):
# CSV.new(nil)
#
def initialize: (?String | IO | StringIO io, ?::Hash[Symbol, untyped] options) -> void
def initialize: (?String | IO | StringIO io, ?(parsing_options | generating_options) options) -> void

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

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

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

# <!--
# rdoc-file=lib/csv.rb
Expand Down
50 changes: 45 additions & 5 deletions stdlib/openssl/0/openssl.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -7856,6 +7856,46 @@ module OpenSSL
# be frozen afterward.
#
class SSLContext
type context_params = {
?alpn_protocols=: Array[String]?,
?alpn_select_cb=: (^(Array[String]) -> String?)?,
?keylog_cb=,
?ssl_timeout=: timeout?,
?ciphers=: Array[String]?,
?ciphersuites=,
?tmp_dh=: (^(Session, Integer, Integer) -> PKey::DH)?,
?tmp_dh_callback=(^(Session, Integer, Integer) -> PKey::DH)?,
?ecdh_curves=: String?,
?security_level=: Integer?,
?key=: PKey::PKey?,
?session_cache_mode=: Integer?,
?session_cache_size=: Integer?,
?timeout=: Integer?,
?options=: Integer?,
?servername_cb=: (^(SSLSocket, String) -> SSLContext?)?,
?min_version=: tls_version?,
?max_version=: tls_version?,
?cert=: X509::Certificate?,
?client_ca=: Array[X509::Certificate] | X509::Certificate | nil,
?ca_file=: String?,
?ca_path=: String?,
?verify_mode=: verify_mode?,
?verify_depth=: Integer?,
?verify_callback=: (^(bool preverify_ok, StoreContext store_ctx) -> boolish)?,
?ssl_version=: tls_version?,
?verify_hostname=: boolish?,
?cert_store=: X509::Store?,
?extra_chain_cert=: Array[X509::Certificate]?,
?client_cert_cb=: (^(Session) -> [ X509::Certificate, PKey::PKey ]??,
?session_id_context=: Integer?,
?session_get_cb=: (^(SSLSocket, Integer) -> Session?)?,
?session_new_cb=: (^(SSLSocket) -> untyped)?,
?session_remove_cb=: (^(SSLContext, Session) -> void)?,
?renegotiation_cb=: (^(SSLSocket) -> void)?,
?npn_protocols=: Array[String]?,
?npn_select_cb=: (^(Array[String]) -> String?)?
}

public

# <!--
Expand Down Expand Up @@ -8183,7 +8223,7 @@ module OpenSSL
#
# ctx.npn_protocols = ["http/1.1", "spdy/2"]
#
def npn_protocols: () -> untyped
def npn_protocols: () -> Array[String]?

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

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

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

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

# <!--
# rdoc-file=ext/openssl/ossl_ssl.c
Expand Down
6 changes: 5 additions & 1 deletion stdlib/uri/0/file.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ module URI
# The "file" URI is defined by RFC8089.
#
class File < Generic
type build_opts = {
?host: String?,
?path: String?
}
# <!-- rdoc-file=lib/uri/file.rb -->
# A Default port of nil for URI::File.
#
Expand Down Expand Up @@ -47,7 +51,7 @@ module URI
# uri3.to_s # => "file:///path/my%20file.txt"
#
def self.build: (Array[String] args) -> URI::File
| ({ host: String?, path: String? }) -> URI::File
| (build_opts args) -> URI::File

# <!--
# rdoc-file=lib/uri/file.rb
Expand Down
20 changes: 16 additions & 4 deletions stdlib/uri/0/generic.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,18 @@ module URI
class Generic
include URI

type build_opts = {
?scheme: String?,
?userinfo: String?,
?host: String?,
?port: Integer?,
?registry: String?,
?path: String?,
?opaque: String?,
?query: String?,
?fragment: String?
}

# <!-- rdoc-file=lib/uri/generic.rb -->
# A Default port of nil for URI::Generic.
#
Expand Down Expand Up @@ -153,8 +165,8 @@ module URI
# URI::Generic::build. But, if exception URI::InvalidComponentError is raised,
# then it does URI::Escape.escape all URI components and tries again.
#
def self.build2: (Array[nil | String | Integer]) -> URI::Generic
| ({ scheme: String?, userinfo: String?, host: String?, port: Integer?, registry: String?, path: String?, opaque: String?, query: String?, fragment: String? }) -> instance
def self.build2: (Array[nil | String | Integer] args) -> URI::Generic
| (build_opts args) -> instance

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

# <!--
# rdoc-file=lib/uri/generic.rb
Expand Down
11 changes: 10 additions & 1 deletion stdlib/uri/0/http.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ module URI
# <URL:http://support.microsoft.com/kb/834489>.
#
class HTTP < Generic

type build_opts = {
?userinfo: String?,
?host: String?,
?port: Integer?,
?path: String?,
?query: String?,
?fragment: String?
}
# <!-- rdoc-file=lib/uri/http.rb -->
# A Default port of 80 for URI::HTTP.
#
Expand Down Expand Up @@ -46,7 +55,7 @@ module URI
# URIs as per RFC 1738.
#
def self.build: (Array[String | Integer] args) -> instance
| ({ userinfo: String?, host: String?, port: Integer?, path: String?, query: String?, fragment: String? }) -> instance
| (build_opts args) -> instance

# <!--
# rdoc-file=lib/uri/http.rb
Expand Down
12 changes: 11 additions & 1 deletion stdlib/uri/0/ldap.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ module URI
# LDAP URI SCHEMA (described in RFC2255).
#
class LDAP < Generic
type build_opts = {
?host: String?,
?port: Integer?,
?dn: String?,
?attributes: String?,
?scope: String?,
?filter: String?,
?extensions: String?
}

# <!-- rdoc-file=lib/uri/ldap.rb -->
# A Default port of 389 for URI::LDAP.
#
Expand Down Expand Up @@ -50,7 +60,7 @@ module URI
# "/dc=example;dc=com", "query", nil, nil, nil])
#
def self.build: (Array[nil | String | Integer] args) -> URI::LDAP
| ({ host: String?, port: Integer?, dn: String?, attributes: String?, scope: String?, filter: String?, extensions: String? }) -> URI::LDAP
| (build_opts args) -> URI::LDAP

# <!--
# rdoc-file=lib/uri/ldap.rb
Expand Down
11 changes: 8 additions & 3 deletions stdlib/uri/0/mailto.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ module URI
# RFC6068, the mailto URL scheme.
#
class MailTo < Generic
type build_opts: {
?headers:, Array[Array[String]]?
?to: String?
}

EMAIL_REGEXP: Regexp

# <!--
Expand Down Expand Up @@ -36,9 +41,9 @@ module URI
# m3 = URI::MailTo.build({:to => 'listman@example.com', :headers => [['subject', 'subscribe']]})
# m3.to_s # => "mailto:listman@example.com?subject=subscribe"
#
def self.build: (Array[String]) -> instance
| ([String, Array[Array[String]]]) -> instance
| (Hash[Symbol, String | Array[Array[String]]]) -> instance
def self.build: (Array[String] args) -> instance
| ([String, Array[Array[String]]] args) -> instance
| (build_opts args) -> instance

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

0 comments on commit eaf2497

Please sign in to comment.