Skip to content

Commit

Permalink
[actionpack] Improve hook methods type such as before_action (#441)
Browse files Browse the repository at this point in the history
  • Loading branch information
pocke authored Oct 5, 2023
1 parent c69c46f commit 361062a
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 18 deletions.
9 changes: 4 additions & 5 deletions gems/actionpack/6.0/_scripts/test
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ bundle exec rbs --repo $REPO_DIR -r actionpack:6.0 \
-rrack -rcgi -ruri \
validate --silent

# TODO
# cd ${RBS_DIR}/_test
# # Run type checks
# bundle exec steep check
cd ${RBS_DIR}/_test
# Run type checks
bundle exec steep check

# $(git rev-parse --show-toplevel)/bin/check-untyped-call.rb
$(git rev-parse --show-toplevel)/bin/check-untyped-call.rb
24 changes: 24 additions & 0 deletions gems/actionpack/6.0/_test/Steepfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
D = Steep::Diagnostic

target :test do
check "."
signature "."

repo_path "../../../"
library "actionpack:6.0"

library "monitor"
library "date"
library "erb"
library "singleton"
library "logger"
library "mutex_m"
library "time"
library "activesupport"
library "actionview"
library "rack"
library "cgi"
library "uri"

configure_code_diagnostics(D::Ruby.all_error)
end
15 changes: 15 additions & 0 deletions gems/actionpack/6.0/_test/test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class ApplicationController < ActionController::Base
before_action :set_locale
before_action -> (controller) { self.controller_instance_method; controller.controller_instance_method }

around_action -> (controller, block) { block.call; controller.controller_instance_method }

module After
def self.after(_) end
end

after_action After

def controller_instance_method
end
end
7 changes: 7 additions & 0 deletions gems/actionpack/6.0/_test/test.rbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class ApplicationController < ActionController::Base
module After
def self.after: (ActionController::Base) -> untyped
end

def controller_instance_method: () -> untyped
end
42 changes: 29 additions & 13 deletions gems/actionpack/6.0/actioncontroller.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,33 @@ module ActionController
end

module AbstractController::Callbacks::ClassMethods
def before_action: (*untyped) -> void
def around_action: (*untyped) -> void
def after_action: (*untyped) -> void
def skip_before_action: (*untyped) -> void
def skip_around_action: (*untyped) -> void
def skip_after_action: (*untyped) -> void
def prepend_before_action: (*untyped) -> void
def prepend_around_action: (*untyped) -> void
def prepend_after_action: (*untyped) -> void
def append_before_action: (*untyped) -> void
def append_around_action: (*untyped) -> void
def append_after_action: (*untyped) -> void
end
interface _BeforeActionCallback
def before: (ActionController::Base controller) -> void
end

interface _AroundActionCallback
def around: (ActionController::Base controller) { () -> void } -> void
end

interface _AfterActionCallback
def after: (ActionController::Base controller) -> void
end

type before_action_callback = Symbol | ^(instance controller) [self: instance] -> void | _BeforeActionCallback
type around_action_callback = Symbol | ^(instance controller, ^() -> void) [self: instance] -> void | _AroundActionCallback
type after_action_callback = Symbol | ^(instance controller) [self: instance] -> void | _AfterActionCallback

def before_action: (*before_action_callback) ?{ (instance controller) [self: instance] -> void } -> void
def around_action: (*around_action_callback) ?{ (instance controller, ^() -> void) [self: instance] -> void } -> void
def after_action: (*after_action_callback) ?{ (instance controller) [self: instance] -> void } -> void
def skip_before_action: (*before_action_callback) ?{ (instance controller) [self: instance] -> void } -> void
def skip_around_action: (*around_action_callback) ?{ (instance controller, ^() -> void) [self: instance] -> void } -> void
def skip_after_action: (*after_action_callback) ?{ (instance controller) [self: instance] -> void } -> void
def prepend_before_action: (*before_action_callback) ?{ (instance controller) [self: instance] -> void } -> void
def prepend_around_action: (*around_action_callback) ?{ (instance controller, ^() -> void) [self: instance] -> void } -> void
def prepend_after_action: (*after_action_callback) ?{ (instance controller) [self: instance] -> void } -> void

alias append_before_action before_action
alias append_around_action around_action
alias append_after_action after_action
end

0 comments on commit 361062a

Please sign in to comment.