rbs_rails 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +3 -0
- data/Gemfile +3 -2
- data/README.md +1 -0
- data/Rakefile +10 -2
- data/Steepfile +1 -0
- data/assets/sig/active_record.rbs +1 -1
- data/assets/sig/generated/actionpack.rbs +697 -543
- data/assets/sig/generated/actionview.rbs +313 -213
- data/assets/sig/generated/activejob.rbs +1920 -0
- data/assets/sig/generated/activemodel.rbs +690 -615
- data/assets/sig/generated/activerecord.rbs +5521 -4942
- data/assets/sig/generated/activesupport.rbs +1613 -1207
- data/assets/sig/generated/railties.rbs +426 -386
- data/assets/sig/patches/README.md +4 -0
- data/assets/sig/patches/for_actionpack.rbs +74 -0
- data/assets/sig/patches/for_actionview.rbs +19 -0
- data/assets/sig/patches/for_activemodel.rbs +11 -0
- data/assets/sig/patches/for_activerecord.rbs +84 -0
- data/assets/sig/patches/for_activesupport.rbs +48 -0
- data/assets/sig/patches/for_railties.rbs +30 -0
- 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/rack.rbs +1 -0
- data/assets/sig/sidekiq.rbs +4 -0
- data/assets/sig/sneakers.rbs +4 -0
- data/assets/sig/sucker_punch.rbs +4 -0
- data/bin/add-type-params.rb +7 -0
- data/bin/generate_rbs_from_rails_source_code.rb +195 -0
- data/bin/postprocess.rb +15 -6
- data/bin/rbs +1 -1
- data/lib/rbs_rails/active_record.rb +40 -10
- data/lib/rbs_rails/version.rb +1 -1
- metadata +18 -3
data/bin/postprocess.rb
CHANGED
@@ -2,21 +2,26 @@
|
|
2
2
|
|
3
3
|
# TODO: Expose me to user
|
4
4
|
|
5
|
+
require 'bundler/inline'
|
6
|
+
|
7
|
+
gemfile do
|
8
|
+
source 'https://rubygems.org'
|
9
|
+
gem 'rbs', '>= 0.16'
|
10
|
+
end
|
11
|
+
|
5
12
|
require 'rbs'
|
6
13
|
require 'rbs/cli'
|
7
14
|
require 'optparse'
|
8
15
|
|
9
16
|
def env(options:)
|
10
|
-
loader =
|
11
|
-
options.setup(loader)
|
17
|
+
loader = options.loader
|
12
18
|
RBS::Environment.from_loader(loader).resolve_type_names
|
13
19
|
end
|
14
20
|
|
15
21
|
def parse_option(argv)
|
16
22
|
opt = OptionParser.new
|
17
23
|
options = RBS::CLI::LibraryOptions.new
|
18
|
-
|
19
|
-
cli.library_parse(opt, options: options)
|
24
|
+
options.setup_library_options(opt)
|
20
25
|
|
21
26
|
return opt.parse(argv), options
|
22
27
|
end
|
@@ -79,8 +84,10 @@ def may_eql_member?(a, b)
|
|
79
84
|
a.name.to_s.split('::').last == b.name.to_s.split('::').last
|
80
85
|
end
|
81
86
|
|
82
|
-
def update!(update_targets:)
|
87
|
+
def update!(update_targets:, only:)
|
83
88
|
update_targets.group_by { |decl, _concern| decl.location.name }.each do |fname, target_decls|
|
89
|
+
next unless only.match?(fname)
|
90
|
+
|
84
91
|
tree = RBS::Parser.parse_signature(File.read(fname))
|
85
92
|
target_decls.each do |target_decl, concern|
|
86
93
|
catch(:break) do
|
@@ -109,6 +116,8 @@ def run(argv)
|
|
109
116
|
builder = RBS::DefinitionBuilder.new(env: env)
|
110
117
|
matcher = FileMatcher.new(targets: targets)
|
111
118
|
|
119
|
+
only = ENV['ONLY']&.then { Regexp.new(_1) } || //
|
120
|
+
|
112
121
|
update_targets = []
|
113
122
|
|
114
123
|
env.class_decls.each do |_name, entry|
|
@@ -122,7 +131,7 @@ def run(argv)
|
|
122
131
|
end
|
123
132
|
end
|
124
133
|
|
125
|
-
update!(update_targets: update_targets)
|
134
|
+
update!(update_targets: update_targets, only: only)
|
126
135
|
end
|
127
136
|
|
128
137
|
run(ARGV)
|
data/bin/rbs
CHANGED
@@ -66,21 +66,45 @@ module RbsRails
|
|
66
66
|
|
67
67
|
private def has_many
|
68
68
|
klass.reflect_on_all_associations(:has_many).map do |a|
|
69
|
-
|
69
|
+
singular_name = a.name.to_s.singularize
|
70
|
+
type = a.klass.name
|
71
|
+
collection_type = "#{type}::ActiveRecord_Associations_CollectionProxy"
|
72
|
+
<<~RUBY.chomp
|
73
|
+
def #{a.name}: () -> #{collection_type}
|
74
|
+
def #{a.name}=: (#{collection_type} | Array[#{type}]) -> (#{collection_type} | Array[#{type}])
|
75
|
+
def #{singular_name}_ids: () -> Array[Integer]
|
76
|
+
def #{singular_name}_ids=: (Array[Integer]) -> Array[Integer]
|
77
|
+
RUBY
|
70
78
|
end.join("\n")
|
71
79
|
end
|
72
80
|
|
73
81
|
private def has_one
|
74
82
|
klass.reflect_on_all_associations(:has_one).map do |a|
|
75
83
|
type = a.polymorphic? ? 'untyped' : a.klass.name
|
76
|
-
|
84
|
+
type_optional = optional(type)
|
85
|
+
<<~RUBY.chomp
|
86
|
+
def #{a.name}: () -> #{type}
|
87
|
+
def #{a.name}=: (#{type_optional}) -> #{type_optional}
|
88
|
+
def build_#{a.name}: (untyped) -> #{type}
|
89
|
+
def create_#{a.name}: (untyped) -> #{type}
|
90
|
+
def create_#{a.name}!: (untyped) -> #{type}
|
91
|
+
def reload_#{a.name}: () -> #{type_optional}
|
92
|
+
RUBY
|
77
93
|
end.join("\n")
|
78
94
|
end
|
79
95
|
|
80
96
|
private def belongs_to
|
81
97
|
klass.reflect_on_all_associations(:belongs_to).map do |a|
|
82
98
|
type = a.polymorphic? ? 'untyped' : a.klass.name
|
83
|
-
|
99
|
+
type_optional = optional(type)
|
100
|
+
<<~RUBY.chomp
|
101
|
+
def #{a.name}: () -> #{type}
|
102
|
+
def #{a.name}=: (#{type_optional}) -> #{type_optional}
|
103
|
+
def build_#{a.name}: (untyped) -> #{type}
|
104
|
+
def create_#{a.name}: (untyped) -> #{type}
|
105
|
+
def create_#{a.name}!: (untyped) -> #{type}
|
106
|
+
def reload_#{a.name}: () -> #{type_optional}
|
107
|
+
RUBY
|
84
108
|
end.join("\n")
|
85
109
|
end
|
86
110
|
|
@@ -238,7 +262,11 @@ module RbsRails
|
|
238
262
|
|
239
263
|
private def columns
|
240
264
|
klass.columns.map do |col|
|
241
|
-
class_name =
|
265
|
+
class_name = if enum_definitions.any? { |hash| hash.key?(col.name) || hash.key?(col.name.to_sym) }
|
266
|
+
'String'
|
267
|
+
else
|
268
|
+
sql_type_to_class(col.type)
|
269
|
+
end
|
242
270
|
class_name_opt = optional(class_name)
|
243
271
|
column_type = col.null ? class_name_opt : class_name
|
244
272
|
sig = <<~EOS
|
@@ -265,15 +293,17 @@ module RbsRails
|
|
265
293
|
private def sql_type_to_class(t)
|
266
294
|
case t
|
267
295
|
when :integer
|
268
|
-
Integer
|
296
|
+
'Integer'
|
269
297
|
when :float
|
270
|
-
Float
|
271
|
-
when :
|
272
|
-
|
298
|
+
'Float'
|
299
|
+
when :decimal
|
300
|
+
'BigDecimal'
|
301
|
+
when :string, :text, :citext, :uuid, :binary
|
302
|
+
'String'
|
273
303
|
when :datetime
|
274
304
|
# TODO
|
275
305
|
# ActiveSupport::TimeWithZone.name
|
276
|
-
Time
|
306
|
+
'Time'
|
277
307
|
when :boolean
|
278
308
|
"TrueClass | FalseClass"
|
279
309
|
when :jsonb, :json
|
@@ -283,7 +313,7 @@ module RbsRails
|
|
283
313
|
# Date.name
|
284
314
|
'untyped'
|
285
315
|
when :time
|
286
|
-
Time
|
316
|
+
'Time'
|
287
317
|
when :inet
|
288
318
|
"IPAddr"
|
289
319
|
else
|
data/lib/rbs_rails/version.rb
CHANGED
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.4.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-
|
11
|
+
date: 2020-11-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: parser
|
@@ -48,6 +48,7 @@ files:
|
|
48
48
|
- assets/sig/erubi.rbs
|
49
49
|
- assets/sig/generated/actionpack.rbs
|
50
50
|
- assets/sig/generated/actionview.rbs
|
51
|
+
- assets/sig/generated/activejob.rbs
|
51
52
|
- assets/sig/generated/activemodel.rbs
|
52
53
|
- assets/sig/generated/activerecord-meta-programming.rbs
|
53
54
|
- assets/sig/generated/activerecord.rbs
|
@@ -57,16 +58,30 @@ files:
|
|
57
58
|
- assets/sig/libxml.rbs
|
58
59
|
- assets/sig/minitest.rbs
|
59
60
|
- assets/sig/nokogiri.rbs
|
61
|
+
- assets/sig/patches/README.md
|
62
|
+
- assets/sig/patches/for_actionpack.rbs
|
63
|
+
- assets/sig/patches/for_actionview.rbs
|
64
|
+
- assets/sig/patches/for_activemodel.rbs
|
65
|
+
- assets/sig/patches/for_activerecord.rbs
|
66
|
+
- assets/sig/patches/for_activesupport.rbs
|
67
|
+
- assets/sig/patches/for_railties.rbs
|
68
|
+
- assets/sig/pg.rbs
|
69
|
+
- assets/sig/que.rbs
|
70
|
+
- assets/sig/queue_classic.rbs
|
60
71
|
- assets/sig/racc.rbs
|
61
72
|
- assets/sig/rack-test.rbs
|
62
73
|
- assets/sig/rack.rbs
|
63
74
|
- assets/sig/rails.rbs
|
64
75
|
- assets/sig/rdoc.rbs
|
76
|
+
- assets/sig/sidekiq.rbs
|
77
|
+
- assets/sig/sneakers.rbs
|
65
78
|
- assets/sig/stdlib.rbs
|
79
|
+
- assets/sig/sucker_punch.rbs
|
66
80
|
- assets/sig/thor.rbs
|
67
81
|
- assets/sig/tzinfo.rbs
|
68
82
|
- bin/add-type-params.rb
|
69
83
|
- bin/console
|
84
|
+
- bin/generate_rbs_from_rails_source_code.rb
|
70
85
|
- bin/postprocess.rb
|
71
86
|
- bin/rbs
|
72
87
|
- bin/rbs-prototype-rb.rb
|
@@ -104,7 +119,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
104
119
|
- !ruby/object:Gem::Version
|
105
120
|
version: '0'
|
106
121
|
requirements: []
|
107
|
-
rubygems_version: 3.2.0.rc.
|
122
|
+
rubygems_version: 3.2.0.rc.2
|
108
123
|
signing_key:
|
109
124
|
specification_version: 4
|
110
125
|
summary: A RBS files generator for Rails application
|