rbs_rails 0.4.0 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitattributes +1 -0
- data/.github/workflows/ci.yml +18 -0
- data/.gitignore +3 -1
- data/.gitmodules +0 -0
- data/CHANGELOG.md +13 -0
- data/Gemfile +2 -2
- data/README.md +24 -43
- data/Rakefile +2 -1
- data/Steepfile +12 -1
- data/bin/add-type-params.rb +2 -1
- data/bin/gem_rbs +94 -0
- data/bin/postprocess.rb +1 -1
- data/bin/rbs +29 -2
- data/bin/rbs-prototype-rb.rb +59 -6
- data/lib/rbs_rails.rb +4 -0
- data/lib/rbs_rails/active_record.rb +74 -46
- data/lib/rbs_rails/dependency_builder.rb +43 -0
- data/lib/rbs_rails/rake_task.rb +73 -0
- data/lib/rbs_rails/util.rb +25 -0
- data/lib/rbs_rails/version.rb +1 -1
- data/rbs_rails.gemspec +3 -2
- data/sig/fileutils.rbs +1 -0
- data/sig/rake.rbs +6 -0
- data/sig/rbs_rails/active_record.rbs +8 -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 +30 -46
- data/.travis.yml +0 -11
- data/assets/sig/action_controller.rbs +0 -49
- data/assets/sig/action_mailer.rbs +0 -8
- data/assets/sig/active_record.rbs +0 -137
- 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/generated/actionpack.rbs +0 -11831
- data/assets/sig/generated/actionview.rbs +0 -10591
- data/assets/sig/generated/activejob.rbs +0 -1920
- data/assets/sig/generated/activemodel.rbs +0 -4214
- data/assets/sig/generated/activerecord-meta-programming.rbs +0 -98
- data/assets/sig/generated/activerecord.rbs +0 -24602
- data/assets/sig/generated/activesupport.rbs +0 -12613
- data/assets/sig/generated/railties.rbs +0 -4687
- 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/patches/README.md +0 -4
- data/assets/sig/patches/for_actionpack.rbs +0 -74
- data/assets/sig/patches/for_actionview.rbs +0 -19
- data/assets/sig/patches/for_activemodel.rbs +0 -11
- data/assets/sig/patches/for_activerecord.rbs +0 -84
- data/assets/sig/patches/for_activesupport.rbs +0 -48
- data/assets/sig/patches/for_railties.rbs +0 -30
- 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
- data/bin/generate_rbs_from_rails_source_code.rb +0 -195
data/assets/sig/sucker_punch.rbs
DELETED
data/assets/sig/thor.rbs
DELETED
data/assets/sig/tzinfo.rbs
DELETED
@@ -1,195 +0,0 @@
|
|
1
|
-
# Usage
|
2
|
-
#
|
3
|
-
# ruby bin/generate_rbs_from_rails_source_code.rb ../../rails/rails actionpack
|
4
|
-
|
5
|
-
require 'bundler/inline'
|
6
|
-
|
7
|
-
require 'pathname'
|
8
|
-
require 'open3'
|
9
|
-
|
10
|
-
SIG_DIR = Pathname('assets/sig/generated/')
|
11
|
-
|
12
|
-
def bin(c)
|
13
|
-
Pathname(__dir__).join(c).to_s
|
14
|
-
end
|
15
|
-
|
16
|
-
def sh!(*cmd, **kwargs)
|
17
|
-
puts(cmd.join(' '))
|
18
|
-
Open3.capture2(*cmd, **kwargs).then do |out, status|
|
19
|
-
raise unless status.success?
|
20
|
-
|
21
|
-
out
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
def patch!(name, rbs)
|
26
|
-
case name
|
27
|
-
when 'actionpack'
|
28
|
-
rbs.gsub!(/( def _reduce_\d+: \(untyped val, untyped _values\) -> )([A-Z]\w*)/) do
|
29
|
-
"#{$~[1]}Nodes::#{$~[2]}"
|
30
|
-
end || raise('it looks unnecessary.')
|
31
|
-
|
32
|
-
# XXX: I guess add-type-params.rb resolves this
|
33
|
-
rbs.gsub!('-> Parameter', '-> Parameter[untyped]') || raise('it looks unnecessary')
|
34
|
-
when 'railties'
|
35
|
-
rbs.gsub!(
|
36
|
-
'class NonSymbolAccessDeprecatedHash < HashWithIndifferentAccess',
|
37
|
-
'class NonSymbolAccessDeprecatedHash[T, U] < HashWithIndifferentAccess[T, U]')
|
38
|
-
# XXX: I guess add-type-params.rb resolves this
|
39
|
-
rbs.gsub!(
|
40
|
-
'def middleware: () -> Hash',
|
41
|
-
'def middleware: () -> Hash[untyped, untyped]')
|
42
|
-
# XXX: I guess add-type-params.rb resolves this
|
43
|
-
rbs.gsub!(
|
44
|
-
'def +: (untyped other) -> Collection',
|
45
|
-
'def +: (untyped other) -> Collection[untyped]')
|
46
|
-
# XXX: I guess add-type-params.rb resolves this
|
47
|
-
rbs.gsub!(
|
48
|
-
'def initializers_for: (untyped binding) -> Collection',
|
49
|
-
'def initializers_for: (untyped binding) -> Collection[untyped]')
|
50
|
-
when 'activesupport'
|
51
|
-
rbs.gsub!(
|
52
|
-
/^ include Java$/,
|
53
|
-
' # include Java # Java module is missing')
|
54
|
-
# XXX: I guess add-type-params.rb resolves this
|
55
|
-
rbs.gsub!(
|
56
|
-
'class Configuration < ActiveSupport::InheritableOptions',
|
57
|
-
'class Configuration[T, U] < ActiveSupport::InheritableOptions[T, U]')
|
58
|
-
# XXX: I guess add-type-params.rb resolves this
|
59
|
-
rbs.gsub!(
|
60
|
-
'class InheritableOptions < OrderedOptions',
|
61
|
-
'class InheritableOptions[T, U] < OrderedOptions[T, U]')
|
62
|
-
rbs.gsub!( # ref: 5c507aaae492ff5b2002fdd3ece2044b283b5d6f
|
63
|
-
'include ActiveSupport::Logger::Severity',
|
64
|
-
'include ::Logger::Severity')
|
65
|
-
# XXX: I guess add-type-params.rb resolves this
|
66
|
-
rbs.gsub!(
|
67
|
-
'def with_indifferent_access: () -> ActiveSupport::HashWithIndifferentAccess',
|
68
|
-
'def with_indifferent_access: () -> ActiveSupport::HashWithIndifferentAccess[K, V]')
|
69
|
-
# XXX: I guess add-type-params.rb resolves this
|
70
|
-
rbs.gsub!(
|
71
|
-
'def inquiry: () -> ActiveSupport::ArrayInquirer',
|
72
|
-
'def inquiry: () -> ActiveSupport::ArrayInquirer[Elem]')
|
73
|
-
|
74
|
-
# These aliases are actually defined, but it causes duplicated method definition
|
75
|
-
rbs.gsub!('alias to_s to_formatted_s', '')
|
76
|
-
rbs.gsub!('alias + plus_with_duration', '')
|
77
|
-
rbs.gsub!('alias - minus_with_duration', '')
|
78
|
-
rbs.gsub!('alias - minus_with_coercion', '')
|
79
|
-
rbs.gsub!('alias <=> compare_with_coercion', '')
|
80
|
-
rbs.gsub!('alias eql? eql_with_coercion', '')
|
81
|
-
rbs.gsub!('alias self.at self.at_with_coercion', '')
|
82
|
-
rbs.gsub!('alias inspect readable_inspect', '')
|
83
|
-
rbs.gsub!('alias default_inspect inspect', '')
|
84
|
-
|
85
|
-
rbs.gsub!('HashWithIndifferentAccess: untyped', <<~RBS)
|
86
|
-
# NOTE: HashWithIndifferentAccess and ActiveSupport::HashWithIndifferentAccess are the same object
|
87
|
-
# but RBS doesn't have class alias syntax
|
88
|
-
class HashWithIndifferentAccess[T, U] < ActiveSupport::HashWithIndifferentAccess[T, U]
|
89
|
-
end
|
90
|
-
RBS
|
91
|
-
when 'actionview'
|
92
|
-
rbs.gsub!(
|
93
|
-
'class CheckBoxBuilder < Builder',
|
94
|
-
'class CheckBoxBuilder < CollectionHelpers::Builder')
|
95
|
-
rbs.gsub!(
|
96
|
-
'class RadioButtonBuilder < Builder',
|
97
|
-
'class RadioButtonBuilder < CollectionHelpers::Builder')
|
98
|
-
rbs.gsub!('TemplateError: untyped', <<~RBS)
|
99
|
-
# It is actual TemplateError = Template::Error, but we can't write it in RBS
|
100
|
-
class TemplateError < Template::Error
|
101
|
-
end
|
102
|
-
RBS
|
103
|
-
when 'activerecord'
|
104
|
-
rbs.gsub!(':==', 'Symbol') # To avoid syntax error
|
105
|
-
|
106
|
-
rbs.gsub!(
|
107
|
-
'< Type::Value',
|
108
|
-
'< ActiveModel::Type::Value')
|
109
|
-
rbs.gsub!(
|
110
|
-
'< Type::Binary',
|
111
|
-
'< ActiveModel::Type::Binary')
|
112
|
-
rbs.gsub!(
|
113
|
-
'< Type::Decimal',
|
114
|
-
'< ActiveModel::Type::Decimal')
|
115
|
-
rbs.gsub!(
|
116
|
-
'< Type::String',
|
117
|
-
'< ActiveModel::Type::String')
|
118
|
-
rbs.gsub!(
|
119
|
-
'< Type::Integer',
|
120
|
-
'< ActiveModel::Type::Integer')
|
121
|
-
|
122
|
-
rbs.gsub!(
|
123
|
-
'class SchemaDumper < SchemaDumper',
|
124
|
-
'class SchemaDumper < ActiveRecord::SchemaDumper')
|
125
|
-
rbs.gsub!(
|
126
|
-
'def schema_creation: () -> SchemaCreation',
|
127
|
-
'def schema_creation: () -> untyped')
|
128
|
-
rbs.gsub!('V6_0: untyped', <<~RBS)
|
129
|
-
# V6_0 and Current are the same object actually. hack for https://github.com/ruby/rbs/issues/345
|
130
|
-
class V6_0 < Current
|
131
|
-
end
|
132
|
-
RBS
|
133
|
-
rbs.gsub!('alias numeric decimal', '')
|
134
|
-
|
135
|
-
# XXX: I guess add-type-params.rb resolves this
|
136
|
-
rbs.gsub!(
|
137
|
-
'-> ColumnDefinition',
|
138
|
-
'-> ColumnDefinition[untyped]')
|
139
|
-
# XXX: I guess add-type-params.rb resolves this
|
140
|
-
rbs.gsub!(
|
141
|
-
'def build_point: (untyped x, untyped y) -> ActiveRecord::Point',
|
142
|
-
'def build_point: (untyped x, untyped y) -> ActiveRecord::Point[untyped]')
|
143
|
-
# XXX: I guess add-type-params.rb resolves this
|
144
|
-
rbs.gsub!(
|
145
|
-
'class NullMigration < MigrationProxy',
|
146
|
-
'class NullMigration[T] < MigrationProxy[T]')
|
147
|
-
# XXX: I guess add-type-params.rb resolves this
|
148
|
-
rbs.gsub!(
|
149
|
-
'-> JoinKeys',
|
150
|
-
'-> JoinKeys[untyped]')
|
151
|
-
# XXX: I guess add-type-params.rb resolves this
|
152
|
-
rbs.gsub!(
|
153
|
-
'def row_num_literal: (untyped order_by) -> RowNumber',
|
154
|
-
'def row_num_literal: (untyped order_by) -> RowNumber[untyped]')
|
155
|
-
|
156
|
-
rbs.gsub!(
|
157
|
-
'def get_database_version: () -> Version',
|
158
|
-
'def get_database_version: () -> AbstractAdapter::Version')
|
159
|
-
rbs.gsub!(
|
160
|
-
'def get_database_version: () -> SQLite3Adapter::Version',
|
161
|
-
'def get_database_version: () -> AbstractAdapter::Version')
|
162
|
-
rbs.gsub!(
|
163
|
-
'def []: (untyped name) -> Attribute',
|
164
|
-
'def []: (untyped name) -> ::Arel::Attributes::Attribute')
|
165
|
-
|
166
|
-
end
|
167
|
-
end
|
168
|
-
|
169
|
-
def generate!(rails_code_dir, name)
|
170
|
-
files = Pathname(rails_code_dir).join(name, 'lib').glob('**/*.rb').map(&:to_s)
|
171
|
-
generated_rbs_path = SIG_DIR.join("#{name}.rbs")
|
172
|
-
|
173
|
-
rbs = sh! 'ruby', bin("rbs-prototype-rb.rb"), 'prototype', 'rb', *files
|
174
|
-
rbs.gsub!(/^(?<indent>\s*)class (?<name>\S+) < $/) { "#{$~[:indent]}class #{$~[:name]} # Note: It inherits unnamed class, but omitted" }
|
175
|
-
rbs.gsub!(/[^[:ascii:]]+/, '(trim non-ascii characters)')
|
176
|
-
patch! name, rbs
|
177
|
-
generated_rbs_path.write(rbs)
|
178
|
-
|
179
|
-
rbs = sh! 'ruby', bin('add-type-params.rb'), generated_rbs_path.to_s
|
180
|
-
generated_rbs_path.write(rbs)
|
181
|
-
|
182
|
-
sh!({ 'ONLY' => name }, 'ruby', bin('postprocess.rb'), '-rlogger', '-rmutex_m', '-Iassets/sig', '-Isig', 'assets/')
|
183
|
-
end
|
184
|
-
|
185
|
-
def main(rails_code_dir, name)
|
186
|
-
if name == 'all'
|
187
|
-
%w[actionpack activejob railties activemodel activesupport actionview activerecord].each do |n|
|
188
|
-
generate!(rails_code_dir, n)
|
189
|
-
end
|
190
|
-
else
|
191
|
-
generate!(rails_code_dir, name)
|
192
|
-
end
|
193
|
-
end
|
194
|
-
|
195
|
-
main(*ARGV)
|