rbs-siggen 0.2.0 → 0.2.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c368db792e08e8417cfc36a43cac9aa49e33eeeaf60c39cc7700db494832553b
4
- data.tar.gz: 11ac12278d9d200e6258fb7230623213e3342006d138127b17f5fd24a454919d
3
+ metadata.gz: 06e23d1dc2eadd500a4871c55965497aa433e702c1a14702d3b6b92b62052d4d
4
+ data.tar.gz: 53f2519a3398677095889d18254eaf3dc4cdbc2e0619f6c30ec642ab897ebc30
5
5
  SHA512:
6
- metadata.gz: d0ece64d8a739c938ad31197082f29fb7db72141a3932512117ea8e42073c56002b6db12fc4fdd130e25bc1d4c78178b1a39345299726344bebdab59a8059ed0
7
- data.tar.gz: aec7870eb75d4fb9d568a546218d4807e1190ac9521b7e50392e0aac4089f79abc5bf6303c621cfddb6f54f44883ba6b0f0e4683a4855308b46147091173eb5c
6
+ metadata.gz: 830a11c06f15f3f2308370732726cb6d2b33f41102fca4c185b64b00f21aa6e06ebc5f4733522e47a817b496b03315d21d625fc701308def69001bf5c9838ffa
7
+ data.tar.gz: 983da6e48b25425bc98d9637c625d19ab1a21d6c5d9ad3a071d8bb926746f6c1e93fc243dcf6585ea3a1e75a99b057192dccb7f89df96308488573a6b7bb2686
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RBS
4
4
  class Siggen
5
- VERSION = "0.2.0"
5
+ VERSION = "0.2.1"
6
6
  end
7
7
  end
data/lib/rbs/siggen.rb CHANGED
@@ -35,6 +35,8 @@ module RBS
35
35
  def analyze(path:)
36
36
  ruby_files = Dir.glob(path) + Dir.glob("#{path}/**/*.rb")
37
37
  ruby_files.each do |file|
38
+ next unless File.file?(file)
39
+
38
40
  analyze_ruby(File.read(file), name: file)
39
41
  yield self, file
40
42
  end
@@ -106,6 +108,10 @@ module RBS
106
108
 
107
109
  @typing = typing
108
110
  @node = source.node
111
+ @source = source
112
+ @context = context
113
+ @checker = checker
114
+ @annotations = annotations
109
115
  # steep:ignore:end
110
116
  end
111
117
 
@@ -138,7 +144,7 @@ module RBS
138
144
  io = ::StringIO.new
139
145
  ::RBS::Writer.new(out: io).write(merge_class_declarations(decls))
140
146
  io.rewind
141
- io.readlines.reject { |line| line.strip.empty? }.join
147
+ io.read || ""
142
148
  end
143
149
 
144
150
  #: (Parser::AST::Node node, ?Array[untyped] stack) ?{ (String, untyped, Hash[untyped, untyped]) -> void } -> void
@@ -171,7 +177,7 @@ module RBS
171
177
  end
172
178
  arg_hash.merge!(create_arg_hash(node, method_decl))
173
179
 
174
- annos.each { |anno| yield(create_class_name(method_decl), anno, arg_hash) }
180
+ annos.each { |anno| yield(create_class_name(self_type_of(node), method_decl), anno, arg_hash) }
175
181
  end
176
182
 
177
183
  if node.type == :block
@@ -188,10 +194,24 @@ module RBS
188
194
  end
189
195
  end
190
196
 
191
- #: (untyped) -> String
192
- def create_class_name(method_decl)
193
- receiver_type = method_decl.method_name.type_name.relative!
194
- "#{receiver_type.namespace}#{receiver_type.name}"
197
+ #: (Parser::AST::Node) -> untyped
198
+ def self_type_of(node)
199
+ # steep:ignore:start
200
+ typing = Steep::Typing.new(source: @source, root_context: @context, cursor: node.loc.expression.begin_pos)
201
+ construction = Steep::TypeConstruction.new(checker: @checker,
202
+ source: @source,
203
+ annotations: @annotations,
204
+ context: @context,
205
+ typing: typing)
206
+ construction.synthesize(@source.node) unless @source.node.nil?
207
+ # steep:ignore:end
208
+ typing.cursor_context.context&.self_type
209
+ end
210
+
211
+ #: (untyped, untyped) -> String
212
+ def create_class_name(reciver_type, method_decl)
213
+ type = reciver_type&.name&.relative! || method_decl.method_name.type_name.relative!
214
+ "#{type.namespace}#{type.name}"
195
215
  end
196
216
 
197
217
  #: (Parser::AST::Node, untyped) -> Hash[Symbol, untyped]
@@ -26,8 +26,11 @@ module RBS
26
26
  # : (Parser::AST::Node node, ?Array[untyped] stack) ?{ (String, untyped, Hash[untyped, untyped]) -> void } -> void
27
27
  def traverse: (Parser::AST::Node node, ?Array[untyped] stack) ?{ (String, untyped, Hash[untyped, untyped]) -> void } -> void
28
28
 
29
- # : (untyped) -> String
30
- def create_class_name: (untyped) -> String
29
+ # : (Parser::AST::Node) -> untyped
30
+ def self_type_of: (Parser::AST::Node) -> untyped
31
+
32
+ # : (untyped, untyped) -> String
33
+ def create_class_name: (untyped, untyped) -> String
31
34
 
32
35
  # : (Parser::AST::Node, untyped) -> Hash[Symbol, untyped]
33
36
  def create_arg_hash: (Parser::AST::Node, untyped) -> Hash[Symbol, untyped]
@@ -2,9 +2,11 @@ module ActiveRecord
2
2
  class Schema
3
3
  def self.[]: (untyped version) -> ActiveRecord::Migration::Current
4
4
  end
5
+
5
6
  class Migration
6
7
  class Current
7
8
  def define: (version: untyped) { () [self: instance] -> void } -> void
9
+
8
10
  %a{siggen:
9
11
  # In schema.rb, this model is declared as:
10
12
  #
@@ -18,6 +20,7 @@ module ActiveRecord
18
20
  def create_table: (untyped table_name, **untyped options) { (ActiveRecord::ConnectionAdapters::ColumnMethods t) -> void } -> void
19
21
  end
20
22
  end
23
+
21
24
  module ConnectionAdapters
22
25
  module ColumnMethods
23
26
  %a{siggen:
@@ -36,12 +39,27 @@ module ActiveRecord
36
39
  # See the documentation comment for the delegated method below:
37
40
  #
38
41
  # <%= ___comment_of["ActiveRecord::AttributeMethods::Read#read_attribute"] %>
39
- def <%= name %>: () -> ::String<%= "?" unless options[:null] == false %>
42
+ def <%= name %>: () -> ::Integer<%= "?" unless options[:null] == false %>
43
+
44
+ # In schema.rb, this column is declared as:
45
+ #
46
+ # ```ruby
47
+ # <%= ___source %>
48
+ # ```
49
+ #
50
+ # This method delegates to `ActiveRecord::AttributeMethods::Write` `#_write_attribute`,
51
+ # passing `"<%= name %>"` as the `attr_name` argument.
52
+ #
53
+ # See the documentation comment for the delegated method below:
54
+ #
55
+ # <%= ___comment_of["ActiveRecord::AttributeMethods::Write#write_attribute"] %>
56
+ def <%= name %>=: (::Integer<%= "?" unless options[:null] == false %> value) -> void
40
57
  <% end %>
41
58
  end
42
59
  end
43
60
  }
44
- def text: (*Array[untyped] names, **untyped options) -> void
61
+ def bitint: (*Array[untyped] names, **untyped options) -> void
62
+
45
63
  %a{siggen:
46
64
  class <%= create_table.table_name.classify %>
47
65
  module GeneratedAttributeMethods
@@ -59,11 +77,100 @@ module ActiveRecord
59
77
  #
60
78
  # <%= ___comment_of["ActiveRecord::AttributeMethods::Read#read_attribute"] %>
61
79
  def <%= name %>: () -> ::String<%= "?" unless options[:null] == false %>
80
+
81
+ # In schema.rb, this column is declared as:
82
+ #
83
+ # ```ruby
84
+ # <%= ___source %>
85
+ # ```
86
+ #
87
+ # This method delegates to `ActiveRecord::AttributeMethods::Write` `#_write_attribute`,
88
+ # passing `"<%= name %>"` as the `attr_name` argument.
89
+ #
90
+ # See the documentation comment for the delegated method below:
91
+ #
92
+ # <%= ___comment_of["ActiveRecord::AttributeMethods::Write#write_attribute"] %>
93
+ def <%= name %>=: (::String<%= "?" unless options[:null] == false %> value) -> void
62
94
  <% end %>
63
95
  end
64
96
  end
65
97
  }
66
- def string: (*Array[untyped] names, **untyped options) -> void
98
+ def binary: (*Array[untyped] names, **untyped options) -> void
99
+
100
+ %a{siggen:
101
+ class <%= create_table.table_name.classify %>
102
+ module GeneratedAttributeMethods
103
+ <% names.each do |name| %>
104
+ # In schema.rb, this column is declared as:
105
+ #
106
+ # ```ruby
107
+ # <%= ___source %>
108
+ # ```
109
+ #
110
+ # This method delegates to `ActiveRecord::AttributeMethods::Read` `#_read_attribute`,
111
+ # passing `"<%= name %>"` as the `attr_name` argument.
112
+ #
113
+ # See the documentation comment for the delegated method below:
114
+ #
115
+ # <%= ___comment_of["ActiveRecord::AttributeMethods::Read#read_attribute"] %>
116
+ def <%= name %>: () -> bool<%= "?" unless options[:null] == false %>
117
+
118
+ # In schema.rb, this column is declared as:
119
+ #
120
+ # ```ruby
121
+ # <%= ___source %>
122
+ # ```
123
+ #
124
+ # This method delegates to `ActiveRecord::AttributeMethods::Write` `#_write_attribute`,
125
+ # passing `"<%= name %>"` as the `attr_name` argument.
126
+ #
127
+ # See the documentation comment for the delegated method below:
128
+ #
129
+ # <%= ___comment_of["ActiveRecord::AttributeMethods::Write#write_attribute"] %>
130
+ def <%= name %>=: (bool<%= "?" unless options[:null] == false %> value) -> void
131
+ <% end %>
132
+ end
133
+ end
134
+ }
135
+ def boolean: (*Array[untyped] names, **untyped options) -> void
136
+
137
+ %a{siggen:
138
+ class <%= create_table.table_name.classify %>
139
+ module GeneratedAttributeMethods
140
+ <% names.each do |name| %>
141
+ # In schema.rb, this column is declared as:
142
+ #
143
+ # ```ruby
144
+ # <%= ___source %>
145
+ # ```
146
+ #
147
+ # This method delegates to `ActiveRecord::AttributeMethods::Read` `#_read_attribute`,
148
+ # passing `"<%= name %>"` as the `attr_name` argument.
149
+ #
150
+ # See the documentation comment for the delegated method below:
151
+ #
152
+ # <%= ___comment_of["ActiveRecord::AttributeMethods::Read#read_attribute"] %>
153
+ def <%= name %>: () -> ::Date<%= "?" unless options[:null] == false %>
154
+
155
+ # In schema.rb, this column is declared as:
156
+ #
157
+ # ```ruby
158
+ # <%= ___source %>
159
+ # ```
160
+ #
161
+ # This method delegates to `ActiveRecord::AttributeMethods::Write` `#_write_attribute`,
162
+ # passing `"<%= name %>"` as the `attr_name` argument.
163
+ #
164
+ # See the documentation comment for the delegated method below:
165
+ #
166
+ # <%= ___comment_of["ActiveRecord::AttributeMethods::Write#write_attribute"] %>
167
+ def <%= name %>=: (::Date<%= "?" unless options[:null] == false %> value) -> void
168
+ <% end %>
169
+ end
170
+ end
171
+ }
172
+ def date: (*Array[untyped] names, **untyped options) -> void
173
+
67
174
  %a{siggen:
68
175
  class <%= create_table.table_name.classify %>
69
176
  module GeneratedAttributeMethods
@@ -81,11 +188,100 @@ module ActiveRecord
81
188
  #
82
189
  # <%= ___comment_of["ActiveRecord::AttributeMethods::Read#read_attribute"] %>
83
190
  def <%= name %>: () -> ::ActiveSupport::TimeWithZone<%= "?" unless options[:null] == false %>
191
+
192
+ # In schema.rb, this column is declared as:
193
+ #
194
+ # ```ruby
195
+ # <%= ___source %>
196
+ # ```
197
+ #
198
+ # This method delegates to `ActiveRecord::AttributeMethods::Write` `#_write_attribute`,
199
+ # passing `"<%= name %>"` as the `attr_name` argument.
200
+ #
201
+ # See the documentation comment for the delegated method below:
202
+ #
203
+ # <%= ___comment_of["ActiveRecord::AttributeMethods::Write#write_attribute"] %>
204
+ def <%= name %>=: (::ActiveSupport::TimeWithZone<%= "?" unless options[:null] == false %> value) -> void
84
205
  <% end %>
85
206
  end
86
207
  end
87
208
  }
88
209
  def datetime: (*Array[untyped] names, **untyped options) -> void
210
+
211
+ %a{siggen:
212
+ class <%= create_table.table_name.classify %>
213
+ module GeneratedAttributeMethods
214
+ <% names.each do |name| %>
215
+ # In schema.rb, this column is declared as:
216
+ #
217
+ # ```ruby
218
+ # <%= ___source %>
219
+ # ```
220
+ #
221
+ # This method delegates to `ActiveRecord::AttributeMethods::Read` `#_read_attribute`,
222
+ # passing `"<%= name %>"` as the `attr_name` argument.
223
+ #
224
+ # See the documentation comment for the delegated method below:
225
+ #
226
+ # <%= ___comment_of["ActiveRecord::AttributeMethods::Read#read_attribute"] %>
227
+ def <%= name %>: () -> ::BigDecimal<%= "?" unless options[:null] == false %>
228
+
229
+ # In schema.rb, this column is declared as:
230
+ #
231
+ # ```ruby
232
+ # <%= ___source %>
233
+ # ```
234
+ #
235
+ # This method delegates to `ActiveRecord::AttributeMethods::Write` `#_write_attribute`,
236
+ # passing `"<%= name %>"` as the `attr_name` argument.
237
+ #
238
+ # See the documentation comment for the delegated method below:
239
+ #
240
+ # <%= ___comment_of["ActiveRecord::AttributeMethods::Write#write_attribute"] %>
241
+ def <%= name %>=: (::BigDecimal<%= "?" unless options[:null] == false %> value) -> void
242
+ <% end %>
243
+ end
244
+ end
245
+ }
246
+ def decimal: (*Array[untyped] names, **untyped options) -> void
247
+
248
+ %a{siggen:
249
+ class <%= create_table.table_name.classify %>
250
+ module GeneratedAttributeMethods
251
+ <% names.each do |name| %>
252
+ # In schema.rb, this column is declared as:
253
+ #
254
+ # ```ruby
255
+ # <%= ___source %>
256
+ # ```
257
+ #
258
+ # This method delegates to `ActiveRecord::AttributeMethods::Read` `#_read_attribute`,
259
+ # passing `"<%= name %>"` as the `attr_name` argument.
260
+ #
261
+ # See the documentation comment for the delegated method below:
262
+ #
263
+ # <%= ___comment_of["ActiveRecord::AttributeMethods::Read#read_attribute"] %>
264
+ def <%= name %>: () -> ::Float<%= "?" unless options[:null] == false %>
265
+
266
+ # In schema.rb, this column is declared as:
267
+ #
268
+ # ```ruby
269
+ # <%= ___source %>
270
+ # ```
271
+ #
272
+ # This method delegates to `ActiveRecord::AttributeMethods::Write` `#_write_attribute`,
273
+ # passing `"<%= name %>"` as the `attr_name` argument.
274
+ #
275
+ # See the documentation comment for the delegated method below:
276
+ #
277
+ # <%= ___comment_of["ActiveRecord::AttributeMethods::Write#write_attribute"] %>
278
+ def <%= name %>=: (::Float<%= "?" unless options[:null] == false %> value) -> void
279
+ <% end %>
280
+ end
281
+ end
282
+ }
283
+ def float: (*Array[untyped] names, **untyped options) -> void
284
+
89
285
  %a{siggen:
90
286
  class <%= create_table.table_name.classify %>
91
287
  module GeneratedAttributeMethods
@@ -103,12 +299,251 @@ module ActiveRecord
103
299
  #
104
300
  # <%= ___comment_of["ActiveRecord::AttributeMethods::Read#read_attribute"] %>
105
301
  def <%= name %>: () -> ::Integer<%= "?" unless options[:null] == false %>
302
+
303
+ # In schema.rb, this column is declared as:
304
+ #
305
+ # ```ruby
306
+ # <%= ___source %>
307
+ # ```
308
+ #
309
+ # This method delegates to `ActiveRecord::AttributeMethods::Write` `#_write_attribute`,
310
+ # passing `"<%= name %>"` as the `attr_name` argument.
311
+ #
312
+ # See the documentation comment for the delegated method below:
313
+ #
314
+ # <%= ___comment_of["ActiveRecord::AttributeMethods::Write#write_attribute"] %>
315
+ def <%= name %>=: (::Integer<%= "?" unless options[:null] == false %> value) -> void
106
316
  <% end %>
107
317
  end
108
318
  end
109
319
  }
110
320
  def integer: (*Array[untyped] names, **untyped options) -> void
321
+
322
+ %a{siggen:
323
+ class <%= create_table.table_name.classify %>
324
+ module GeneratedAttributeMethods
325
+ <% names.each do |name| %>
326
+ # In schema.rb, this column is declared as:
327
+ #
328
+ # ```ruby
329
+ # <%= ___source %>
330
+ # ```
331
+ #
332
+ # This method delegates to `ActiveRecord::AttributeMethods::Read` `#_read_attribute`,
333
+ # passing `"<%= name %>"` as the `attr_name` argument.
334
+ #
335
+ # See the documentation comment for the delegated method below:
336
+ #
337
+ # <%= ___comment_of["ActiveRecord::AttributeMethods::Read#read_attribute"] %>
338
+ def <%= name %>: () -> untyped<%= "?" unless options[:null] == false %>
339
+
340
+ # In schema.rb, this column is declared as:
341
+ #
342
+ # ```ruby
343
+ # <%= ___source %>
344
+ # ```
345
+ #
346
+ # This method delegates to `ActiveRecord::AttributeMethods::Write` `#_write_attribute`,
347
+ # passing `"<%= name %>"` as the `attr_name` argument.
348
+ #
349
+ # See the documentation comment for the delegated method below:
350
+ #
351
+ # <%= ___comment_of["ActiveRecord::AttributeMethods::Write#write_attribute"] %>
352
+ def <%= name %>=: (untyped<%= "?" unless options[:null] == false %> value) -> void
353
+ <% end %>
354
+ end
355
+ end
356
+ }
357
+ def json: (*Array[untyped] names, **untyped options) -> void
358
+
359
+ %a{siggen:
360
+ class <%= create_table.table_name.classify %>
361
+ module GeneratedAttributeMethods
362
+ <% names.each do |name| %>
363
+ # In schema.rb, this column is declared as:
364
+ #
365
+ # ```ruby
366
+ # <%= ___source %>
367
+ # ```
368
+ #
369
+ # This method delegates to `ActiveRecord::AttributeMethods::Read` `#_read_attribute`,
370
+ # passing `"<%= name %>"` as the `attr_name` argument.
371
+ #
372
+ # See the documentation comment for the delegated method below:
373
+ #
374
+ # <%= ___comment_of["ActiveRecord::AttributeMethods::Read#read_attribute"] %>
375
+ def <%= name %>: () -> ::String<%= "?" unless options[:null] == false %>
376
+
377
+ # In schema.rb, this column is declared as:
378
+ #
379
+ # ```ruby
380
+ # <%= ___source %>
381
+ # ```
382
+ #
383
+ # This method delegates to `ActiveRecord::AttributeMethods::Write` `#_write_attribute`,
384
+ # passing `"<%= name %>"` as the `attr_name` argument.
385
+ #
386
+ # See the documentation comment for the delegated method below:
387
+ #
388
+ # <%= ___comment_of["ActiveRecord::AttributeMethods::Write#write_attribute"] %>
389
+ def <%= name %>=: (::String<%= "?" unless options[:null] == false %> value) -> void
390
+ <% end %>
391
+ end
392
+ end
393
+ }
394
+ def string: (*Array[untyped] names, **untyped options) -> void
395
+
396
+ %a{siggen:
397
+ class <%= create_table.table_name.classify %>
398
+ module GeneratedAttributeMethods
399
+ <% names.each do |name| %>
400
+ # In schema.rb, this column is declared as:
401
+ #
402
+ # ```ruby
403
+ # <%= ___source %>
404
+ # ```
405
+ #
406
+ # This method delegates to `ActiveRecord::AttributeMethods::Read` `#_read_attribute`,
407
+ # passing `"<%= name %>"` as the `attr_name` argument.
408
+ #
409
+ # See the documentation comment for the delegated method below:
410
+ #
411
+ # <%= ___comment_of["ActiveRecord::AttributeMethods::Read#read_attribute"] %>
412
+ def <%= name %>: () -> ::String<%= "?" unless options[:null] == false %>
413
+
414
+ # In schema.rb, this column is declared as:
415
+ #
416
+ # ```ruby
417
+ # <%= ___source %>
418
+ # ```
419
+ #
420
+ # This method delegates to `ActiveRecord::AttributeMethods::Write` `#_write_attribute`,
421
+ # passing `"<%= name %>"` as the `attr_name` argument.
422
+ #
423
+ # See the documentation comment for the delegated method below:
424
+ #
425
+ # <%= ___comment_of["ActiveRecord::AttributeMethods::Write#write_attribute"] %>
426
+ def <%= name %>=: (::String<%= "?" unless options[:null] == false %> value) -> void
427
+ <% end %>
428
+ end
429
+ end
430
+ }
431
+ def text: (*Array[untyped] names, **untyped options) -> void
432
+
433
+ %a{siggen:
434
+ class <%= create_table.table_name.classify %>
435
+ module GeneratedAttributeMethods
436
+ <% names.each do |name| %>
437
+ # In schema.rb, this column is declared as:
438
+ #
439
+ # ```ruby
440
+ # <%= ___source %>
441
+ # ```
442
+ #
443
+ # This method delegates to `ActiveRecord::AttributeMethods::Read` `#_read_attribute`,
444
+ # passing `"<%= name %>"` as the `attr_name` argument.
445
+ #
446
+ # See the documentation comment for the delegated method below:
447
+ #
448
+ # <%= ___comment_of["ActiveRecord::AttributeMethods::Read#read_attribute"] %>
449
+ def <%= name %>: () -> ::ActiveSupport::TimeWithZone<%= "?" unless options[:null] == false %>
450
+
451
+ # In schema.rb, this column is declared as:
452
+ #
453
+ # ```ruby
454
+ # <%= ___source %>
455
+ # ```
456
+ #
457
+ # This method delegates to `ActiveRecord::AttributeMethods::Write` `#_write_attribute`,
458
+ # passing `"<%= name %>"` as the `attr_name` argument.
459
+ #
460
+ # See the documentation comment for the delegated method below:
461
+ #
462
+ # <%= ___comment_of["ActiveRecord::AttributeMethods::Write#write_attribute"] %>
463
+ def <%= name %>=: (::ActiveSupport::TimeWithZone<%= "?" unless options[:null] == false %> value) -> void
464
+ <% end %>
465
+ end
466
+ end
467
+ }
468
+ def time: (*Array[untyped] names, **untyped options) -> void
469
+
470
+ %a{siggen:
471
+ class <%= create_table.table_name.classify %>
472
+ module GeneratedAttributeMethods
473
+ <% names.each do |name| %>
474
+ # In schema.rb, this column is declared as:
475
+ #
476
+ # ```ruby
477
+ # <%= ___source %>
478
+ # ```
479
+ #
480
+ # This method delegates to `ActiveRecord::AttributeMethods::Read` `#_read_attribute`,
481
+ # passing `"<%= name %>"` as the `attr_name` argument.
482
+ #
483
+ # See the documentation comment for the delegated method below:
484
+ #
485
+ # <%= ___comment_of["ActiveRecord::AttributeMethods::Read#read_attribute"] %>
486
+ def <%= name %>: () -> ::ActiveSupport::TimeWithZone<%= "?" unless options[:null] == false %>
487
+
488
+ # In schema.rb, this column is declared as:
489
+ #
490
+ # ```ruby
491
+ # <%= ___source %>
492
+ # ```
493
+ #
494
+ # This method delegates to `ActiveRecord::AttributeMethods::Write` `#_write_attribute`,
495
+ # passing `"<%= name %>"` as the `attr_name` argument.
496
+ #
497
+ # See the documentation comment for the delegated method below:
498
+ #
499
+ # <%= ___comment_of["ActiveRecord::AttributeMethods::Write#write_attribute"] %>
500
+ def <%= name %>=: (::ActiveSupport::TimeWithZone<%= "?" unless options[:null] == false %> value) -> void
501
+ <% end %>
502
+ end
503
+ end
504
+ }
505
+ def timestamp: (*Array[untyped] names, **untyped options) -> void
506
+
507
+ %a{siggen:
508
+ <% map = [[:bitint, "::Integer"], [:binary, "::String"], [:boolean, "bool"], [:date, "::Date"], [:datetime, "::ActiveSupport::TimeWithZone"], [:decimal, "::BigDecimal"], [:float, "::Float"], [:integer, "::Integer"], [:json, "untyped"], [:string, "::String"], [:text, "::String"], [:time, "::ActiveSupport::TimeWithZone"], [:timestamp, "::ActiveSupport::TimeWithZone"], [:virtual, "_"]].to_h %>
509
+ class <%= create_table.table_name.classify %>
510
+ module GeneratedAttributeMethods
511
+ <% names.each do |name| %>
512
+ # In schema.rb, this column is declared as:
513
+ #
514
+ # ```ruby
515
+ # <%= ___source %>
516
+ # ```
517
+ #
518
+ # This method delegates to `ActiveRecord::AttributeMethods::Read` `#_read_attribute`,
519
+ # passing `"<%= name %>"` as the `attr_name` argument.
520
+ #
521
+ # See the documentation comment for the delegated method below:
522
+ #
523
+ # <%= ___comment_of["ActiveRecord::AttributeMethods::Read#read_attribute"] %>
524
+ def <%= name %>: () -> <%= map[options[:type]] %><%= "?" unless options[:null] == false %>
525
+
526
+ # In schema.rb, this column is declared as:
527
+ #
528
+ # ```ruby
529
+ # <%= ___source %>
530
+ # ```
531
+ #
532
+ # This method delegates to `ActiveRecord::AttributeMethods::Write` `#_write_attribute`,
533
+ # passing `"<%= name %>"` as the `attr_name` argument.
534
+ #
535
+ # See the documentation comment for the delegated method below:
536
+ #
537
+ # <%= ___comment_of["ActiveRecord::AttributeMethods::Write#write_attribute"] %>
538
+ def <%= name %>=: (<%= map[options[:type]] %><%= "?" unless options[:null] == false %> value) -> void
539
+ <% end %>
540
+ end
541
+ end
542
+ }
543
+ def virtual: (*Array[untyped] names, **untyped options) -> void
544
+
111
545
  end
546
+
112
547
  class TableDefinition
113
548
  include ColumnMethods
114
549
  end
@@ -3,9 +3,11 @@ module ActiveRecord
3
3
  class Schema
4
4
  def self.[]: (untyped version) -> ActiveRecord::Migration::Current
5
5
  end
6
+
6
7
  class Migration
7
8
  class Current
8
9
  def define: (version: untyped) { () [self: instance] -> void } -> void
10
+
9
11
  %a{siggen:
10
12
  # In schema.rb, this model is declared as:
11
13
  #
@@ -19,13 +21,36 @@ module ActiveRecord
19
21
  def create_table: (untyped table_name, **untyped options) { (ActiveRecord::ConnectionAdapters::ColumnMethods t) -> void } -> void
20
22
  end
21
23
  end
24
+
22
25
  module ConnectionAdapters
23
26
  module ColumnMethods
24
- <%- { text: "::String", string: "::String", datetime: "::ActiveSupport::TimeWithZone", integer: "::Integer" }.each do |key, type| -%>
27
+ <%- map = {
28
+ # https://github.com/rails/rails/blob/v8.1.2/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb#L331-L332
29
+ bitint: "::Integer",
30
+ binary: "::String",
31
+ boolean: "bool",
32
+ date: "::Date",
33
+ datetime: "::ActiveSupport::TimeWithZone",
34
+ decimal: "::BigDecimal",
35
+ float: "::Float",
36
+ integer: "::Integer",
37
+ json: "untyped",
38
+ string: "::String",
39
+ text: "::String",
40
+ time: "::ActiveSupport::TimeWithZone",
41
+ timestamp: "::ActiveSupport::TimeWithZone",
42
+ virtual: "_",
43
+ }
44
+ map.each do |key, type| -%>
25
45
  %a{siggen:
46
+ <%- if key == :virtual -%>
47
+ <%% map = <%= map.to_a %>.to_h %>
48
+ <%- type = "<" + "%= map[options[:type]] %" + ">" -%>
49
+ <%- end -%>
26
50
  class <%%= create_table.table_name.classify %>
27
51
  module GeneratedAttributeMethods
28
52
  <%% names.each do |name| %>
53
+ <%-# https://github.com/rails/rails/blob/v8.1.2/activerecord/lib/active_record/attribute_methods/read.rb -%>
29
54
  # In schema.rb, this column is declared as:
30
55
  #
31
56
  # ```ruby
@@ -39,13 +64,30 @@ module ActiveRecord
39
64
  #
40
65
  # <%%= ___comment_of["ActiveRecord::AttributeMethods::Read#read_attribute"] %>
41
66
  def <%%= name %>: () -> <%= type %><%%= "?" unless options[:null] == false %>
67
+
68
+ <%-# https://github.com/rails/rails/blob/v8.1.2/activerecord/lib/active_record/attribute_methods/write.rb -%>
69
+ # In schema.rb, this column is declared as:
70
+ #
71
+ # ```ruby
72
+ # <%%= ___source %>
73
+ # ```
74
+ #
75
+ # This method delegates to `ActiveRecord::AttributeMethods::Write` `#_write_attribute`,
76
+ # passing `"<%%= name %>"` as the `attr_name` argument.
77
+ #
78
+ # See the documentation comment for the delegated method below:
79
+ #
80
+ # <%%= ___comment_of["ActiveRecord::AttributeMethods::Write#write_attribute"] %>
81
+ def <%%= name %>=: (<%= type %><%%= "?" unless options[:null] == false %> value) -> void
42
82
  <%% end %>
43
83
  end
44
84
  end
45
85
  }
46
86
  def <%= key %>: (*Array[untyped] names, **untyped options) -> void
87
+
47
88
  <%- end -%>
48
89
  end
90
+
49
91
  class TableDefinition
50
92
  include ColumnMethods
51
93
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbs-siggen
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Koji NAKAMURA