rbs_rails 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -1
- data/Gemfile +2 -2
- data/README.md +10 -43
- data/assets/sig/rails.rbs +1 -5
- data/bin/add-type-params.rb +1 -1
- data/bin/postprocess.rb +1 -1
- data/bin/rbs-prototype-rb.rb +5 -1
- data/lib/rbs_rails/active_record.rb +5 -8
- data/lib/rbs_rails/rake_task.rb +75 -0
- data/lib/rbs_rails/version.rb +1 -1
- data/rbs_rails.gemspec +1 -1
- data/sig/fileutils.rbs +1 -0
- data/sig/rake.rbs +6 -0
- data/sig/rbs_rails/rake_task.rbs +20 -0
- metadata +8 -5
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/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,56 +20,23 @@ 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?
|
26
|
+
require 'rbs_rails/rake_task'
|
46
27
|
|
47
|
-
|
28
|
+
RbsRails::RakeTask.new
|
29
|
+
```
|
48
30
|
|
49
|
-
|
50
|
-
next if klass.abstract_class?
|
31
|
+
Then, the following four tasks are available.
|
51
32
|
|
52
|
-
|
53
|
-
|
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
|
54
37
|
|
55
|
-
sig = RbsRails::ActiveRecord.class_to_rbs(klass)
|
56
|
-
path.write sig
|
57
|
-
end
|
58
|
-
end
|
59
|
-
```
|
60
38
|
|
61
|
-
### For path helpers
|
62
39
|
|
63
|
-
```ruby
|
64
|
-
# Rakefile
|
65
|
-
|
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
40
|
|
74
41
|
### Steep integration
|
75
42
|
|
data/assets/sig/rails.rbs
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
module Rails
|
2
|
-
|
2
|
+
def self.env: () -> ActiveSupport::StringInquirer | ...
|
3
3
|
|
4
4
|
module Dom
|
5
5
|
module Testing
|
@@ -8,7 +8,3 @@ module Rails
|
|
8
8
|
end
|
9
9
|
end
|
10
10
|
end
|
11
|
-
|
12
|
-
class Rails::Application
|
13
|
-
def routes: () -> untyped
|
14
|
-
end
|
data/bin/add-type-params.rb
CHANGED
data/bin/postprocess.rb
CHANGED
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
|
}
|
@@ -303,23 +303,20 @@ module RbsRails
|
|
303
303
|
when :string, :text, :citext, :uuid, :binary
|
304
304
|
'String'
|
305
305
|
when :datetime
|
306
|
-
|
307
|
-
# ActiveSupport::TimeWithZone.name
|
308
|
-
'Time'
|
306
|
+
'ActiveSupport::TimeWithZone'
|
309
307
|
when :boolean
|
310
|
-
"
|
308
|
+
"bool"
|
311
309
|
when :jsonb, :json
|
312
310
|
"untyped"
|
313
311
|
when :date
|
314
|
-
|
315
|
-
# Date.name
|
316
|
-
'untyped'
|
312
|
+
'Date'
|
317
313
|
when :time
|
318
314
|
'Time'
|
319
315
|
when :inet
|
320
316
|
"IPAddr"
|
321
317
|
else
|
322
|
-
|
318
|
+
# Unknown column type, give up
|
319
|
+
'untyped'
|
323
320
|
end
|
324
321
|
end
|
325
322
|
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/tasklib'
|
3
|
+
|
4
|
+
module RbsRails
|
5
|
+
class RakeTask < Rake::TaskLib
|
6
|
+
attr_accessor :ignore_model_if, :name
|
7
|
+
|
8
|
+
def initialize(name = :rbs_rails, &block)
|
9
|
+
super()
|
10
|
+
|
11
|
+
@name = name
|
12
|
+
|
13
|
+
block.call(self) if block
|
14
|
+
|
15
|
+
def_copy_signature_files
|
16
|
+
def_generate_rbs_for_models
|
17
|
+
def_generate_rbs_for_path_helpers
|
18
|
+
def_all
|
19
|
+
end
|
20
|
+
|
21
|
+
def def_all
|
22
|
+
desc 'Run all tasks of rbs_rails'
|
23
|
+
|
24
|
+
deps = [:"#{name}:copy_signature_files", :"#{name}:generate_rbs_for_models", :"#{name}:generate_rbs_for_path_helpers"]
|
25
|
+
task("#{name}:all": deps)
|
26
|
+
end
|
27
|
+
|
28
|
+
def def_copy_signature_files
|
29
|
+
desc 'Copy RBS files for rbs_rails'
|
30
|
+
task("#{name}:copy_signature_files": :environment) do
|
31
|
+
require 'rbs_rails'
|
32
|
+
|
33
|
+
to = Rails.root.join('sig/rbs_rails/')
|
34
|
+
to.mkpath unless to.exist?
|
35
|
+
RbsRails.copy_signatures(to: to)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def def_generate_rbs_for_models
|
40
|
+
desc 'Generate RBS files for Active Record models'
|
41
|
+
task("#{name}:generate_rbs_for_models": :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!
|
48
|
+
|
49
|
+
|
50
|
+
# HACK: for steep
|
51
|
+
(_ = ::ActiveRecord::Base).descendants.each do |klass|
|
52
|
+
next if klass.abstract_class?
|
53
|
+
next if ignore_model_if&.call(klass)
|
54
|
+
|
55
|
+
path = out_dir / "app/models/#{klass.name.underscore}.rbs"
|
56
|
+
FileUtils.mkdir_p(path.dirname)
|
57
|
+
|
58
|
+
sig = RbsRails::ActiveRecord.class_to_rbs(klass)
|
59
|
+
path.write sig
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def def_generate_rbs_for_path_helpers
|
65
|
+
desc 'Generate RBS files for path helpers'
|
66
|
+
task("#{name}:generate_rbs_for_path_helpers": :environment) do
|
67
|
+
require 'rbs_rails'
|
68
|
+
|
69
|
+
out_path = Rails.root.join 'sig/path_helpers.rbs'
|
70
|
+
rbs = RbsRails::PathHelpers.generate
|
71
|
+
out_path.write rbs
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
data/lib/rbs_rails/version.rb
CHANGED
data/rbs_rails.gemspec
CHANGED
data/sig/fileutils.rbs
CHANGED
data/sig/rake.rbs
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
module RbsRails
|
2
|
+
class RakeTask < Rake::TaskLib
|
3
|
+
interface _Filter
|
4
|
+
def call: (Class) -> boolish
|
5
|
+
end
|
6
|
+
attr_accessor ignore_model_if: _Filter | nil
|
7
|
+
|
8
|
+
attr_accessor name: Symbol
|
9
|
+
|
10
|
+
def initialize: (?::Symbol name) { (self) -> void } -> void
|
11
|
+
|
12
|
+
def def_all: () -> void
|
13
|
+
|
14
|
+
def def_copy_signature_files: () -> void
|
15
|
+
|
16
|
+
def def_generate_rbs_for_models: () -> void
|
17
|
+
|
18
|
+
def def_generate_rbs_for_path_helpers: () -> void
|
19
|
+
end
|
20
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rbs_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Masataka Pocke Kuwabara
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-12-
|
11
|
+
date: 2020-12-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: parser
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '1'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '1'
|
41
41
|
description: A RBS files generator for Rails application
|
42
42
|
email:
|
43
43
|
- kuwabara@pocke.me
|
@@ -87,13 +87,16 @@ files:
|
|
87
87
|
- lib/rbs_rails.rb
|
88
88
|
- lib/rbs_rails/active_record.rb
|
89
89
|
- lib/rbs_rails/path_helpers.rb
|
90
|
+
- lib/rbs_rails/rake_task.rb
|
90
91
|
- lib/rbs_rails/version.rb
|
91
92
|
- rbs_rails.gemspec
|
92
93
|
- sig/fileutils.rbs
|
93
94
|
- sig/parser.rbs
|
95
|
+
- sig/rake.rbs
|
94
96
|
- sig/rbs_rails.rbs
|
95
97
|
- sig/rbs_rails/active_record.rbs
|
96
98
|
- sig/rbs_rails/path_helpers.rbs
|
99
|
+
- sig/rbs_rails/rake_task.rbs
|
97
100
|
- sig/rbs_rails/version.rbs
|
98
101
|
homepage: https://github.com/pocke/rbs_rails
|
99
102
|
licenses:
|
@@ -116,7 +119,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
116
119
|
- !ruby/object:Gem::Version
|
117
120
|
version: '0'
|
118
121
|
requirements: []
|
119
|
-
rubygems_version: 3.2.
|
122
|
+
rubygems_version: 3.2.3
|
120
123
|
signing_key:
|
121
124
|
specification_version: 4
|
122
125
|
summary: A RBS files generator for Rails application
|