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 21, 2024
1 parent 0e66e1e commit 7d4f483
Show file tree
Hide file tree
Showing 12 changed files with 200 additions and 36 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
16 changes: 10 additions & 6 deletions stdlib/date/0/date.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@
# * Other non-numeric: raises TypeError.
#
class Date
type date_record = { mday: Integer, mon: Integer, year: Integer }

type datetime_with_timezone_record = { wday: Integer, mday: Integer, mon: Integer, year: Integer, hour: Integer, min: Integer, sec: Integer, zone: String, offset: Integer}

# <!--
# rdoc-file=ext/date/date_core.c
# - Date.new(year = -4712, month = 1, mday = 1, start = Date::ITALY) -> date
Expand Down Expand Up @@ -112,7 +116,7 @@ class Date
#
# Related: Date.httpdate (returns a Date object).
#
def self._httpdate: (String str) -> Hash[Symbol, Integer]
def self._httpdate: (String str, ?limit: Integer) -> datetime_with_timezone_record

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

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

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

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

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

# <!--
# rdoc-file=ext/date/date_core.c
Expand Down
2 changes: 1 addition & 1 deletion stdlib/json/0/json.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ interface _JsonRead
def read: () -> string
end

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

# <!-- rdoc-file=ext/json/lib/json/common.rb -->
# The base exception for JSON errors.
Expand Down
25 changes: 23 additions & 2 deletions stdlib/net-http/0/net-http.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -913,6 +913,27 @@ module Net
#
def self.https_default_port: () -> Integer

type start_options = {
?ca_file: String,
?ca_path: String,
?cert: OpenSSL::X509::Certificate,
?cert_store: X509::Store,
?ciphers: Array[String],
?close_on_empty_response: bool,
?ipaddr: String,
?keep_alive_timeout: Numeric,
?key: OpenSSL::PKey::PKey,
?open_timeout: Numeric,
?read_timeout: Numeric,
?ssl_timeout: Numeric,
?ssl_version: OpenSSL::SSL::tls_version,
?use_ssl: bool,
?verify_callback: ^(bool preverify_ok, StoreContext store_ctx) -> boolish,
?verify_depth: Integer,
?verify_mode: OpenSSL::SSL::verify_mode,
?write_timeout: Numeric
}

# <!--
# rdoc-file=lib/net/http.rb
# - HTTP.start(address, port = nil, p_addr = :ENV, p_port = nil, p_user = nil, p_pass = nil, opts) -> http
Expand Down Expand Up @@ -1003,8 +1024,8 @@ module Net
# Note: If `port` is `nil` and `opts[:use_ssl]` is a truthy value, the value
# passed to `new` is Net::HTTP.https_default_port, not `port`.
#
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
| [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
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
| [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

# <!--
# rdoc-file=lib/net/http.rb
Expand Down
67 changes: 60 additions & 7 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 @@ -8414,7 +8454,20 @@ module OpenSSL
# : Number of sessions proposed by clients that were found in the cache but
# had expired due to timeouts
#
def session_cache_stats: () -> Hash[Symbol, Integer]
def session_cache_stats: () -> {
accept: Integer,
accept_good: Integer,
accept_renegotiate: Integer,
cache_full: Integer,
cache_hits: Integer,
cache_misses: Integer,
cache_num: Integer,
cb_hits: Integer,
connect: Integer,
connect_good: Integer,
connect_renegotiate: Integer,
timeouts: Integer
}

# <!-- rdoc-file=ext/openssl/ossl_ssl.c -->
# A callback invoked on a server when a session is proposed by the client but
Expand Down Expand Up @@ -8504,7 +8557,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 Expand Up @@ -8689,7 +8742,7 @@ module OpenSSL

DEFAULT_CERT_STORE: X509::Store

DEFAULT_PARAMS: Hash[Symbol, untyped]
DEFAULT_PARAMS: context_params

DEFAULT_TMP_DH_CALLBACK: Proc

Expand Down
18 changes: 13 additions & 5 deletions stdlib/resolv/0/resolv.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,14 @@ class Resolv::DNS

private

type dns_config_options = {
nameserver: String | Array[String],
search: String | Array[String],
ndots: Integer,
?nameserver_port: Array[[String, Integer]],
?raise_timeout_errors: bool
}

# <!--
# rdoc-file=lib/resolv.rb
# - new(config_info=nil)
Expand Down Expand Up @@ -371,7 +379,7 @@ class Resolv::DNS
# :search => ['ruby-lang.org'],
# :ndots => 1)
#
def initialize: (?String | Hash[Symbol, untyped] config_info) -> untyped
def initialize: (?String | dns_config_options config_info) -> untyped

def use_ipv6?: () -> untyped
end
Expand All @@ -391,9 +399,9 @@ Resolv::DNS::RequestIDMutex: Thread::Mutex
Resolv::DNS::UDPSize: Integer

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

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

public

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

private

def initialize: (?String | Hash[Symbol, untyped] config_info) -> untyped
def initialize: (?String | dns_config_options config_info) -> untyped
end

Resolv::DNS::Config::InitialTimeout: Integer
Expand Down Expand Up @@ -1859,7 +1867,7 @@ class Resolv::MDNS < Resolv::DNS
# Hash
# : Must contain :nameserver or :nameserver_port like Resolv::DNS#initialize.
#
def initialize: (?String | Hash[Symbol, untyped] config_info) -> untyped
def initialize: (?String | DNS::dns_config_options config_info) -> untyped
end

# <!-- rdoc-file=lib/resolv.rb -->
Expand Down
Loading

0 comments on commit 7d4f483

Please sign in to comment.