rbs_rails 0.5.0 → 0.8.2
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/.dependabot/config.yml +8 -0
- data/.github/workflows/ci.yml +29 -0
- data/.gitignore +4 -2
- data/.gitmodules +0 -3
- data/CHANGELOG.md +22 -0
- data/Gemfile +2 -2
- data/Gemfile.lock +61 -0
- data/README.md +16 -44
- data/Steepfile +3 -0
- data/bin/add-type-params.rb +2 -1
- data/bin/gem_rbs +94 -0
- data/bin/postprocess.rb +1 -1
- data/bin/rbs +1 -1
- data/bin/rbs-prototype-rb.rb +5 -1
- data/bin/setup +1 -0
- data/lib/rbs_rails.rb +4 -0
- data/lib/rbs_rails/active_record.rb +91 -46
- data/lib/rbs_rails/dependency_builder.rb +43 -0
- data/lib/rbs_rails/rake_task.rb +72 -0
- data/lib/rbs_rails/util.rb +25 -0
- data/lib/rbs_rails/version.rb +1 -1
- data/rbs_rails.gemspec +2 -2
- data/sig/activerecord.rbs +4 -0
- data/sig/fileutils.rbs +1 -0
- data/sig/rake.rbs +6 -0
- data/sig/rbs_rails/active_record.rbs +11 -2
- data/sig/rbs_rails/dependency_builder.rbs +9 -0
- data/sig/rbs_rails/rake_task.rbs +26 -0
- data/sig/rbs_rails/util.rbs +11 -0
- metadata +19 -30
- data/.travis.yml +0 -11
- data/assets/sig/action_mailer.rbs +0 -8
- data/assets/sig/builtin.rbs +0 -7
- data/assets/sig/capybara.rbs +0 -14
- data/assets/sig/concurrent.rbs +0 -4
- data/assets/sig/erb.rbs +0 -4
- data/assets/sig/erubi.rbs +0 -4
- data/assets/sig/i18n.rbs +0 -4
- data/assets/sig/libxml.rbs +0 -10
- data/assets/sig/minitest.rbs +0 -13
- data/assets/sig/nokogiri.rbs +0 -8
- data/assets/sig/pg.rbs +0 -5
- data/assets/sig/que.rbs +0 -4
- data/assets/sig/queue_classic.rbs +0 -4
- data/assets/sig/racc.rbs +0 -4
- data/assets/sig/rack-test.rbs +0 -6
- data/assets/sig/rack.rbs +0 -47
- data/assets/sig/rails.rbs +0 -14
- data/assets/sig/rdoc.rbs +0 -9
- data/assets/sig/sidekiq.rbs +0 -4
- data/assets/sig/sneakers.rbs +0 -4
- data/assets/sig/stdlib.rbs +0 -24
- data/assets/sig/sucker_punch.rbs +0 -4
- data/assets/sig/thor.rbs +0 -12
- data/assets/sig/tzinfo.rbs +0 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2d70009e239cba7c79ad16cf1861495051952a6930205678b05fcf5ad97f0809
|
4
|
+
data.tar.gz: 20e8d58362c2222651aa10430417ac90af1b8e38e5b3bbfcfdf43f186f77eff6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ef998ce7910f4169eb43716ed8ad0132338751b0c9346213cb02ddecae71fe1c0159d8eb2404877cd599dbd352fe42d3d52bd1316f6577fe2568c912ec0f402a
|
7
|
+
data.tar.gz: 846055b9290bfb250e933686a7dcd05bd52ff331cc1a83a3ddae4cd05ff480b2b43b7c164dbbbff164f25c568837b9d30353eb787464f430b08ffbed69737add
|
@@ -0,0 +1,29 @@
|
|
1
|
+
name: CI
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches:
|
6
|
+
- master
|
7
|
+
pull_request:
|
8
|
+
types:
|
9
|
+
- opened
|
10
|
+
- synchronize
|
11
|
+
- reopened
|
12
|
+
|
13
|
+
jobs:
|
14
|
+
test:
|
15
|
+
strategy:
|
16
|
+
fail-fast: false
|
17
|
+
matrix:
|
18
|
+
ruby: [2.6, 2.7, '3.0', head]
|
19
|
+
runs-on: ubuntu-latest
|
20
|
+
steps:
|
21
|
+
- uses: actions/checkout@v2
|
22
|
+
- uses: ruby/setup-ruby@v1
|
23
|
+
with:
|
24
|
+
ruby-version: ${{ matrix.ruby }}
|
25
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
26
|
+
- env:
|
27
|
+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
28
|
+
run: bin/gem_rbs
|
29
|
+
- run: bundle exec rake
|
data/.gitignore
CHANGED
data/.gitmodules
CHANGED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# Change log
|
2
|
+
|
3
|
+
## master (unreleased)
|
4
|
+
|
5
|
+
## 0.8.2 (2021-02-20)
|
6
|
+
|
7
|
+
* Add ActiveRecord::AttributeMethods::Dirty methods [#104](https://github.com/pocke/rbs_rails/pull/104)
|
8
|
+
* Define find method based on primary key [#105](https://github.com/pocke/rbs_rails/pull/105)
|
9
|
+
|
10
|
+
## 0.8.1 (2021-01-09)
|
11
|
+
|
12
|
+
* Skip generation RBS fro class that doesn't have table in DB. [#95](https://github.com/pocke/rbs_rails/pull/95)
|
13
|
+
|
14
|
+
## 0.8.0 (2020-12-31)
|
15
|
+
|
16
|
+
* **[BREAKING]** Move RBS files that are copied by `rbs_rails:copy_signature_files` task to [ruby/gem_rbs](https://github.com/ruby/gem_rbs) repository [#90](https://github.com/pocke/rbs_rails/pull/90)
|
17
|
+
* Allow all kinds of argument for scope [#89](https://github.com/pocke/rbs_rails/pull/89)
|
18
|
+
|
19
|
+
## 0.7.0 (2020-12-28)
|
20
|
+
|
21
|
+
* **[BREAKING]** Re-structure signature directory. [#86](https://github.com/pocke/rbs_rails/pull/86)
|
22
|
+
* Generate ActiveRecord models with namespaces and superclasses. [#87](https://github.com/pocke/rbs_rails/pull/87)
|
data/Gemfile
CHANGED
data/Gemfile.lock
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
rbs_rails (0.8.2)
|
5
|
+
parser
|
6
|
+
rbs (>= 1)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
activesupport (6.1.2.1)
|
12
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
13
|
+
i18n (>= 1.6, < 2)
|
14
|
+
minitest (>= 5.1)
|
15
|
+
tzinfo (~> 2.0)
|
16
|
+
zeitwerk (~> 2.3)
|
17
|
+
ast (2.4.2)
|
18
|
+
ast_utils (0.4.0)
|
19
|
+
parser (>= 2.7.0)
|
20
|
+
concurrent-ruby (1.1.8)
|
21
|
+
ffi (1.14.2)
|
22
|
+
i18n (1.8.9)
|
23
|
+
concurrent-ruby (~> 1.0)
|
24
|
+
language_server-protocol (3.15.0.1)
|
25
|
+
listen (3.4.1)
|
26
|
+
rb-fsevent (~> 0.10, >= 0.10.3)
|
27
|
+
rb-inotify (~> 0.9, >= 0.9.10)
|
28
|
+
minitest (5.14.3)
|
29
|
+
parser (3.0.0.0)
|
30
|
+
ast (~> 2.4.1)
|
31
|
+
rainbow (3.0.0)
|
32
|
+
rake (13.0.3)
|
33
|
+
rb-fsevent (0.10.4)
|
34
|
+
rb-inotify (0.10.1)
|
35
|
+
ffi (~> 1.0)
|
36
|
+
rbs (1.0.6)
|
37
|
+
steep (0.41.0)
|
38
|
+
activesupport (>= 5.1)
|
39
|
+
ast_utils (>= 0.4.0)
|
40
|
+
language_server-protocol (~> 3.15.0.1)
|
41
|
+
listen (~> 3.0)
|
42
|
+
parser (>= 2.7)
|
43
|
+
rainbow (>= 2.2.2, < 4.0)
|
44
|
+
rbs (~> 1.0.3)
|
45
|
+
tzinfo (2.0.4)
|
46
|
+
concurrent-ruby (~> 1.0)
|
47
|
+
zeitwerk (2.4.2)
|
48
|
+
|
49
|
+
PLATFORMS
|
50
|
+
ruby
|
51
|
+
x86_64-linux
|
52
|
+
|
53
|
+
DEPENDENCIES
|
54
|
+
minitest
|
55
|
+
rake (~> 13.0)
|
56
|
+
rbs (>= 1.0.0)
|
57
|
+
rbs_rails!
|
58
|
+
steep (>= 0.34.0)
|
59
|
+
|
60
|
+
BUNDLED WITH
|
61
|
+
2.2.4
|
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,56 +20,22 @@ Or install it yourself as:
|
|
20
20
|
|
21
21
|
## Usage
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
It has two tasks.
|
26
|
-
|
27
|
-
* `copy_signature_files`: Copy type definition files for Rails from rbs_rails.
|
28
|
-
* `generate_rbs_for_model`: Generate RBS files from model classes.
|
23
|
+
Put the following code to `lib/tasks/rbs.rake`.
|
29
24
|
|
30
25
|
```ruby
|
31
|
-
|
32
|
-
|
33
|
-
task copy_signature_files: :environment do
|
34
|
-
require 'rbs_rails'
|
35
|
-
|
36
|
-
to = Rails.root.join('sig/rbs_rails/')
|
37
|
-
to.mkpath unless to.exist?
|
38
|
-
RbsRails.copy_signatures(to: to)
|
39
|
-
end
|
40
|
-
|
41
|
-
task generate_rbs_for_model: :environment do
|
42
|
-
require 'rbs_rails'
|
43
|
-
|
44
|
-
out_dir = Rails.root / 'sig'
|
45
|
-
out_dir.mkdir unless out_dir.exist?
|
46
|
-
|
47
|
-
Rails.application.eager_load!
|
26
|
+
require 'rbs_rails/rake_task'
|
48
27
|
|
49
|
-
|
50
|
-
|
28
|
+
RbsRails::RakeTask.new
|
29
|
+
```
|
51
30
|
|
52
|
-
|
53
|
-
FileUtils.mkdir_p(path.dirname)
|
31
|
+
Then, the following three tasks are available.
|
54
32
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
end
|
59
|
-
```
|
33
|
+
* `rbs_rails:generate_rbs_for_models`: Generate RBS files for Active Record models
|
34
|
+
* `rbs_rails:generate_rbs_for_path_helpers`: Generate RBS files for path helpers
|
35
|
+
* `rbs_rails:all`: Execute all tasks of RBS Rails
|
60
36
|
|
61
|
-
### For path helpers
|
62
37
|
|
63
|
-
```ruby
|
64
|
-
# Rakefile
|
65
38
|
|
66
|
-
task generate_rbs_for_path_helpers: :environment do
|
67
|
-
require 'rbs_rails'
|
68
|
-
out_path = Rails.root.join 'sig/path_helpers.rbs'
|
69
|
-
rbs = RbsRails::PathHelpers.generate
|
70
|
-
out_path.write rbs
|
71
|
-
end
|
72
|
-
```
|
73
39
|
|
74
40
|
### Steep integration
|
75
41
|
|
@@ -89,6 +55,9 @@ target :app do
|
|
89
55
|
library 'logger'
|
90
56
|
library 'mutex_m'
|
91
57
|
library 'date'
|
58
|
+
library 'monitor'
|
59
|
+
library 'singleton'
|
60
|
+
library 'tsort'
|
92
61
|
|
93
62
|
library 'activesupport'
|
94
63
|
library 'actionpack'
|
@@ -104,7 +73,10 @@ You need to put RBS repo to `path/to/rbs_repo`. See https://github.com/ruby/gem_
|
|
104
73
|
|
105
74
|
## Development
|
106
75
|
|
107
|
-
After checking out the repo, run `bin/setup` to install dependencies.
|
76
|
+
After checking out the repo, run `GITHUB_TOKEN=xxx bin/setup` to install dependencies.
|
77
|
+
`GITHUB_TOKEN` environment variable is required to fetch RBS from [ruby/gem_rbs](https://github.com/ruby/gem_rbs) repository.
|
78
|
+
|
79
|
+
You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
108
80
|
|
109
81
|
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
110
82
|
|
data/Steepfile
CHANGED
data/bin/add-type-params.rb
CHANGED
@@ -4,7 +4,7 @@ require 'bundler/inline'
|
|
4
4
|
|
5
5
|
gemfile do
|
6
6
|
source 'https://rubygems.org'
|
7
|
-
gem 'rbs', '
|
7
|
+
gem 'rbs', '1.0.0'
|
8
8
|
end
|
9
9
|
|
10
10
|
require 'rbs'
|
@@ -16,6 +16,7 @@ end
|
|
16
16
|
def env
|
17
17
|
@env ||= begin
|
18
18
|
loader = RBS::EnvironmentLoader.new()
|
19
|
+
loader.add(library: 'tsort')
|
19
20
|
RBS::Environment.from_loader(loader).resolve_type_names
|
20
21
|
end
|
21
22
|
end
|
data/bin/gem_rbs
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'net/http'
|
4
|
+
require 'json'
|
5
|
+
require 'securerandom'
|
6
|
+
require 'pathname'
|
7
|
+
|
8
|
+
TOKEN = ENV.fetch('GITHUB_TOKEN')
|
9
|
+
VERSION = "6.0.3.2"
|
10
|
+
|
11
|
+
def req(query)
|
12
|
+
http = Net::HTTP.new("api.github.com", 443)
|
13
|
+
http.use_ssl = true
|
14
|
+
header = {
|
15
|
+
"Authorization" => "Bearer #{TOKEN}",
|
16
|
+
'Content-Type' => 'application/json',
|
17
|
+
'User-Agent' => 'gem_rbs client',
|
18
|
+
}
|
19
|
+
resp = http.request_post('/graphql', JSON.generate(query), header)
|
20
|
+
JSON.parse(resp.body, symbolize_names: true).tap do |content|
|
21
|
+
raise content[:errors].inspect if content[:errors]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
class QueryBuilder
|
26
|
+
attr_reader :variables
|
27
|
+
|
28
|
+
def initialize
|
29
|
+
@queries = []
|
30
|
+
@variables = {}
|
31
|
+
end
|
32
|
+
|
33
|
+
def add(query, variables)
|
34
|
+
query = query.dup
|
35
|
+
variables = variables.transform_keys do |key|
|
36
|
+
next key unless @variables.key?(key)
|
37
|
+
|
38
|
+
new_key = key + '_' + SecureRandom.hex(8)
|
39
|
+
query.gsub!(key, new_key)
|
40
|
+
new_key
|
41
|
+
end
|
42
|
+
|
43
|
+
@queries << query
|
44
|
+
@variables.merge!(variables)
|
45
|
+
end
|
46
|
+
|
47
|
+
def query
|
48
|
+
# TODO: Allow non-String type for variables
|
49
|
+
"query(#{variables.keys.map { |v| "$#{v}: String!" }.join(',')}) { #{@queries.join("\n")} }"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
gems = %w[activesupport actionpack activejob activemodel actionview activerecord railties]
|
54
|
+
|
55
|
+
builder = QueryBuilder.new
|
56
|
+
gems.each do |gem|
|
57
|
+
path = "main:gems/#{gem}/#{VERSION}"
|
58
|
+
builder.add(<<~GRAPHQL, { 'path' => path })
|
59
|
+
#{gem}:repository(owner: "ruby", name: "gem_rbs_collection") {
|
60
|
+
object(expression: $path) {
|
61
|
+
... on Tree {
|
62
|
+
entries {
|
63
|
+
name
|
64
|
+
object {
|
65
|
+
... on Blob {
|
66
|
+
isTruncated
|
67
|
+
text
|
68
|
+
}
|
69
|
+
}
|
70
|
+
}
|
71
|
+
}
|
72
|
+
}
|
73
|
+
}
|
74
|
+
GRAPHQL
|
75
|
+
end
|
76
|
+
|
77
|
+
resp = req(query: builder.query, variables: builder.variables)
|
78
|
+
|
79
|
+
resp[:data].each do |gem_name, gem_value|
|
80
|
+
gem_value.dig(:object, :entries).each do |entry|
|
81
|
+
fname = entry[:name]
|
82
|
+
if fname.end_with?('.rbs')
|
83
|
+
content =
|
84
|
+
if entry.dig(:object, :isTruncated)
|
85
|
+
`curl -H 'Accept: application/vnd.github.v3.raw' -H Authorization: token #{TOKEN} https://api.github.com/repos/ruby/gem_rbs_collection/contents/gems/#{gem_name}/#{VERSION}/#{fname}`
|
86
|
+
else
|
87
|
+
entry.dig(:object, :text)
|
88
|
+
end
|
89
|
+
dir = Pathname("gem_rbs/gems/#{gem_name}/#{VERSION}")
|
90
|
+
dir.mkpath
|
91
|
+
dir.join(fname).write(content)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
data/bin/postprocess.rb
CHANGED
data/bin/rbs
CHANGED
@@ -18,7 +18,7 @@ end
|
|
18
18
|
exec(
|
19
19
|
'rbs',
|
20
20
|
# Require stdlibs
|
21
|
-
'-rlogger', '-rpathname', '-rmutex_m', '-rdate',
|
21
|
+
'-rlogger', '-rpathname', '-rmutex_m', '-rdate', '-rmonitor', '-rsingleton', '-rtsort',
|
22
22
|
"--repo=#{repo}",
|
23
23
|
# Require Rails libraries
|
24
24
|
v('-ractivesupport'), v('-ractionpack'), v('-ractivejob'), v('-ractivemodel'), v('-ractionview'), v('-ractiverecord'), v('-rrailties'),
|
data/bin/rbs-prototype-rb.rb
CHANGED
@@ -68,6 +68,7 @@ using Module.new {
|
|
68
68
|
kls.members << RBS::AST::Members::AttrAccessor.new(
|
69
69
|
name: f.children.first,
|
70
70
|
type: untyped,
|
71
|
+
kind: :instance,
|
71
72
|
ivar_name: false,
|
72
73
|
annotations: [],
|
73
74
|
location: nil,
|
@@ -98,6 +99,7 @@ using Module.new {
|
|
98
99
|
name: name,
|
99
100
|
ivar_name: :"@_#{name}",
|
100
101
|
type: RBS::Types::Bases::Any.new(location: nil),
|
102
|
+
kind: context.attribute_kind,
|
101
103
|
location: nil,
|
102
104
|
comment: comments[node.first_lineno - 1],
|
103
105
|
annotations: []
|
@@ -111,6 +113,7 @@ using Module.new {
|
|
111
113
|
name: name,
|
112
114
|
ivar_name: :"@_#{name}",
|
113
115
|
type: RBS::Types::Bases::Any.new(location: nil),
|
116
|
+
kind: context.attribute_kind,
|
114
117
|
location: nil,
|
115
118
|
comment: comments[node.first_lineno - 1],
|
116
119
|
annotations: []
|
@@ -124,6 +127,7 @@ using Module.new {
|
|
124
127
|
name: name,
|
125
128
|
ivar_name: :"@_#{name}",
|
126
129
|
type: RBS::Types::Bases::Any.new(location: nil),
|
130
|
+
kind: context.attribute_kind,
|
127
131
|
location: nil,
|
128
132
|
comment: comments[node.first_lineno - 1],
|
129
133
|
annotations: []
|
@@ -171,7 +175,7 @@ using Module.new {
|
|
171
175
|
|
172
176
|
def struct_as_superclass
|
173
177
|
name = RBS::TypeName.new(name: 'Struct', namespace: RBS::Namespace.root)
|
174
|
-
RBS::AST::Declarations::Class::Super.new(name: name, args: ['untyped'])
|
178
|
+
RBS::AST::Declarations::Class::Super.new(name: name, args: ['untyped'], location: nil)
|
175
179
|
end
|
176
180
|
end
|
177
181
|
}
|