rbs_rails 0.4.1 → 0.5.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: a95c070dd8a694d1226c7985be11458ebea02c89fda95c6bc0842c84fd44b69a
4
- data.tar.gz: 6e29540a2c6e0cb76b01ca08aa6081e4144260380900ecb632113eab04326ed6
3
+ metadata.gz: 820a0b86c257e12194d883e6f5edda1793b54cb789c2b57da2e496e16041c803
4
+ data.tar.gz: 173abfdce9274fc34671198b7640f5e84a92c8b0bb1a7ede8224cd2fb851137d
5
5
  SHA512:
6
- metadata.gz: b5ef79213cc6cbdb1e4d20ea901ccd65071c6c2fea5c9dc28cc80cb75739e712534ad2d7b19fa9c4174d7fee5da50e787d7ccb742933e51e7f337b4fc285838c
7
- data.tar.gz: ed7492f9b9b61fca7bc4d0ee52ebf9646d3127cf82c73d6b64d136d6c2cf248be86fa49a4324769bbde6d2304c5325be1e7cd6e7b6753e55d612f21627133f07
6
+ metadata.gz: 500bb14e66e9d6188d931e8a655b8af42b17caf13fa9487e8ad22318a54f34b5e05c412e65c2e68258d13165cb5760d09dc00d52d05b7cb9c9696e97dbbcc8bb
7
+ data.tar.gz: 86e1ec208cba577ce7ed5ac4a6b7bcd5ada10fe7d3ca0fd4ba5e014a68144bbe3182fcbd04145e9b9472be24a627eb0d5c3a2b7424661caae25d43507390d15a
@@ -0,0 +1,3 @@
1
+ [submodule "gem_rbs"]
2
+ path = gem_rbs
3
+ url = https://github.com/ruby/gem_rbs.git
data/README.md CHANGED
@@ -83,13 +83,25 @@ target :app do
83
83
 
84
84
  check 'app'
85
85
 
86
+ repo_path "path/to/rbs_repo"
87
+
86
88
  library 'pathname'
87
89
  library 'logger'
88
90
  library 'mutex_m'
89
91
  library 'date'
92
+
93
+ library 'activesupport'
94
+ library 'actionpack'
95
+ library 'activejob'
96
+ library 'activemodel'
97
+ library 'actionview'
98
+ library 'activerecord'
99
+ library 'railties'
90
100
  end
91
101
  ```
92
102
 
103
+ You need to put RBS repo to `path/to/rbs_repo`. See https://github.com/ruby/gem_rbs
104
+
93
105
  ## Development
94
106
 
95
107
  After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
data/Rakefile CHANGED
@@ -9,7 +9,8 @@ task :steep do
9
9
  end
10
10
 
11
11
  task :rbs_validate do
12
- sh 'bin/rbs validate --silent'
12
+ rbs = Pathname(__dir__).join('bin/rbs').to_s
13
+ sh "ruby #{rbs} validate --silent"
13
14
  end
14
15
 
15
16
  Rake::TestTask.new do |test|
data/Steepfile CHANGED
@@ -3,10 +3,18 @@ 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'
6
7
 
7
8
  library "pathname"
8
9
  library "logger"
9
10
  library "mutex_m"
10
11
  library "date"
11
- # library "strong_json" # Gems
12
+
13
+ library 'activesupport'
14
+ library 'actionpack'
15
+ library 'activejob'
16
+ library 'activemodel'
17
+ library 'actionview'
18
+ library 'activerecord'
19
+ library 'railties'
12
20
  end
@@ -4,7 +4,7 @@ require 'bundler/inline'
4
4
 
5
5
  gemfile do
6
6
  source 'https://rubygems.org'
7
- gem 'rbs', '>= 0.17'
7
+ gem 'rbs', '>= 0.19'
8
8
  end
9
9
 
10
10
  require 'rbs'
@@ -6,7 +6,7 @@ require 'bundler/inline'
6
6
 
7
7
  gemfile do
8
8
  source 'https://rubygems.org'
9
- gem 'rbs', '>= 0.17'
9
+ gem 'rbs', '>= 0.19.0'
10
10
  end
11
11
 
12
12
  require 'rbs'
data/bin/rbs CHANGED
@@ -1,3 +1,30 @@
1
- #!/bin/bash
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',
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
+ )
2
30
 
3
- rbs -rlogger -rpathname -rmutex_m -rdate -Isig -Iassets/sig $@
@@ -17,7 +17,7 @@ using Module.new {
17
17
  end
18
18
  end
19
19
 
20
- def process_class_methods(node, decls:, comments:, singleton:)
20
+ def process_class_methods(node, decls:, comments:, context:)
21
21
  return false unless node.type == :ITER
22
22
 
23
23
  fcall = node.children[0]
@@ -37,13 +37,13 @@ using Module.new {
37
37
  decls.push mod
38
38
 
39
39
  each_node [node.children[1]] do |child|
40
- process child, decls: mod.members, comments: comments, singleton: false
40
+ process child, decls: mod.members, comments: comments, context: RBS::Prototype::RB::Context.initial
41
41
  end
42
42
 
43
43
  true
44
44
  end
45
45
 
46
- def process_struct_new(node, decls:, comments:, singleton:)
46
+ def process_struct_new(node, decls:, comments:, context:)
47
47
  return unless node.type == :CDECL
48
48
 
49
49
  name, *_, rhs = node.children
@@ -78,13 +78,62 @@ using Module.new {
78
78
 
79
79
  if body
80
80
  each_node [body] do |child|
81
- process child, decls: kls.members, comments: comments, singleton: false
81
+ process child, decls: kls.members, comments: comments, context: RBS::Prototype::RB::Context.initial
82
82
  end
83
83
  end
84
84
 
85
85
  true
86
86
  end
87
87
 
88
+ def process_attr_internal(node, decls:, comments:, context:)
89
+ case node.type
90
+ when :FCALL, :VCALL
91
+ args = node.children[1]&.children || []
92
+
93
+ case node.children[0]
94
+ when :attr_internal_reader
95
+ args.each do |arg|
96
+ if arg && (name = literal_to_symbol(arg))
97
+ decls << RBS::AST::Members::AttrReader.new(
98
+ name: name,
99
+ ivar_name: :"@_#{name}",
100
+ type: RBS::Types::Bases::Any.new(location: nil),
101
+ location: nil,
102
+ comment: comments[node.first_lineno - 1],
103
+ annotations: []
104
+ )
105
+ end
106
+ end
107
+ when :attr_internal_writer
108
+ args.each do |arg|
109
+ if arg && (name = literal_to_symbol(arg))
110
+ decls << RBS::AST::Members::AttrWriter.new(
111
+ name: name,
112
+ ivar_name: :"@_#{name}",
113
+ type: RBS::Types::Bases::Any.new(location: nil),
114
+ location: nil,
115
+ comment: comments[node.first_lineno - 1],
116
+ annotations: []
117
+ )
118
+ end
119
+ end
120
+ when :attr_internal_accessor, :attr_internal
121
+ args.each do |arg|
122
+ if arg && (name = literal_to_symbol(arg))
123
+ decls << RBS::AST::Members::AttrAccessor.new(
124
+ name: name,
125
+ ivar_name: :"@_#{name}",
126
+ type: RBS::Types::Bases::Any.new(location: nil),
127
+ location: nil,
128
+ comment: comments[node.first_lineno - 1],
129
+ annotations: []
130
+ )
131
+ end
132
+ end
133
+ end
134
+ end
135
+ end
136
+
88
137
  def class_new_method_to_type(node)
89
138
  case node.type
90
139
  when :CALL
@@ -129,7 +178,7 @@ using Module.new {
129
178
 
130
179
  module PrototypeExt
131
180
  def process(...)
132
- process_class_methods(...) || process_struct_new(...) || super
181
+ process_class_methods(...) || process_struct_new(...) || process_attr_internal(...) || super
133
182
  end
134
183
 
135
184
  def literal_to_type(node)
@@ -154,6 +154,7 @@ module RbsRails
154
154
  return [] unless ast
155
155
 
156
156
  traverse(ast).map do |node|
157
+ # @type block: nil | Hash[untyped, untyped]
157
158
  next unless node.type == :send
158
159
  next unless node.children[0].nil?
159
160
  next unless node.children[1] == :enum
@@ -192,6 +193,7 @@ module RbsRails
192
193
  return '' unless ast
193
194
 
194
195
  traverse(ast).map do |node|
196
+ # @type block: nil | String
195
197
  next unless node.type == :send
196
198
  next unless node.children[0].nil?
197
199
  next unless node.children[1] == :scope
@@ -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.4.1"
5
+ VERSION = "0.5.0"
6
6
  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.1
4
+ version: 0.5.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-21 00:00:00.000000000 Z
11
+ date: 2020-12-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parser
@@ -46,39 +46,23 @@ extensions: []
46
46
  extra_rdoc_files: []
47
47
  files:
48
48
  - ".gitignore"
49
+ - ".gitmodules"
49
50
  - ".travis.yml"
50
51
  - Gemfile
51
52
  - LICENSE
52
53
  - README.md
53
54
  - Rakefile
54
55
  - Steepfile
55
- - assets/sig/action_controller.rbs
56
56
  - assets/sig/action_mailer.rbs
57
- - assets/sig/active_record.rbs
58
57
  - assets/sig/builtin.rbs
59
58
  - assets/sig/capybara.rbs
60
59
  - assets/sig/concurrent.rbs
61
60
  - assets/sig/erb.rbs
62
61
  - assets/sig/erubi.rbs
63
- - assets/sig/generated/actionpack.rbs
64
- - assets/sig/generated/actionview.rbs
65
- - assets/sig/generated/activejob.rbs
66
- - assets/sig/generated/activemodel.rbs
67
- - assets/sig/generated/activerecord-meta-programming.rbs
68
- - assets/sig/generated/activerecord.rbs
69
- - assets/sig/generated/activesupport.rbs
70
- - assets/sig/generated/railties.rbs
71
62
  - assets/sig/i18n.rbs
72
63
  - assets/sig/libxml.rbs
73
64
  - assets/sig/minitest.rbs
74
65
  - assets/sig/nokogiri.rbs
75
- - assets/sig/patches/README.md
76
- - assets/sig/patches/for_actionpack.rbs
77
- - assets/sig/patches/for_actionview.rbs
78
- - assets/sig/patches/for_activemodel.rbs
79
- - assets/sig/patches/for_activerecord.rbs
80
- - assets/sig/patches/for_activesupport.rbs
81
- - assets/sig/patches/for_railties.rbs
82
66
  - assets/sig/pg.rbs
83
67
  - assets/sig/que.rbs
84
68
  - assets/sig/queue_classic.rbs
@@ -95,7 +79,6 @@ files:
95
79
  - assets/sig/tzinfo.rbs
96
80
  - bin/add-type-params.rb
97
81
  - bin/console
98
- - bin/generate_rbs_from_rails_source_code.rb
99
82
  - bin/postprocess.rb
100
83
  - bin/rbs
101
84
  - bin/rbs-prototype-rb.rb
@@ -133,7 +116,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
133
116
  - !ruby/object:Gem::Version
134
117
  version: '0'
135
118
  requirements: []
136
- rubygems_version: 3.2.0.rc.2
119
+ rubygems_version: 3.2.1
137
120
  signing_key:
138
121
  specification_version: 4
139
122
  summary: A RBS files generator for Rails application
@@ -1,49 +0,0 @@
1
- interface _ActionController_API_and_Base
2
- def request: () -> untyped
3
- def params: () -> untyped
4
- def session: () -> untyped
5
- def cookies: () -> untyped
6
- def flash: () -> untyped
7
- def render: (*untyped) -> void
8
- def redirect_to: (*untyped) -> void
9
- end
10
-
11
- interface _ActionController_API_and_Base_singletion
12
- # hooks
13
- def before_action: (*untyped) -> void
14
- def around_action: (*untyped) -> void
15
- def after_action: (*untyped) -> void
16
- def skip_before_action: (*untyped) -> void
17
- def skip_around_action: (*untyped) -> void
18
- def skip_after_action: (*untyped) -> void
19
- def prepend_before_action: (*untyped) -> void
20
- def prepend_around_action: (*untyped) -> void
21
- def prepend_after_action: (*untyped) -> void
22
- def append_before_action: (*untyped) -> void
23
- def append_around_action: (*untyped) -> void
24
- def append_after_action: (*untyped) -> void
25
-
26
- def rescue_from: (*Class, ?with: Symbol | Proc) { (Exception) -> void } -> void
27
- end
28
-
29
- module AbstractController
30
- class Base
31
- end
32
- end
33
-
34
- module ActionController
35
- class Metal < ::AbstractController::Base
36
- end
37
-
38
- class Base < Metal
39
- include _ActionController_API_and_Base
40
- extend _ActionController_API_and_Base_singletion
41
- extend ::ActionView::Layouts::ClassMethods
42
- end
43
-
44
- class API < Metal
45
- include _ActionController_API_and_Base
46
- extend _ActionController_API_and_Base_singletion
47
- end
48
- end
49
-
@@ -1,137 +0,0 @@
1
- module ActiveRecord
2
- end
3
-
4
- class ActiveRecord::Base
5
- def self.abstract_class=: (bool) -> void
6
- def self.scope: (Symbol, ^(*untyped) -> untyped ) -> void
7
- | (Symbol) { (*untyped) -> untyped } -> void
8
- def self.belongs_to: (Symbol, ?untyped, **untyped) -> void
9
- def self.has_many: (Symbol, ?untyped, **untyped) -> void
10
- def self.has_one: (Symbol, ?untyped, **untyped) -> void
11
- def self.transaction: [T] () { () -> T } -> T
12
- def self.create!: (**untyped) -> instance
13
- def self.validate: (*untyped) -> void
14
- def self.validates: (*untyped) -> void
15
- def self.enum: (Hash[Symbol, untyped]) -> void
16
-
17
- # callbacks
18
- def self.after_commit: (*untyped) -> void
19
- def self.after_create: (*untyped) -> void
20
- def self.after_destroy: (*untyped) -> void
21
- def self.after_rollback: (*untyped) -> void
22
- def self.after_save: (*untyped) -> void
23
- def self.after_update: (*untyped) -> void
24
- def self.after_validation: (*untyped) -> void
25
- def self.around_create: (*untyped) -> void
26
- def self.around_destroy: (*untyped) -> void
27
- def self.around_save: (*untyped) -> void
28
- def self.around_update: (*untyped) -> void
29
- def self.before_create: (*untyped) -> void
30
- def self.before_destroy: (*untyped) -> void
31
- def self.before_save: (*untyped) -> void
32
- def self.before_update: (*untyped) -> void
33
- def self.before_validation: (*untyped) -> void
34
-
35
- def self.columns: () -> Array[untyped]
36
- def self.reflect_on_all_associations: (?Symbol) -> Array[untyped]
37
-
38
- def will_save_change_to_attribute?: (String | Symbol attr_name, ?from: untyped, ?to: untyped) -> bool
39
-
40
- def save!: (?validate: bool, ?touch: bool) -> self
41
- def save: () -> bool
42
- def update!: (*untyped) -> self
43
- def update: (*untyped) -> bool
44
- def destroy!: () -> self
45
- def destroy: () -> bool
46
- def valid?: () -> bool
47
- def invalid?: () -> bool
48
- def errors: () -> untyped
49
- def []: (Symbol) -> untyped
50
- def []=: (Symbol, untyped) -> untyped
51
- end
52
-
53
- class ActiveRecord::Relation
54
- end
55
-
56
- class ActiveRecord::Associations::CollectionProxy
57
- end
58
-
59
- interface _ActiveRecord_Relation[Model]
60
- def all: () -> self
61
- def ids: () -> Array[Integer]
62
- def none: () -> self
63
- def pluck: (Symbol | String column) -> Array[untyped]
64
- | (*Symbol | String columns) -> Array[Array[untyped]]
65
- def where: (*untyped) -> self
66
- def not: (*untyped) -> self
67
- def exists?: (*untyped) -> bool
68
- def order: (*untyped) -> self
69
- def group: (*Symbol | String) -> untyped
70
- def distinct: () -> self
71
- def or: (self) -> self
72
- def merge: (self) -> self
73
- def joins: (*String | Symbol) -> self
74
- | (Hash[untyped, untyped]) -> self
75
- def left_joins: (*String | Symbol) -> self
76
- | (Hash[untyped, untyped]) -> self
77
- def left_outer_joins: (*String | Symbol) -> self
78
- | (Hash[untyped, untyped]) -> self
79
- def includes: (*String | Symbol) -> self
80
- | (Hash[untyped, untyped]) -> self
81
- def eager_load: (*String | Symbol) -> self
82
- | (Hash[untyped, untyped]) -> self
83
- def preload: (*String | Symbol) -> self
84
- | (Hash[untyped, untyped]) -> self
85
- def find_by: (*untyped) -> Model?
86
- def find_by!: (*untyped) -> Model
87
- def find: (Integer id) -> Model
88
- def first: () -> Model
89
- | (Integer count) -> Array[Model]
90
- def last: () -> Model
91
- | (Integer count) -> Array[Model]
92
- def find_each: (?batch_size: Integer, ?start: Integer, ?finish: Integer, ?error_on_ignore: bool) { (Model) -> void } -> nil
93
- def find_in_batches: (?batch_size: Integer, ?start: Integer, ?finish: Integer, ?error_on_ignore: bool) { (self) -> void } -> nil
94
- def destroy_all: () -> untyped
95
- def delete_all: () -> untyped
96
- def update_all: (*untyped) -> untyped
97
- def each: () { (Model) -> void } -> self
98
- end
99
-
100
- interface _ActiveRecord_Relation_ClassMethods[Model, Relation]
101
- def all: () -> Relation
102
- def ids: () -> Array[Integer]
103
- def none: () -> Relation
104
- def pluck: (Symbol | String column) -> Array[untyped]
105
- | (*Symbol | String columns) -> Array[Array[untyped]]
106
- def where: (*untyped) -> Relation
107
- def exists?: (*untyped) -> bool
108
- def order: (*untyped) -> Relation
109
- def group: (*Symbol | String) -> untyped
110
- def distinct: () -> self
111
- def or: (Relation) -> Relation
112
- def merge: (Relation) -> Relation
113
- def joins: (*String | Symbol) -> self
114
- | (Hash[untyped, untyped]) -> self
115
- def left_joins: (*String | Symbol) -> self
116
- | (Hash[untyped, untyped]) -> self
117
- def left_outer_joins: (*String | Symbol) -> self
118
- | (Hash[untyped, untyped]) -> self
119
- def includes: (*String | Symbol) -> self
120
- | (Hash[untyped, untyped]) -> self
121
- def eager_load: (*String | Symbol) -> self
122
- | (Hash[untyped, untyped]) -> self
123
- def preload: (*String | Symbol) -> self
124
- | (Hash[untyped, untyped]) -> self
125
- def find_by: (*untyped) -> Model?
126
- def find_by!: (*untyped) -> Model
127
- def find: (Integer id) -> Model
128
- def first: () -> Model
129
- | (Integer count) -> Array[Model]
130
- def last: () -> Model
131
- | (Integer count) -> Array[Model]
132
- def find_each: (?batch_size: Integer, ?start: Integer, ?finish: Integer, ?error_on_ignore: bool) { (Model) -> void } -> nil
133
- def find_in_batches: (?batch_size: Integer, ?start: Integer, ?finish: Integer, ?error_on_ignore: bool) { (self) -> void } -> nil
134
- def destroy_all: () -> untyped
135
- def delete_all: () -> untyped
136
- def update_all: (*untyped) -> untyped
137
- end