Skip to content

Commit

Permalink
Merge branch 'main' into fix_mixin_structure_of_actioncontoroller
Browse files Browse the repository at this point in the history
  • Loading branch information
tk0miya authored Oct 23, 2023
2 parents ab6b370 + 3e93a59 commit 1fa770c
Show file tree
Hide file tree
Showing 366 changed files with 11,394 additions and 8,710 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
tmp
.gem_rbs_collection
.yardoc
24 changes: 24 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -202,3 +202,27 @@
[submodule "gems/recaptcha/5.15/_src"]
path = gems/recaptcha/5.15/_src
url = https://github.com/ambethia/recaptcha.git
[submodule "gems/rack-oauth2/2.2/_src"]
path = gems/rack-oauth2/2.2/_src
url = https://github.com/nov/rack-oauth2.git
[submodule "gems/rqrcode/2.2/_src"]
path = gems/rqrcode/2.2/_src
url = https://github.com/whomwah/rqrcode.git
[submodule "gems/dotenv-rails/2.8/_src"]
path = gems/dotenv-rails/2.8/_src
url = https://github.com/bkeepers/dotenv.git
[submodule "gems/activerecord-import/1.5/_src"]
path = gems/activerecord-import/1.5/_src
url = https://github.com/zdennis/activerecord-import.git
[submodule "gems/rest-client/2.1/_src"]
path = gems/rest-client/2.1/_src
url = https://github.com/rest-client/rest-client.git
[submodule "gems/rake/13.0/_src"]
path = gems/rake/13.0/_src
url = https://github.com/ruby/rake.git
[submodule "gems/chartkick/5.0/_src"]
path = gems/chartkick/5.0/_src
url = https://github.com/ankane/chartkick.git
[submodule "gems/browser/5.3/_src"]
path = gems/browser/5.3/_src
url = https://github.com/fnando/browser.git
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ GEM
rb-fsevent (0.11.2)
rb-inotify (0.10.1)
ffi (~> 1.0)
rbs (3.2.1)
rbs (3.2.2)
securerandom (0.2.2)
steep (1.5.3)
activesupport (>= 5.1)
Expand Down
42 changes: 42 additions & 0 deletions bin/check-manifest-yaml.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env ruby

require 'pathname'
require 'rbs'
require 'yaml'

def green(str)
"\e[32m#{str}\e[0m"
end

def stdlib?(name)
(RBS::Repository::DEFAULT_STDLIB_ROOT / name / '0').exist?
end

manifest_file = Pathname('manifest.yaml')
if manifest_file.exist?
manifest = YAML.safe_load(manifest_file.read)

unless manifest && manifest.key?('dependencies') && !manifest['dependencies'].empty?
puts <<~END
#{manifest_file} exists but does not contain dependencies.
Please add dependencies to #{manifest_file} or remove it.
END
exit 1
end

manifest['dependencies'].each do |dep|
unless dep.key?('name')
puts "#{dep} does not contain the name of dependency."
exit 1
end

unless stdlib?(dep['name'])
puts "#{dep['name']} is not a standard library."
exit 1
end
end

puts green "manifest.yaml is valid. 🐾"
else
puts green "manifest.yaml is not exist skipped. 🐾"
end
3 changes: 2 additions & 1 deletion bin/init_new_gem
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ put base / '_scripts/test', <<~BASH
bundle exec steep check
$(git rev-parse --show-toplevel)/bin/check-untyped-call.rb
$(git rev-parse --show-toplevel)/bin/check-manifest-yaml.rb
BASH
(base / '_scripts/test').chmod(0o755)
put base / 'manifest.yaml', <<~'YAML'
Expand All @@ -129,7 +130,7 @@ if github_account
update(Pathname('.github/CODEOWNERS')) do |content|
lines = content.lines

pre_gems_lines, gems_lines =
pre_gems_lines, gems_lines =
lines.map(&:chomp).slice_before('# Maintainer of individual gems (alphabetical order)').to_a
pre_gems_lines << gems_lines.shift

Expand Down
1 change: 1 addition & 0 deletions gems/actionmailer/7.0/_scripts/test
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ cd ${RBS_DIR}/_test
bundle exec steep check

$(git rev-parse --show-toplevel)/bin/check-untyped-call.rb
$(git rev-parse --show-toplevel)/bin/check-manifest-yaml.rb
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 @@ -92,17 +92,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
1 change: 1 addition & 0 deletions gems/activemodel/7.0/_scripts/test
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ cd ${RBS_DIR}/_test
bundle exec steep check

$(git rev-parse --show-toplevel)/bin/check-untyped-call.rb
$(git rev-parse --show-toplevel)/bin/check-manifest-yaml.rb
21 changes: 21 additions & 0 deletions gems/activerecord-import/1.5/_scripts/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env bash

# Exit command with non-zero status code, Output logs of every command executed, Treat unset variables as an error when substituting.
set -eou pipefail
# Internal Field Separator - Linux shell variable
IFS=$'\n\t'
# Print shell input lines
set -v

# Set RBS_DIR variable to change directory to execute type checks using `steep check`
RBS_DIR=$(cd $(dirname $0)/..; pwd)
# Set REPO_DIR variable to validate RBS files added to the corresponding folder
REPO_DIR=$(cd $(dirname $0)/../../..; pwd)
# Validate RBS files, using the bundler environment present
bundle exec rbs --repo $REPO_DIR -r activerecord-import:1.5 validate --silent

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

$(git rev-parse --show-toplevel)/bin/check-untyped-call.rb
1 change: 1 addition & 0 deletions gems/activerecord-import/1.5/_src
Submodule _src added at 08a76f
11 changes: 11 additions & 0 deletions gems/activerecord-import/1.5/_test/Steepfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
D = Steep::Diagnostic

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

repo_path "../../../"
library "activerecord-import"

configure_code_diagnostics(D::Ruby.all_error)
end
39 changes: 39 additions & 0 deletions gems/activerecord-import/1.5/_test/test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Write Ruby code to test the RBS.
# It is type checked by `steep check` command.

require "activerecord"
require "activerecord-import"

class Book < ActiveRecord::Base
end

# @type var books: Array[Book]

books = []
10.times do |i|
books << Book.new
end
Book.import books # or use import!

columns = [ :title, :author ]
values = [ ['Book1', 'George Orwell'], ['Book2', 'Bob Jones'] ]

# Importing without model validations
Book.import columns, values, validate: false

# Import with model validations
Book.import columns, values, validate: true

# when not specified :validate defaults to true
Book.import columns, values

values = [{ title: 'Book1', author: 'George Orwell' }, { title: 'Book2', author: 'Bob Jones'}]

# Importing without model validations
Book.import values, validate: false

# Import with model validations
Book.import values, validate: true

# when not specified :validate defaults to true
Book.import values
2 changes: 2 additions & 0 deletions gems/activerecord-import/1.5/_test/test.rbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class Book < ActiveRecord::Base
end
23 changes: 23 additions & 0 deletions gems/activerecord-import/1.5/activerecord-import.rbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module ActiveRecord
class Base
def self.bulk_import: (*untyped) -> void
alias self.import self.bulk_import

def self.bulk_import!: (*untyped) -> void
alias self.import! self.bulk_import!
end
end

module ActiveRecord
module Associations
class CollectionProxy
def bulk_import: (*untyped) -> void
alias import bulk_import
end

class CollectionAssociation
def bulk_import: (*untyped) -> void
alias import bulk_import
end
end
end
1 change: 1 addition & 0 deletions gems/activerecord/6.0/activerecord.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,7 @@ interface _ActiveRecord_Relation_ClassMethods[Model, Relation, PrimaryKey]
def select: (*Symbol | String) -> Relation
| () { (Model) -> boolish } -> Array[Model]
def reselect: (*Symbol | String) -> Relation
def scope: (Symbol, ^(*untyped, **untyped) [self: Relation] -> void }) ?{ (Module extention) [self: Relation] -> void } -> void
end

# https://github.com/rails/rails/blob/fbe2433be6e052a1acac63c7faf287c52ed3c5ba/activerecord/lib/arel/nodes/unary.rb
Expand Down
1 change: 1 addition & 0 deletions gems/activerecord/7.0/_scripts/test
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ cd ${RBS_DIR}/_test
bundle exec steep check

$(git rev-parse --show-toplevel)/bin/check-untyped-call.rb
$(git rev-parse --show-toplevel)/bin/check-manifest-yaml.rb
1 change: 1 addition & 0 deletions gems/activesupport/6.0/_scripts/test
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ cd ${RBS_DIR}/_test
bundle exec steep check

$(git rev-parse --show-toplevel)/bin/check-untyped-call.rb
$(git rev-parse --show-toplevel)/bin/check-manifest-yaml.rb
5 changes: 1 addition & 4 deletions gems/activesupport/6.0/activesupport-generated.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -7953,10 +7953,7 @@ module ActiveSupport
end
end

# NOTE: HashWithIndifferentAccess and ActiveSupport::HashWithIndifferentAccess are the same object
# but RBS doesn't have class alias syntax
class HashWithIndifferentAccess[T, U] < ActiveSupport::HashWithIndifferentAccess[T, U]
end
class HashWithIndifferentAccess = ActiveSupport::HashWithIndifferentAccess

module I18n
class Railtie < Rails::Railtie
Expand Down
1 change: 1 addition & 0 deletions gems/activesupport/7.0/_scripts/test
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ cd ${RBS_DIR}/_test
bundle exec steep check

$(git rev-parse --show-toplevel)/bin/check-untyped-call.rb
$(git rev-parse --show-toplevel)/bin/check-manifest-yaml.rb
1 change: 1 addition & 0 deletions gems/aws-sdk-s3/1/_scripts/test
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ cd ${RBS_DIR}/_test
bundle exec steep check

$(git rev-parse --show-toplevel)/bin/check-untyped-call.rb
$(git rev-parse --show-toplevel)/bin/check-manifest-yaml.rb
1 change: 1 addition & 0 deletions gems/bcrypt/3.1/_scripts/test
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ cd ${RBS_DIR}/_test
bundle exec steep check

$(git rev-parse --show-toplevel)/bin/check-untyped-call.rb
$(git rev-parse --show-toplevel)/bin/check-manifest-yaml.rb
21 changes: 21 additions & 0 deletions gems/browser/5.3/_scripts/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env bash

# Exit command with non-zero status code, Output logs of every command executed, Treat unset variables as an error when substituting.
set -eou pipefail
# Internal Field Separator - Linux shell variable
IFS=$'\n\t'
# Print shell input lines
set -v

# Set RBS_DIR variable to change directory to execute type checks using `steep check`
RBS_DIR=$(cd $(dirname $0)/..; pwd)
# Set REPO_DIR variable to validate RBS files added to the corresponding folder
REPO_DIR=$(cd $(dirname $0)/../../..; pwd)
# Validate RBS files, using the bundler environment present
bundle exec rbs --repo $REPO_DIR -r browser:5.3 validate --silent

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

$(git rev-parse --show-toplevel)/bin/check-untyped-call.rb
1 change: 1 addition & 0 deletions gems/browser/5.3/_src
Submodule _src added at fa4f68
Loading

0 comments on commit 1fa770c

Please sign in to comment.