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 26, 2024
1 parent 4601d66 commit fca4c65
Show file tree
Hide file tree
Showing 15 changed files with 267 additions and 45 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
1 change: 1 addition & 0 deletions stdlib/net-http/0/manifest.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
dependencies:
- name: net-protocol
- name: uri
- name: openssl
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: OpenSSL::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, OpenSSL::X509::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
Loading

0 comments on commit fca4c65

Please sign in to comment.