rbs_rails 0.8.2 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2d70009e239cba7c79ad16cf1861495051952a6930205678b05fcf5ad97f0809
4
- data.tar.gz: 20e8d58362c2222651aa10430417ac90af1b8e38e5b3bbfcfdf43f186f77eff6
3
+ metadata.gz: ccb7076ac91a406f491cf3e6c4d8499525f860660061ff23809635d000d1aba3
4
+ data.tar.gz: a863d9e16999e7491cef930b8fb79515c538ad7d83b919abad762a5c1290e370
5
5
  SHA512:
6
- metadata.gz: ef998ce7910f4169eb43716ed8ad0132338751b0c9346213cb02ddecae71fe1c0159d8eb2404877cd599dbd352fe42d3d52bd1316f6577fe2568c912ec0f402a
7
- data.tar.gz: 846055b9290bfb250e933686a7dcd05bd52ff331cc1a83a3ddae4cd05ff480b2b43b7c164dbbbff164f25c568837b9d30353eb787464f430b08ffbed69737add
6
+ metadata.gz: 10dccf3356c898258d6c13aaed04d61a5f137787f9ea696fe0d7005e2063c2fd130d9fdda59c4c7b4fa58d1cde84a3ca0cf750dac28f1ac9ffbfe94ead90da57
7
+ data.tar.gz: b8f5c227bf58bdb16044867cd4abd883f21782817eda8fa6d85d1956418c763829748d5d0ee0e81e1005ffd18e022d6da6e83b64aa97cf4f77fe6942bacec48b
@@ -3,6 +3,3 @@ update_configs:
3
3
  - package_manager: "ruby:bundler"
4
4
  directory: "/"
5
5
  update_schedule: "live"
6
- - package_manager: "ruby:bundler"
7
- directory: "/test/app/"
8
- update_schedule: "live"
@@ -23,7 +23,5 @@ jobs:
23
23
  with:
24
24
  ruby-version: ${{ matrix.ruby }}
25
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
26
+ - run: bin/setup
29
27
  - run: bundle exec rake
data/.gitignore CHANGED
@@ -9,4 +9,4 @@
9
9
  /test/app/sig/rbs_rails
10
10
  /test/app/sig/app
11
11
  /test/app/sig/path_helpers.rbs
12
- /gem_rbs
12
+ /.gem_rbs_collection/
data/CHANGELOG.md CHANGED
@@ -2,6 +2,22 @@
2
2
 
3
3
  ## master (unreleased)
4
4
 
5
+ ## 0.9.0 (2021-09-18)
6
+
7
+ ### New Features
8
+
9
+ * Support delegated_type association. [#181](https://github.com/pocke/rbs_rails/pull/181)
10
+
11
+ ### Bug Fixes
12
+
13
+ * Fix error on a table that doesn't have the PK. [#121](https://github.com/pocke/rbs_rails/pull/121)
14
+ * Quote variable names to avoid syntax errors. [#178](https://github.com/pocke/rbs_rails/pull/178)
15
+ * Add scope methods to `ActiveRecord_Associations_CollectionProxy`. [#182](https://github.com/pocke/rbs_rails/pull/182)
16
+ * Make `has_one` association optional. [#180](https://github.com/pocke/rbs_rails/pull/180)
17
+ * Omit some methods for polymorphic associations. [#184](https://github.com/pocke/rbs_rails/pull/184)
18
+ * Include enum methods to GeneratedRelationMethods. [#183](https://github.com/pocke/rbs_rails/pull/183)
19
+ * Include `_ActiveRecord_Relation` to `CollectionProxy`. [#189](https://github.com/pocke/rbs_rails/pull/189)
20
+
5
21
  ## 0.8.2 (2021-02-20)
6
22
 
7
23
  * Add ActiveRecord::AttributeMethods::Dirty methods [#104](https://github.com/pocke/rbs_rails/pull/104)
data/Gemfile CHANGED
@@ -1,9 +1,12 @@
1
1
  source "https://rubygems.org"
2
2
 
3
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
+
3
5
  # Specify your gem's dependencies in rbs_rails.gemspec
4
6
  gemspec
5
7
 
6
8
  gem "rake", "~> 13.0"
7
- gem 'rbs', '>= 1.0.0'
8
- gem 'steep', '>= 0.34.0'
9
+ gem 'rails', '< 6.1', '>= 6.0'
10
+ gem 'rbs', '>= 1.6'
11
+ gem 'steep', github: 'soutaro/steep'
9
12
  gem 'minitest'
data/Gemfile.lock CHANGED
@@ -1,49 +1,166 @@
1
+ GIT
2
+ remote: https://github.com/soutaro/steep
3
+ revision: 0673d88395fb0ea380463fef1aed568dfb077a60
4
+ specs:
5
+ steep (0.46.0)
6
+ activesupport (>= 5.1)
7
+ language_server-protocol (>= 3.15, < 4.0)
8
+ listen (~> 3.0)
9
+ parallel (>= 1.0.0)
10
+ parser (>= 3.0)
11
+ rainbow (>= 2.2.2, < 4.0)
12
+ rbs (>= 1.6.0)
13
+ terminal-table (>= 2, < 4)
14
+
1
15
  PATH
2
16
  remote: .
3
17
  specs:
4
- rbs_rails (0.8.2)
18
+ rbs_rails (0.9.0)
5
19
  parser
6
20
  rbs (>= 1)
7
21
 
8
22
  GEM
9
23
  remote: https://rubygems.org/
10
24
  specs:
11
- activesupport (6.1.2.1)
25
+ actioncable (6.0.4.1)
26
+ actionpack (= 6.0.4.1)
27
+ nio4r (~> 2.0)
28
+ websocket-driver (>= 0.6.1)
29
+ actionmailbox (6.0.4.1)
30
+ actionpack (= 6.0.4.1)
31
+ activejob (= 6.0.4.1)
32
+ activerecord (= 6.0.4.1)
33
+ activestorage (= 6.0.4.1)
34
+ activesupport (= 6.0.4.1)
35
+ mail (>= 2.7.1)
36
+ actionmailer (6.0.4.1)
37
+ actionpack (= 6.0.4.1)
38
+ actionview (= 6.0.4.1)
39
+ activejob (= 6.0.4.1)
40
+ mail (~> 2.5, >= 2.5.4)
41
+ rails-dom-testing (~> 2.0)
42
+ actionpack (6.0.4.1)
43
+ actionview (= 6.0.4.1)
44
+ activesupport (= 6.0.4.1)
45
+ rack (~> 2.0, >= 2.0.8)
46
+ rack-test (>= 0.6.3)
47
+ rails-dom-testing (~> 2.0)
48
+ rails-html-sanitizer (~> 1.0, >= 1.2.0)
49
+ actiontext (6.0.4.1)
50
+ actionpack (= 6.0.4.1)
51
+ activerecord (= 6.0.4.1)
52
+ activestorage (= 6.0.4.1)
53
+ activesupport (= 6.0.4.1)
54
+ nokogiri (>= 1.8.5)
55
+ actionview (6.0.4.1)
56
+ activesupport (= 6.0.4.1)
57
+ builder (~> 3.1)
58
+ erubi (~> 1.4)
59
+ rails-dom-testing (~> 2.0)
60
+ rails-html-sanitizer (~> 1.1, >= 1.2.0)
61
+ activejob (6.0.4.1)
62
+ activesupport (= 6.0.4.1)
63
+ globalid (>= 0.3.6)
64
+ activemodel (6.0.4.1)
65
+ activesupport (= 6.0.4.1)
66
+ activerecord (6.0.4.1)
67
+ activemodel (= 6.0.4.1)
68
+ activesupport (= 6.0.4.1)
69
+ activestorage (6.0.4.1)
70
+ actionpack (= 6.0.4.1)
71
+ activejob (= 6.0.4.1)
72
+ activerecord (= 6.0.4.1)
73
+ marcel (~> 1.0.0)
74
+ activesupport (6.0.4.1)
12
75
  concurrent-ruby (~> 1.0, >= 1.0.2)
13
- i18n (>= 1.6, < 2)
14
- minitest (>= 5.1)
15
- tzinfo (~> 2.0)
16
- zeitwerk (~> 2.3)
76
+ i18n (>= 0.7, < 2)
77
+ minitest (~> 5.1)
78
+ tzinfo (~> 1.1)
79
+ zeitwerk (~> 2.2, >= 2.2.2)
17
80
  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)
81
+ builder (3.2.4)
82
+ concurrent-ruby (1.1.9)
83
+ crass (1.0.6)
84
+ erubi (1.10.0)
85
+ ffi (1.15.4)
86
+ globalid (0.5.2)
87
+ activesupport (>= 5.0)
88
+ i18n (1.8.10)
23
89
  concurrent-ruby (~> 1.0)
24
- language_server-protocol (3.15.0.1)
25
- listen (3.4.1)
90
+ language_server-protocol (3.16.0.3)
91
+ listen (3.7.0)
26
92
  rb-fsevent (~> 0.10, >= 0.10.3)
27
93
  rb-inotify (~> 0.9, >= 0.9.10)
28
- minitest (5.14.3)
29
- parser (3.0.0.0)
94
+ loofah (2.12.0)
95
+ crass (~> 1.0.2)
96
+ nokogiri (>= 1.5.9)
97
+ mail (2.7.1)
98
+ mini_mime (>= 0.1.1)
99
+ marcel (1.0.1)
100
+ method_source (1.0.0)
101
+ mini_mime (1.1.1)
102
+ mini_portile2 (2.6.1)
103
+ minitest (5.14.4)
104
+ nio4r (2.5.8)
105
+ nokogiri (1.12.4)
106
+ mini_portile2 (~> 2.6.1)
107
+ racc (~> 1.4)
108
+ parallel (1.20.1)
109
+ parser (3.0.2.0)
30
110
  ast (~> 2.4.1)
111
+ racc (1.5.2)
112
+ rack (2.2.3)
113
+ rack-test (1.1.0)
114
+ rack (>= 1.0, < 3)
115
+ rails (6.0.4.1)
116
+ actioncable (= 6.0.4.1)
117
+ actionmailbox (= 6.0.4.1)
118
+ actionmailer (= 6.0.4.1)
119
+ actionpack (= 6.0.4.1)
120
+ actiontext (= 6.0.4.1)
121
+ actionview (= 6.0.4.1)
122
+ activejob (= 6.0.4.1)
123
+ activemodel (= 6.0.4.1)
124
+ activerecord (= 6.0.4.1)
125
+ activestorage (= 6.0.4.1)
126
+ activesupport (= 6.0.4.1)
127
+ bundler (>= 1.3.0)
128
+ railties (= 6.0.4.1)
129
+ sprockets-rails (>= 2.0.0)
130
+ rails-dom-testing (2.0.3)
131
+ activesupport (>= 4.2.0)
132
+ nokogiri (>= 1.6)
133
+ rails-html-sanitizer (1.4.2)
134
+ loofah (~> 2.3)
135
+ railties (6.0.4.1)
136
+ actionpack (= 6.0.4.1)
137
+ activesupport (= 6.0.4.1)
138
+ method_source
139
+ rake (>= 0.8.7)
140
+ thor (>= 0.20.3, < 2.0)
31
141
  rainbow (3.0.0)
32
- rake (13.0.3)
33
- rb-fsevent (0.10.4)
142
+ rake (13.0.6)
143
+ rb-fsevent (0.11.0)
34
144
  rb-inotify (0.10.1)
35
145
  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)
146
+ rbs (1.6.2)
147
+ sprockets (4.0.2)
46
148
  concurrent-ruby (~> 1.0)
149
+ rack (> 1, < 3)
150
+ sprockets-rails (3.2.2)
151
+ actionpack (>= 4.0)
152
+ activesupport (>= 4.0)
153
+ sprockets (>= 3.0.0)
154
+ terminal-table (3.0.1)
155
+ unicode-display_width (>= 1.1.1, < 3)
156
+ thor (1.1.0)
157
+ thread_safe (0.3.6)
158
+ tzinfo (1.2.9)
159
+ thread_safe (~> 0.1)
160
+ unicode-display_width (2.0.0)
161
+ websocket-driver (0.7.5)
162
+ websocket-extensions (>= 0.1.0)
163
+ websocket-extensions (0.1.5)
47
164
  zeitwerk (2.4.2)
48
165
 
49
166
  PLATFORMS
@@ -52,10 +169,11 @@ PLATFORMS
52
169
 
53
170
  DEPENDENCIES
54
171
  minitest
172
+ rails (>= 6.0, < 6.1)
55
173
  rake (~> 13.0)
56
- rbs (>= 1.0.0)
174
+ rbs (>= 1.6)
57
175
  rbs_rails!
58
- steep (>= 0.34.0)
176
+ steep!
59
177
 
60
178
  BUNDLED WITH
61
- 2.2.4
179
+ 2.2.27
data/README.md CHANGED
@@ -58,6 +58,9 @@ target :app do
58
58
  library 'monitor'
59
59
  library 'singleton'
60
60
  library 'tsort'
61
+ library 'time'
62
+
63
+ library 'rack'
61
64
 
62
65
  library 'activesupport'
63
66
  library 'actionpack'
@@ -69,12 +72,11 @@ target :app do
69
72
  end
70
73
  ```
71
74
 
72
- You need to put RBS repo to `path/to/rbs_repo`. See https://github.com/ruby/gem_rbs
75
+ You need to put RBS repo to `path/to/rbs_repo`. See https://github.com/ruby/gem_rbs_collection
73
76
 
74
77
  ## Development
75
78
 
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.
79
+ After checking out the repo, run `bin/setup` to install dependencies.
78
80
 
79
81
  You can also run `bin/console` for an interactive prompt that will allow you to experiment.
80
82
 
data/Rakefile CHANGED
@@ -9,8 +9,10 @@ task :steep do
9
9
  end
10
10
 
11
11
  task :rbs_validate do
12
- rbs = Pathname(__dir__).join('bin/rbs').to_s
13
- sh "ruby #{rbs} validate --silent"
12
+ repo = ENV['RBS_REPO_DIR']&.then do |env|
13
+ "--repo=#{env}"
14
+ end
15
+ sh "rbs #{repo} validate --silent"
14
16
  end
15
17
 
16
18
  Rake::TestTask.new do |test|
data/Steepfile CHANGED
@@ -3,21 +3,5 @@ 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'
7
-
8
- library "pathname"
9
- library "logger"
10
- library "mutex_m"
11
- library "date"
12
- library 'monitor'
13
- library 'singleton'
14
- library 'tsort'
15
-
16
- library 'activesupport'
17
- library 'actionpack'
18
- library 'activejob'
19
- library 'activemodel'
20
- library 'actionview'
21
- library 'activerecord'
22
- library 'railties'
6
+ repo_path ENV['RBS_REPO_DIR'] if ENV['RBS_REPO_DIR']
23
7
  end
data/bin/setup CHANGED
@@ -4,6 +4,6 @@ IFS=$'\n\t'
4
4
  set -vx
5
5
 
6
6
  bundle install
7
- bin/gem_rbs
7
+ bundle exec rbs collection install --frozen
8
8
 
9
9
  # Do any other automated setup that you need to do here
@@ -32,10 +32,14 @@ module RbsRails
32
32
 
33
33
  #{columns}
34
34
  #{associations}
35
+ #{delegated_type_instance}
36
+ #{delegated_type_scope(singleton: true)}
35
37
  #{enum_instance_methods}
36
38
  #{enum_scope_methods(singleton: true)}
37
39
  #{scopes(singleton: true)}
38
40
 
41
+ #{generated_relation_methods_decl}
42
+
39
43
  #{relation_decl}
40
44
 
41
45
  #{collection_proxy_decl}
@@ -46,18 +50,28 @@ module RbsRails
46
50
 
47
51
  private def pk_type
48
52
  pk = klass.primary_key
53
+ return 'top' unless pk
54
+
49
55
  col = klass.columns.find {|col| col.name == pk }
50
56
  sql_type_to_class(col.type)
51
57
  end
52
58
 
59
+ private def generated_relation_methods_decl
60
+ <<~RBS
61
+ module GeneratedRelationMethods
62
+ #{enum_scope_methods(singleton: false)}
63
+ #{scopes(singleton: false)}
64
+ #{delegated_type_scope(singleton: false)}
65
+ end
66
+ RBS
67
+ end
68
+
53
69
  private def relation_decl
54
70
  <<~RBS
55
71
  class #{relation_class_name} < ActiveRecord::Relation
72
+ include GeneratedRelationMethods
56
73
  include _ActiveRecord_Relation[#{klass_name}, #{pk_type}]
57
74
  include Enumerable[#{klass_name}]
58
-
59
- #{enum_scope_methods(singleton: false)}
60
- #{scopes(singleton: false)}
61
75
  end
62
76
  RBS
63
77
  end
@@ -65,6 +79,8 @@ module RbsRails
65
79
  private def collection_proxy_decl
66
80
  <<~RBS
67
81
  class ActiveRecord_Associations_CollectionProxy < ActiveRecord::Associations::CollectionProxy
82
+ include GeneratedRelationMethods
83
+ include _ActiveRecord_Relation[#{klass_name}, #{pk_type}]
68
84
  end
69
85
  RBS
70
86
  end
@@ -121,7 +137,7 @@ module RbsRails
121
137
  type = a.polymorphic? ? 'untyped' : Util.module_name(a.klass)
122
138
  type_optional = optional(type)
123
139
  <<~RUBY.chomp
124
- def #{a.name}: () -> #{type}
140
+ def #{a.name}: () -> #{type_optional}
125
141
  def #{a.name}=: (#{type_optional}) -> #{type_optional}
126
142
  def build_#{a.name}: (untyped) -> #{type}
127
143
  def create_#{a.name}: (untyped) -> #{type}
@@ -135,17 +151,91 @@ module RbsRails
135
151
  klass.reflect_on_all_associations(:belongs_to).map do |a|
136
152
  type = a.polymorphic? ? 'untyped' : Util.module_name(a.klass)
137
153
  type_optional = optional(type)
138
- <<~RUBY.chomp
139
- def #{a.name}: () -> #{type}
140
- def #{a.name}=: (#{type_optional}) -> #{type_optional}
141
- def build_#{a.name}: (untyped) -> #{type}
142
- def create_#{a.name}: (untyped) -> #{type}
143
- def create_#{a.name}!: (untyped) -> #{type}
144
- def reload_#{a.name}: () -> #{type_optional}
145
- RUBY
154
+ # @type var methods: Array[String]
155
+ methods = []
156
+ methods << "def #{a.name}: () -> #{type}"
157
+ methods << "def #{a.name}=: (#{type_optional}) -> #{type_optional}"
158
+ methods << "def reload_#{a.name}: () -> #{type_optional}"
159
+ if !a.polymorphic?
160
+ methods << "def build_#{a.name}: (untyped) -> #{type}"
161
+ methods << "def create_#{a.name}: (untyped) -> #{type}"
162
+ methods << "def create_#{a.name}!: (untyped) -> #{type}"
163
+ end
164
+ methods.join("\n")
146
165
  end.join("\n")
147
166
  end
148
167
 
168
+ private def delegated_type_scope(singleton:)
169
+ definitions = delegated_type_definitions
170
+ return "" unless definitions
171
+ definitions.map do |definition|
172
+ definition[:types].map do |type|
173
+ scope_name = type.tableize.gsub("/", "_")
174
+ "def #{singleton ? 'self.' : ''}#{scope_name}: () -> #{relation_class_name}"
175
+ end
176
+ end.flatten.join("\n")
177
+ end
178
+
179
+ private def delegated_type_instance
180
+ definitions = delegated_type_definitions
181
+ return "" unless definitions
182
+ # @type var methods: Array[String]
183
+ methods = []
184
+ definitions.each do |definition|
185
+ methods << "def #{definition[:role]}_class: () -> Class"
186
+ methods << "def #{definition[:role]}_name: () -> String"
187
+ methods << definition[:types].map do |type|
188
+ scope_name = type.tableize.gsub("/", "_")
189
+ singular = scope_name.singularize
190
+ <<~RUBY.chomp
191
+ def #{singular}?: () -> bool
192
+ def #{singular}: () -> #{type.classify}?
193
+ def #{singular}_id: () -> Integer?
194
+ RUBY
195
+ end.join("\n")
196
+ end
197
+ methods.join("\n")
198
+ end
199
+
200
+ private def delegated_type_definitions
201
+ ast = parse_model_file
202
+ return unless ast
203
+
204
+ traverse(ast).map do |node|
205
+ # @type block: { role: Symbol, types: Array[String] }?
206
+ next unless node.type == :send
207
+ next unless node.children[0].nil?
208
+ next unless node.children[1] == :delegated_type
209
+
210
+ role_node = node.children[2]
211
+ next unless role_node
212
+ next unless role_node.type == :sym
213
+ # @type var role: Symbol
214
+ role = role_node.children[0]
215
+
216
+ args_node = node.children[3]
217
+ next unless args_node
218
+ next unless args_node.type == :hash
219
+
220
+ types = traverse(args_node).map do |n|
221
+ # @type block: Array[String]?
222
+ next unless n.type == :pair
223
+ key_node = n.children[0]
224
+ next unless key_node
225
+ next unless key_node.type == :sym
226
+ next unless key_node.children[0] == :types
227
+
228
+ types_node = n.children[1]
229
+ next unless types_node
230
+ next unless types_node.type == :array
231
+ code = types_node.loc.expression.source
232
+ eval(code)
233
+ end.compact.flatten
234
+
235
+ { role: role, types: types }
236
+ end.compact
237
+ end
238
+
149
239
  private def enum_instance_methods
150
240
  # @type var methods: Array[String]
151
241
  methods = []
@@ -258,17 +348,17 @@ module RbsRails
258
348
  args_node.children.each do |node|
259
349
  case node.type
260
350
  when :arg
261
- res << "untyped #{node.children[0]}"
351
+ res << "untyped `#{node.children[0]}`"
262
352
  when :optarg
263
- res << "?untyped #{node.children[0]}"
353
+ res << "?untyped `#{node.children[0]}`"
264
354
  when :kwarg
265
355
  res << "#{node.children[0]}: untyped"
266
356
  when :kwoptarg
267
357
  res << "?#{node.children[0]}: untyped"
268
358
  when :restarg
269
- res << "*untyped #{node.children[0]}"
359
+ res << "*untyped `#{node.children[0]}`"
270
360
  when :kwrestarg
271
- res << "**untyped #{node.children[0]}"
361
+ res << "**untyped `#{node.children[0]}`"
272
362
  when :blockarg
273
363
  block = " { (*untyped) -> untyped }"
274
364
  else
@@ -292,7 +382,7 @@ module RbsRails
292
382
  end
293
383
 
294
384
  private def traverse(node, &block)
295
- return to_enum(__method__, node) unless block_given?
385
+ return to_enum(__method__ || raise, node) unless block_given?
296
386
 
297
387
  # @type var block: ^(Parser::AST::Node) -> untyped
298
388
  block.call node
@@ -2,5 +2,5 @@ module RbsRails
2
2
  # Because of copy_signatures is defined by lib/rbs_rails.rb
3
3
  # @dynamic self.copy_signatures
4
4
 
5
- VERSION = "0.8.2"
5
+ VERSION = "0.9.0"
6
6
  end
@@ -0,0 +1,132 @@
1
+ ---
2
+ sources:
3
+ - name: ruby/gem_rbs_collection
4
+ remote: https://github.com/ruby/gem_rbs_collection.git
5
+ revision: main
6
+ repo_dir: gems
7
+ path: ".gem_rbs_collection"
8
+ gems:
9
+ - name: pathname
10
+ version: '0'
11
+ source:
12
+ type: stdlib
13
+ - name: logger
14
+ version: '0'
15
+ source:
16
+ type: stdlib
17
+ - name: mutex_m
18
+ version: '0'
19
+ source:
20
+ type: stdlib
21
+ - name: date
22
+ version: '0'
23
+ source:
24
+ type: stdlib
25
+ - name: monitor
26
+ version: '0'
27
+ source:
28
+ type: stdlib
29
+ - name: singleton
30
+ version: '0'
31
+ source:
32
+ type: stdlib
33
+ - name: tsort
34
+ version: '0'
35
+ source:
36
+ type: stdlib
37
+ - name: time
38
+ version: '0'
39
+ source:
40
+ type: stdlib
41
+ - name: set
42
+ version: '0'
43
+ source:
44
+ type: stdlib
45
+ - name: rack
46
+ version: 2.2.2
47
+ source:
48
+ type: git
49
+ name: ruby/gem_rbs_collection
50
+ revision: 51880bed87fbc3dc8076fedb5cf798be05148220
51
+ remote: https://github.com/ruby/gem_rbs_collection.git
52
+ repo_dir: gems
53
+ - name: json
54
+ version: '0'
55
+ source:
56
+ type: stdlib
57
+ - name: strscan
58
+ version: '0'
59
+ source:
60
+ type: stdlib
61
+ - name: optparse
62
+ version: '0'
63
+ source:
64
+ type: stdlib
65
+ - name: actionpack
66
+ version: '6.0'
67
+ source:
68
+ type: git
69
+ name: ruby/gem_rbs_collection
70
+ revision: 51880bed87fbc3dc8076fedb5cf798be05148220
71
+ remote: https://github.com/ruby/gem_rbs_collection.git
72
+ repo_dir: gems
73
+ - name: actionview
74
+ version: '6.0'
75
+ source:
76
+ type: git
77
+ name: ruby/gem_rbs_collection
78
+ revision: 51880bed87fbc3dc8076fedb5cf798be05148220
79
+ remote: https://github.com/ruby/gem_rbs_collection.git
80
+ repo_dir: gems
81
+ - name: activejob
82
+ version: '6.0'
83
+ source:
84
+ type: git
85
+ name: ruby/gem_rbs_collection
86
+ revision: 51880bed87fbc3dc8076fedb5cf798be05148220
87
+ remote: https://github.com/ruby/gem_rbs_collection.git
88
+ repo_dir: gems
89
+ - name: activemodel
90
+ version: '6.0'
91
+ source:
92
+ type: git
93
+ name: ruby/gem_rbs_collection
94
+ revision: 51880bed87fbc3dc8076fedb5cf798be05148220
95
+ remote: https://github.com/ruby/gem_rbs_collection.git
96
+ repo_dir: gems
97
+ - name: activerecord
98
+ version: '6.0'
99
+ source:
100
+ type: git
101
+ name: ruby/gem_rbs_collection
102
+ revision: 51880bed87fbc3dc8076fedb5cf798be05148220
103
+ remote: https://github.com/ruby/gem_rbs_collection.git
104
+ repo_dir: gems
105
+ - name: activesupport
106
+ version: '6.0'
107
+ source:
108
+ type: git
109
+ name: ruby/gem_rbs_collection
110
+ revision: 51880bed87fbc3dc8076fedb5cf798be05148220
111
+ remote: https://github.com/ruby/gem_rbs_collection.git
112
+ repo_dir: gems
113
+ - name: parallel
114
+ version: '1.20'
115
+ source:
116
+ type: git
117
+ name: ruby/gem_rbs_collection
118
+ revision: 51880bed87fbc3dc8076fedb5cf798be05148220
119
+ remote: https://github.com/ruby/gem_rbs_collection.git
120
+ repo_dir: gems
121
+ - name: railties
122
+ version: '6.0'
123
+ source:
124
+ type: git
125
+ name: ruby/gem_rbs_collection
126
+ revision: 51880bed87fbc3dc8076fedb5cf798be05148220
127
+ remote: https://github.com/ruby/gem_rbs_collection.git
128
+ repo_dir: gems
129
+ - name: rbs
130
+ version: 1.6.2
131
+ source:
132
+ type: rubygems
@@ -0,0 +1,45 @@
1
+ # Download sources
2
+ sources:
3
+ - name: ruby/gem_rbs_collection
4
+ remote: https://github.com/ruby/gem_rbs_collection.git
5
+ revision: main
6
+ repo_dir: gems
7
+
8
+ # A directory to install the downloaded RBSs
9
+ path: .gem_rbs_collection
10
+
11
+ gems:
12
+ # stdlibs
13
+ - name: 'pathname'
14
+ - name: 'logger'
15
+ - name: 'mutex_m'
16
+ - name: 'date'
17
+ - name: 'monitor'
18
+ - name: 'singleton'
19
+ - name: 'tsort'
20
+ - name: 'time'
21
+ - name: 'set'
22
+
23
+ # gems
24
+ - name: 'rack'
25
+
26
+ # RBS gem dependencies
27
+ - name: 'json'
28
+ - name: 'strscan'
29
+ - name: 'optparse'
30
+
31
+ # Ignores - Gemfile.lock contains them but their RBSs are unnecessary
32
+ - name: steep
33
+ ignore: true
34
+ - name: nokogiri
35
+ ignore: true
36
+ - name: ast
37
+ ignore: true
38
+ - name: rainbow
39
+ ignore: true
40
+ - name: listen
41
+ ignore: true
42
+
43
+ # ignore RBS Rails itself
44
+ - name: rbs_rails
45
+ ignore: true
@@ -14,6 +14,8 @@ class RbsRails::ActiveRecord::Generator
14
14
 
15
15
  def pk_type: () -> String
16
16
 
17
+ def generated_relation_methods_decl: () -> String
18
+
17
19
  def relation_decl: () -> String
18
20
 
19
21
  def collection_proxy_decl: () -> String
@@ -30,6 +32,12 @@ class RbsRails::ActiveRecord::Generator
30
32
 
31
33
  def belongs_to: () -> String
32
34
 
35
+ def delegated_type_scope: (singleton: bool) -> String
36
+
37
+ def delegated_type_instance: () -> String
38
+
39
+ def delegated_type_definitions: () -> Array[{ role: Symbol, types: Array[String] }]?
40
+
33
41
  def enum_instance_methods: () -> String
34
42
 
35
43
  def enum_scope_methods: (singleton: untyped `singleton`) -> String
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.8.2
4
+ version: 0.9.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: 2021-02-20 00:00:00.000000000 Z
11
+ date: 2021-09-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parser
@@ -58,9 +58,7 @@ files:
58
58
  - Steepfile
59
59
  - bin/add-type-params.rb
60
60
  - bin/console
61
- - bin/gem_rbs
62
61
  - bin/postprocess.rb
63
- - bin/rbs
64
62
  - bin/rbs-prototype-rb.rb
65
63
  - bin/setup
66
64
  - bin/to-ascii.rb
@@ -71,6 +69,8 @@ files:
71
69
  - lib/rbs_rails/rake_task.rb
72
70
  - lib/rbs_rails/util.rb
73
71
  - lib/rbs_rails/version.rb
72
+ - rbs_collection.lock.yaml
73
+ - rbs_collection.yaml
74
74
  - rbs_rails.gemspec
75
75
  - sig/activerecord.rbs
76
76
  - sig/fileutils.rbs
@@ -105,7 +105,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
105
105
  - !ruby/object:Gem::Version
106
106
  version: '0'
107
107
  requirements: []
108
- rubygems_version: 3.2.3
108
+ rubygems_version: 3.3.0.dev
109
109
  signing_key:
110
110
  specification_version: 4
111
111
  summary: A RBS files generator for Rails application
data/bin/gem_rbs DELETED
@@ -1,94 +0,0 @@
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/rbs DELETED
@@ -1,30 +0,0 @@
1
- #!ruby
2
-
3
- require 'pathname'
4
- root = Pathname(__dir__) / '../'
5
-
6
- def v(require)
7
- if v = ENV['RAILS_VERSION']
8
- "#{require}:#{v}"
9
- else
10
- require
11
- end
12
- end
13
-
14
- def repo
15
- ENV['RBS_REPO_DIR'] || Pathname(__dir__).join('../gem_rbs/gems').to_s
16
- end
17
-
18
- exec(
19
- 'rbs',
20
- # Require stdlibs
21
- '-rlogger', '-rpathname', '-rmutex_m', '-rdate', '-rmonitor', '-rsingleton', '-rtsort',
22
- "--repo=#{repo}",
23
- # Require Rails libraries
24
- v('-ractivesupport'), v('-ractionpack'), v('-ractivejob'), v('-ractivemodel'), v('-ractionview'), v('-ractiverecord'), v('-rrailties'),
25
- # Load signatures that are bundled in rbs_rails
26
- '-I' + root.join('sig').to_s, '-I' + root.join('assets/sig').to_s,
27
- # Expand arguments
28
- *ARGV,
29
- )
30
-