Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various type signature updates for Rails #735

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
4d738af
actionview: update `label` and `button` signatures to use an optional…
hjwylde Nov 28, 2024
1c16116
activemodel: update `register` signature to use an optional block
hjwylde Nov 28, 2024
cc59e23
activerecord: update `find_each` signatures to use an optional block
hjwylde Nov 28, 2024
1d478ab
actionview: update `content_tag` signature to use an optional block
hjwylde Nov 28, 2024
c40103c
railties: update `insert_before`, `insert`, and `insert_after` signat…
hjwylde Nov 28, 2024
a6129ae
railties: update `use` signature to use an optional block
hjwylde Nov 28, 2024
c13837c
actionpack: update `delete` signature to use an optional block
hjwylde Nov 28, 2024
39fe450
actionview: update `render` signature to use an optional block
hjwylde Nov 28, 2024
7513d16
railties: update `routes` signature to use an optional block
hjwylde Nov 28, 2024
f4e7882
activerecord: update `touch` signature to use variable args
hjwylde Dec 5, 2024
2804750
actioncontroller: update `ActionController::Parameters` signatures to…
hjwylde Dec 5, 2024
73ff052
activesupport: update `to_xml` signature to use an optional block
hjwylde Dec 5, 2024
66afc32
actionpack: update `fetch` signature to use an optional block
hjwylde Dec 5, 2024
fb15ffd
actionpack: update `content_security_policy` signature to use an opti…
hjwylde Dec 5, 2024
f4c9e04
activemodel: update `delete` signature to include optional type and o…
hjwylde Dec 5, 2024
08adb5d
actionpack: update `redirect` signature to use an optional block
hjwylde Dec 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 24 additions & 4 deletions gems/actionpack/6.0/actioncontroller.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,19 @@ end

module ActionController
class Parameters
# Deletes a key-value pair from +Parameters+ and returns the value. If
# +key+ is not found, returns +nil+ (or, with optional code block, yields
# +key+ and returns the result). Cf. +#extract!+, which returns the
# corresponding +ActionController::Parameters+ object.
def delete: (untyped key) ?{ () -> untyped } -> untyped

def keys: () -> Array[untyped]
def key?: () -> bool
def has_key?: () -> bool
def key?: (untyped key) -> bool
def has_key?: (untyped key) -> bool
def values: () -> Array[untyped]
def has_value?: () -> bool
def has_value?: (untyped value) -> bool
def empty?: () -> bool
def include?: (untyped) -> bool
def include?: (untyped key) -> bool
def as_json: () -> String
def to_s: () -> String
def each_key: () { (untyped) -> untyped} -> Hash[untyped, untyped]
Expand Down Expand Up @@ -255,3 +261,17 @@ module ActionController
extend AbstractController::Caching::Fragments::ClassMethods
end
end

module ActionController
module ContentSecurityPolicy
module ClassMethods
def content_security_policy: (?bool enabled, **untyped options) ?{ (untyped) -> untyped } -> untyped
end
end
end

module ActionController
class TestSession < Rack::Session::Abstract::PersistedSecure::SecureSessionHash
def fetch: (untyped key, *untyped args) ?{ () -> untyped } -> untyped
end
end
102 changes: 102 additions & 0 deletions gems/actionpack/6.0/actiondispatch.rbs
Original file line number Diff line number Diff line change
@@ -1,3 +1,50 @@
module ActionDispatch
class Cookies
class CookieJar
def fetch: (untyped name, *untyped args) ?{ () -> untyped } -> untyped
end
end
end

module ActionDispatch
module Http
class Headers
# Returns the value for the given key mapped to @env.
#
# If the key is not found and an optional code block is not provided,
# raises a <tt>KeyError</tt> exception.
#
# If the code block is provided, then it will be run and
# its result returned.
def fetch: (untyped key) { () -> untyped } -> untyped
| (untyped key, untyped default) -> untyped
end
end
end

module ActionDispatch
class Request
class Session
# Returns value of the given key from the session, or raises +KeyError+
# if can't find the given key and no default value is set.
# Returns default value if specified.
#
# session.fetch(:foo)
# # => KeyError: key not found: "foo"
#
# session.fetch(:foo, :bar)
# # => :bar
#
# session.fetch(:foo) do
# :bar
# end
# # => :bar
def fetch: (untyped key) { () -> untyped } -> untyped
| (untyped key, untyped default) -> untyped
end
end
end

module ActionDispatch
class RequestId
X_REQUEST_ID: ::String
Expand Down Expand Up @@ -228,6 +275,61 @@ module ActionDispatch
end
end

module ActionDispatch
module Routing
module Redirection
# Redirect any path to another path:
#
# get "/stories" => redirect("/posts")
#
# This will redirect the user, while ignoring certain parts of the request, including query string, etc.
# <tt>/stories</tt>, <tt>/stories?foo=bar</tt>, etc all redirect to <tt>/posts</tt>.
#
# You can also use interpolation in the supplied redirect argument:
#
# get 'docs/:article', to: redirect('/wiki/%{article}')
#
# Note that if you return a path without a leading slash then the URL is prefixed with the
# current SCRIPT_NAME environment variable. This is typically '/' but may be different in
# a mounted engine or where the application is deployed to a subdirectory of a website.
#
# Alternatively you can use one of the other syntaxes:
#
# The block version of redirect allows for the easy encapsulation of any logic associated with
# the redirect in question. Either the params and request are supplied as arguments, or just
# params, depending of how many arguments your block accepts. A string is required as a
# return value.
#
# get 'jokes/:number', to: redirect { |params, request|
# path = (params[:number].to_i.even? ? "wheres-the-beef" : "i-love-lamp")
# "http://#{request.host_with_port}/#{path}"
# }
#
# Note that the +do end+ syntax for the redirect block wouldn't work, as Ruby would pass
# the block to +get+ instead of +redirect+. Use <tt>{ ... }</tt> instead.
#
# The options version of redirect allows you to supply only the parts of the URL which need
# to change, it also supports interpolation of the path similar to the first example.
#
# get 'stores/:name', to: redirect(subdomain: 'stores', path: '/%{name}')
# get 'stores/:name(*all)', to: redirect(subdomain: 'stores', path: '/%{name}%{all}')
# get '/stories', to: redirect(path: '/posts')
#
# This will redirect the user, while changing only the specified parts of the request,
# for example the +path+ option in the last example.
# <tt>/stories</tt>, <tt>/stories?foo=bar</tt>, redirect to <tt>/posts</tt> and <tt>/posts?foo=bar</tt> respectively.
#
# Finally, an object which responds to call can be supplied to redirect, allowing you to reuse
# common redirect routes. The call method must accept two arguments, params and request, and return
# a string.
#
# get 'accounts/:name' => redirect(SubdomainRedirector.new('api'))
#
def redirect: (*untyped args) ?{ () -> untyped } -> (OptionRedirect | PathRedirect | Redirect)
end
end
end

module ActionDispatch
module Http
module MimeNegotiation
Expand Down
88 changes: 0 additions & 88 deletions gems/actionpack/6.0/actionpack-generated.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -1252,8 +1252,6 @@ module ActionController
include AbstractController::Callbacks

module ClassMethods
def content_security_policy: (?bool enabled, **untyped options) { (untyped) -> untyped } -> untyped

def content_security_policy_report_only: (?bool report_only, **untyped options) -> untyped
end

Expand Down Expand Up @@ -3662,12 +3660,6 @@ module ActionController
# <tt>ActionController::Parameters</tt> instance.
def transform_keys!: () { () -> untyped } -> untyped

# Deletes a key-value pair from +Parameters+ and returns the value. If
# +key+ is not found, returns +nil+ (or, with optional code block, yields
# +key+ and returns the result). Cf. +#extract!+, which returns the
# corresponding +ActionController::Parameters+ object.
def delete: (untyped key) { () -> untyped } -> untyped

# Returns a new instance of <tt>ActionController::Parameters</tt> with only
# items that the block evaluates to true.
def select: () { () -> untyped } -> untyped
Expand Down Expand Up @@ -4229,8 +4221,6 @@ module ActionController

def dig: (*untyped keys) -> untyped

def fetch: (untyped key, *untyped args) { () -> untyped } -> untyped

private

def load!: () -> untyped
Expand Down Expand Up @@ -4837,15 +4827,6 @@ module ActionDispatch

DEFAULT: untyped

# Returns the value for the given key mapped to @env.
#
# If the key is not found and an optional code block is not provided,
# raises a <tt>KeyError</tt> exception.
#
# If the code block is provided, then it will be run and
# its result returned.
def fetch: (untyped key, ?untyped default) { () -> untyped } -> untyped

def each: () { (untyped) -> untyped } -> untyped

# Returns a new Http::Headers instance containing the contents of
Expand Down Expand Up @@ -7296,8 +7277,6 @@ module ActionDispatch
# Returns the value of the cookie by +name+, or +nil+ if no such cookie exists.
def []: (untyped name) -> untyped

def fetch: (untyped name, *untyped args) { () -> untyped } -> untyped

def key?: (untyped name) -> untyped

alias has_key? key?
Expand Down Expand Up @@ -8439,22 +8418,6 @@ module ActionDispatch
# Deletes given key from the session.
def delete: (untyped key) -> untyped

# Returns value of the given key from the session, or raises +KeyError+
# if can't find the given key and no default value is set.
# Returns default value if specified.
#
# session.fetch(:foo)
# # => KeyError: key not found: "foo"
#
# session.fetch(:foo, :bar)
# # => :bar
#
# session.fetch(:foo) do
# :bar
# end
# # => :bar
def fetch: (untyped key, ?untyped default) { () -> untyped } -> untyped

def inspect: () -> untyped

def exists?: () -> untyped
Expand Down Expand Up @@ -9917,57 +9880,6 @@ module ActionDispatch

def inspect: () -> ::String
end

module Redirection
# Redirect any path to another path:
#
# get "/stories" => redirect("/posts")
#
# This will redirect the user, while ignoring certain parts of the request, including query string, etc.
# <tt>/stories</tt>, <tt>/stories?foo=bar</tt>, etc all redirect to <tt>/posts</tt>.
#
# You can also use interpolation in the supplied redirect argument:
#
# get 'docs/:article', to: redirect('/wiki/%{article}')
#
# Note that if you return a path without a leading slash then the URL is prefixed with the
# current SCRIPT_NAME environment variable. This is typically '/' but may be different in
# a mounted engine or where the application is deployed to a subdirectory of a website.
#
# Alternatively you can use one of the other syntaxes:
#
# The block version of redirect allows for the easy encapsulation of any logic associated with
# the redirect in question. Either the params and request are supplied as arguments, or just
# params, depending of how many arguments your block accepts. A string is required as a
# return value.
#
# get 'jokes/:number', to: redirect { |params, request|
# path = (params[:number].to_i.even? ? "wheres-the-beef" : "i-love-lamp")
# "http://#{request.host_with_port}/#{path}"
# }
#
# Note that the +do end+ syntax for the redirect block wouldn't work, as Ruby would pass
# the block to +get+ instead of +redirect+. Use <tt>{ ... }</tt> instead.
#
# The options version of redirect allows you to supply only the parts of the URL which need
# to change, it also supports interpolation of the path similar to the first example.
#
# get 'stores/:name', to: redirect(subdomain: 'stores', path: '/%{name}')
# get 'stores/:name(*all)', to: redirect(subdomain: 'stores', path: '/%{name}%{all}')
# get '/stories', to: redirect(path: '/posts')
#
# This will redirect the user, while changing only the specified parts of the request,
# for example the +path+ option in the last example.
# <tt>/stories</tt>, <tt>/stories?foo=bar</tt>, redirect to <tt>/posts</tt> and <tt>/posts?foo=bar</tt> respectively.
#
# Finally, an object which responds to call can be supplied to redirect, allowing you to reuse
# common redirect routes. The call method must accept two arguments, params and request, and return
# a string.
#
# get 'accounts/:name' => redirect(SubdomainRedirector.new('api'))
#
def redirect: (*untyped args) { () -> untyped } -> (OptionRedirect | PathRedirect | Redirect)
end
end
end

Expand Down
Loading
Loading