rbs_rails 0.2.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/.gitmodules +3 -0
- data/.travis.yml +3 -0
- data/Gemfile +3 -2
- data/README.md +33 -35
- data/Rakefile +14 -1
- data/Steepfile +12 -1
- data/assets/sig/action_mailer.rbs +6 -3
- data/assets/sig/capybara.rbs +14 -0
- data/assets/sig/concurrent.rbs +4 -0
- data/assets/sig/erb.rbs +4 -0
- data/assets/sig/erubi.rbs +4 -0
- data/assets/sig/i18n.rbs +4 -0
- data/assets/sig/minitest.rbs +12 -1
- data/assets/sig/pg.rbs +5 -0
- data/assets/sig/que.rbs +4 -0
- data/assets/sig/queue_classic.rbs +4 -0
- data/assets/sig/racc.rbs +4 -0
- data/assets/sig/rack-test.rbs +6 -0
- data/assets/sig/rack.rbs +47 -0
- data/assets/sig/rails.rbs +7 -8
- data/assets/sig/rdoc.rbs +9 -0
- data/assets/sig/sidekiq.rbs +4 -0
- data/assets/sig/sneakers.rbs +4 -0
- data/assets/sig/stdlib.rbs +15 -5
- data/assets/sig/sucker_punch.rbs +4 -0
- data/assets/sig/thor.rbs +12 -0
- data/assets/sig/tzinfo.rbs +4 -0
- data/bin/add-type-params.rb +39 -13
- data/bin/postprocess.rb +137 -0
- data/bin/rbs +30 -0
- data/bin/rbs-prototype-rb.rb +195 -0
- data/bin/to-ascii.rb +5 -0
- data/lib/rbs_rails/active_record.rb +78 -33
- data/lib/rbs_rails/rake_task.rb +75 -0
- data/lib/rbs_rails/version.rb +1 -1
- data/rbs_rails.gemspec +1 -0
- data/sig/fileutils.rbs +1 -0
- data/sig/rake.rbs +6 -0
- data/sig/rbs_rails/active_record.rbs +4 -4
- data/sig/rbs_rails/rake_task.rbs +20 -0
- metadata +45 -12
- data/assets/sig/action_controller.rbs +0 -44
- data/assets/sig/action_view.rbs +0 -3
- data/assets/sig/active_record.rbs +0 -130
- data/assets/sig/generated/activemodel.rbs +0 -3877
- data/assets/sig/generated/activesupport.rbs +0 -11480
- data/bin/merge-duplicate-decls.rb +0 -30
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5dd350161bbcf1358c43fbda2fb5b42aa106b42a14f079a26e60338e9ccbae92
|
4
|
+
data.tar.gz: b5a700311050c8500037f70be69d652c96bbf20ebc0334ad49d7c97964b977ec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 414a6a9fa8feb585dbae5826c68e9043eedeb3b4e1c43d112efdcdcb61c10686d18dc76d57191c34f456ec43c36246cb4c096ceb59dba7cdf0bba4f10a5e4159
|
7
|
+
data.tar.gz: da5d5c7f919d5b2dedfb596bb8e207210ee9a3391db6af13372cc976b57f3ba89ca4b8a19578847f538b4b6adfd547c634f261ac8e21030f2ec98dee3e15147e
|
data/.gitignore
CHANGED
data/.gitmodules
ADDED
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -7,7 +7,7 @@ RBS files generator for Ruby on Rails.
|
|
7
7
|
Add this line to your application's Gemfile:
|
8
8
|
|
9
9
|
```ruby
|
10
|
-
gem 'rbs_rails'
|
10
|
+
gem 'rbs_rails', require: false
|
11
11
|
```
|
12
12
|
|
13
13
|
And then execute:
|
@@ -20,57 +20,55 @@ Or install it yourself as:
|
|
20
20
|
|
21
21
|
## Usage
|
22
22
|
|
23
|
-
|
23
|
+
Put the following code to `lib/tasks/rbs.rake`.
|
24
24
|
|
25
|
-
|
25
|
+
```ruby
|
26
|
+
require 'rbs_rails/rake_task'
|
26
27
|
|
27
|
-
|
28
|
-
|
28
|
+
RbsRails::RakeTask.new
|
29
|
+
```
|
29
30
|
|
30
|
-
|
31
|
-
|
31
|
+
Then, the following four tasks are available.
|
32
|
+
|
33
|
+
* `rbs_rails:copy_signature_files`: Copy RBS files for rbs_rails
|
34
|
+
* `rbs_rails:generate_rbs_for_models`: Generate RBS files for Active Record models
|
35
|
+
* `rbs_rails:generate_rbs_for_path_helpers`: Generate RBS files for path helpers
|
36
|
+
* `rbs_rails:all`: Execute all tasks of RBS Rails
|
32
37
|
|
33
|
-
task copy_signature_files: :environment do
|
34
|
-
require 'rbs_rails'
|
35
38
|
|
36
|
-
to = Rails.root.join('sig/rbs_rails/')
|
37
|
-
to.mkpath unless to.exist?
|
38
|
-
RbsRails.copy_signatures(to: to)
|
39
|
-
end
|
40
39
|
|
41
|
-
task generate_rbs_for_model: :environment do
|
42
|
-
require 'rbs_rails'
|
43
40
|
|
44
|
-
|
45
|
-
out_dir.mkdir unless out_dir.exist?
|
41
|
+
### Steep integration
|
46
42
|
|
47
|
-
|
43
|
+
You need to specify the following libraries by `Steepfile`.
|
48
44
|
|
49
|
-
|
50
|
-
|
45
|
+
```ruby
|
46
|
+
# Steepfile
|
51
47
|
|
52
|
-
|
53
|
-
|
48
|
+
target :app do
|
49
|
+
signature 'sig'
|
54
50
|
|
55
|
-
|
56
|
-
path.write sig
|
57
|
-
end
|
58
|
-
end
|
59
|
-
```
|
51
|
+
check 'app'
|
60
52
|
|
61
|
-
|
53
|
+
repo_path "path/to/rbs_repo"
|
62
54
|
|
63
|
-
|
64
|
-
|
55
|
+
library 'pathname'
|
56
|
+
library 'logger'
|
57
|
+
library 'mutex_m'
|
58
|
+
library 'date'
|
65
59
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
60
|
+
library 'activesupport'
|
61
|
+
library 'actionpack'
|
62
|
+
library 'activejob'
|
63
|
+
library 'activemodel'
|
64
|
+
library 'actionview'
|
65
|
+
library 'activerecord'
|
66
|
+
library 'railties'
|
71
67
|
end
|
72
68
|
```
|
73
69
|
|
70
|
+
You need to put RBS repo to `path/to/rbs_repo`. See https://github.com/ruby/gem_rbs
|
71
|
+
|
74
72
|
## Development
|
75
73
|
|
76
74
|
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/Rakefile
CHANGED
@@ -1,7 +1,20 @@
|
|
1
1
|
require "bundler/gem_tasks"
|
2
|
-
|
2
|
+
require 'rake/testtask'
|
3
|
+
|
4
|
+
task :default => [:rbs_validate, :steep, :test]
|
3
5
|
|
4
6
|
desc 'run Steep'
|
5
7
|
task :steep do
|
6
8
|
sh 'steep', 'check'
|
7
9
|
end
|
10
|
+
|
11
|
+
task :rbs_validate do
|
12
|
+
rbs = Pathname(__dir__).join('bin/rbs').to_s
|
13
|
+
sh "ruby #{rbs} validate --silent"
|
14
|
+
end
|
15
|
+
|
16
|
+
Rake::TestTask.new do |test|
|
17
|
+
test.libs << 'test'
|
18
|
+
test.test_files = Dir['test/**/*_test.rb']
|
19
|
+
test.verbose = true
|
20
|
+
end
|
data/Steepfile
CHANGED
@@ -3,7 +3,18 @@ target :lib do
|
|
3
3
|
signature 'assets/sig'
|
4
4
|
|
5
5
|
check "lib" # Directory name
|
6
|
+
repo_path ENV['RBS_REPO_DIR'] || './gem_rbs/gems'
|
6
7
|
|
7
8
|
library "pathname"
|
8
|
-
|
9
|
+
library "logger"
|
10
|
+
library "mutex_m"
|
11
|
+
library "date"
|
12
|
+
|
13
|
+
library 'activesupport'
|
14
|
+
library 'actionpack'
|
15
|
+
library 'activejob'
|
16
|
+
library 'activemodel'
|
17
|
+
library 'actionview'
|
18
|
+
library 'activerecord'
|
19
|
+
library 'railties'
|
9
20
|
end
|
@@ -1,5 +1,8 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
module ActionMailer
|
2
|
+
class Base
|
3
|
+
# TODO
|
4
|
+
# extend ActionView::Layouts::ClassMethods
|
3
5
|
|
4
|
-
|
6
|
+
def self.default: (?Hash[Symbol, untyped] value) -> Hash[Symbol, untyped]
|
7
|
+
end
|
5
8
|
end
|
data/assets/sig/erb.rbs
ADDED
data/assets/sig/i18n.rbs
ADDED
data/assets/sig/minitest.rbs
CHANGED
data/assets/sig/pg.rbs
ADDED
data/assets/sig/que.rbs
ADDED
data/assets/sig/racc.rbs
ADDED
data/assets/sig/rack.rbs
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
module Rack
|
2
|
+
class Server
|
3
|
+
end
|
4
|
+
|
5
|
+
class Response
|
6
|
+
module Helpers
|
7
|
+
def location: () -> untyped
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
class Request
|
12
|
+
module Helpers
|
13
|
+
end
|
14
|
+
|
15
|
+
module Env
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
module Session
|
20
|
+
module Abstract
|
21
|
+
class SessionHash
|
22
|
+
end
|
23
|
+
|
24
|
+
class PersistedSecure
|
25
|
+
class SecureSessionHash
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
class Persisted
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
class SessionId
|
34
|
+
end
|
35
|
+
|
36
|
+
class Dalli
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
module Cache
|
41
|
+
class MetaStore
|
42
|
+
end
|
43
|
+
|
44
|
+
class EntityStore
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
data/assets/sig/rails.rbs
CHANGED
@@ -1,11 +1,10 @@
|
|
1
1
|
module Rails
|
2
|
-
def self.
|
3
|
-
def self.application: () -> Rails::Application
|
4
|
-
end
|
5
|
-
|
6
|
-
class Rails::Application
|
7
|
-
def routes: () -> untyped
|
8
|
-
end
|
2
|
+
def self.env: () -> ActiveSupport::StringInquirer | ...
|
9
3
|
|
10
|
-
|
4
|
+
module Dom
|
5
|
+
module Testing
|
6
|
+
module Assertions
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
11
10
|
end
|
data/assets/sig/rdoc.rbs
ADDED
data/assets/sig/stdlib.rbs
CHANGED
@@ -1,14 +1,24 @@
|
|
1
|
-
|
1
|
+
module DRb
|
2
2
|
end
|
3
3
|
|
4
|
-
|
4
|
+
module DRb::DRbUndumped
|
5
5
|
end
|
6
6
|
|
7
|
-
module
|
7
|
+
module TSort
|
8
8
|
end
|
9
9
|
|
10
|
-
|
10
|
+
class SimpleDelegator
|
11
11
|
end
|
12
12
|
|
13
|
-
module
|
13
|
+
module Gem
|
14
|
+
class Version
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
module OpenSSL
|
19
|
+
class Cipher
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
module FileUtils
|
14
24
|
end
|
data/assets/sig/thor.rbs
ADDED
data/bin/add-type-params.rb
CHANGED
@@ -1,15 +1,22 @@
|
|
1
|
+
#!ruby
|
2
|
+
|
3
|
+
require 'bundler/inline'
|
4
|
+
|
5
|
+
gemfile do
|
6
|
+
source 'https://rubygems.org'
|
7
|
+
gem 'rbs', '1.0.0'
|
8
|
+
end
|
9
|
+
|
1
10
|
require 'rbs'
|
2
|
-
rbs = ARGF.read
|
3
|
-
decls = RBS::Parser.parse_signature(rbs)
|
4
11
|
|
5
12
|
def args(n)
|
6
13
|
(:T..).take(n)
|
7
14
|
end
|
8
15
|
|
9
16
|
def env
|
10
|
-
@env ||=
|
17
|
+
@env ||= begin
|
11
18
|
loader = RBS::EnvironmentLoader.new()
|
12
|
-
|
19
|
+
RBS::Environment.from_loader(loader).resolve_type_names
|
13
20
|
end
|
14
21
|
end
|
15
22
|
|
@@ -17,7 +24,7 @@ def apply_to_superclass(decl)
|
|
17
24
|
return unless decl.super_class
|
18
25
|
|
19
26
|
name = decl.super_class.name
|
20
|
-
type = env.
|
27
|
+
type = env.class_decls[name] || env.class_decls[name.absolute!]
|
21
28
|
return unless type
|
22
29
|
return if type.type_params.empty?
|
23
30
|
|
@@ -32,12 +39,21 @@ def apply_to_superclass(decl)
|
|
32
39
|
decl.instance_variable_set(:@type_params, type_params)
|
33
40
|
end
|
34
41
|
|
42
|
+
def apply_to_itself(decl)
|
43
|
+
name = decl.name
|
44
|
+
type = env.class_decls[name] || env.class_decls[name.absolute!]
|
45
|
+
return unless type
|
46
|
+
return if type.type_params.empty?
|
47
|
+
|
48
|
+
decl.instance_variable_set(:@type_params, type.type_params.dup)
|
49
|
+
end
|
50
|
+
|
35
51
|
def apply_to_includes(decl)
|
36
52
|
decl.members.each do |member|
|
37
53
|
next unless member.is_a?(RBS::AST::Members::Mixin)
|
38
54
|
|
39
55
|
name = member.name
|
40
|
-
type = env.
|
56
|
+
type = env.class_decls[name] || env.class_decls[name.absolute!]
|
41
57
|
next unless type
|
42
58
|
next if type.type_params.empty?
|
43
59
|
|
@@ -46,14 +62,24 @@ def apply_to_includes(decl)
|
|
46
62
|
end
|
47
63
|
end
|
48
64
|
|
49
|
-
decls
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
65
|
+
def analyze(decls)
|
66
|
+
decls.each do |decl|
|
67
|
+
case decl
|
68
|
+
when RBS::AST::Declarations::Class
|
69
|
+
apply_to_itself(decl)
|
70
|
+
apply_to_superclass(decl)
|
71
|
+
apply_to_includes(decl)
|
72
|
+
analyze(decl.members)
|
73
|
+
when RBS::AST::Declarations::Module, RBS::AST::Declarations::Interface
|
74
|
+
apply_to_itself(decl)
|
75
|
+
apply_to_includes(decl)
|
76
|
+
analyze(decl.members)
|
77
|
+
end
|
56
78
|
end
|
57
79
|
end
|
58
80
|
|
81
|
+
rbs = ARGF.read
|
82
|
+
decls = RBS::Parser.parse_signature(rbs)
|
83
|
+
analyze(decls)
|
84
|
+
|
59
85
|
puts RBS::Writer.new(out: $stdout).write(decls)
|