rbs_rails 0.3.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +18 -0
  3. data/.gitignore +3 -0
  4. data/.gitmodules +0 -0
  5. data/CHANGELOG.md +8 -0
  6. data/Gemfile +3 -2
  7. data/README.md +23 -43
  8. data/Rakefile +11 -2
  9. data/Steepfile +10 -1
  10. data/assets/sig/pg.rbs +5 -0
  11. data/assets/sig/que.rbs +4 -0
  12. data/assets/sig/queue_classic.rbs +4 -0
  13. data/assets/sig/rack.rbs +1 -0
  14. data/assets/sig/rails.rbs +1 -5
  15. data/assets/sig/sidekiq.rbs +4 -0
  16. data/assets/sig/sneakers.rbs +4 -0
  17. data/assets/sig/sucker_punch.rbs +4 -0
  18. data/bin/add-type-params.rb +7 -0
  19. data/bin/gem_rbs +94 -0
  20. data/bin/postprocess.rb +15 -6
  21. data/bin/rbs +29 -2
  22. data/bin/rbs-prototype-rb.rb +59 -6
  23. data/lib/rbs_rails.rb +4 -0
  24. data/lib/rbs_rails/active_record.rb +100 -50
  25. data/lib/rbs_rails/dependency_builder.rb +43 -0
  26. data/lib/rbs_rails/rake_task.rb +83 -0
  27. data/lib/rbs_rails/util.rb +25 -0
  28. data/lib/rbs_rails/version.rb +1 -1
  29. data/rbs_rails.gemspec +2 -1
  30. data/sig/fileutils.rbs +1 -0
  31. data/sig/rake.rbs +6 -0
  32. data/sig/rbs_rails/active_record.rbs +8 -2
  33. data/sig/rbs_rails/dependency_builder.rbs +9 -0
  34. data/sig/rbs_rails/rake_task.rbs +26 -0
  35. data/sig/rbs_rails/util.rbs +11 -0
  36. metadata +34 -13
  37. data/.travis.yml +0 -8
  38. data/assets/sig/action_controller.rbs +0 -49
  39. data/assets/sig/active_record.rbs +0 -137
  40. data/assets/sig/generated/actionpack.rbs +0 -11677
  41. data/assets/sig/generated/actionview.rbs +0 -10491
  42. data/assets/sig/generated/activemodel.rbs +0 -4139
  43. data/assets/sig/generated/activerecord-meta-programming.rbs +0 -98
  44. data/assets/sig/generated/activerecord.rbs +0 -24023
  45. data/assets/sig/generated/activesupport.rbs +0 -12207
  46. data/assets/sig/generated/railties.rbs +0 -4647
@@ -0,0 +1,25 @@
1
+ module RbsRails
2
+ module Util
3
+ MODULE_NAME = Module.instance_method(:name)
4
+
5
+ extend self
6
+
7
+ if '2.7' <= RUBY_VERSION
8
+ def module_name(mod)
9
+ # HACK: RBS doesn't have UnboundMethod#bind_call
10
+ (_ = MODULE_NAME).bind_call(mod)
11
+ end
12
+ else
13
+ def module_name(mod)
14
+ MODULE_NAME.bind(mod).call
15
+ end
16
+ end
17
+
18
+ def format_rbs(rbs)
19
+ decls = RBS::Parser.parse_signature(rbs)
20
+ StringIO.new.tap do |io|
21
+ RBS::Writer.new(out: io).write(decls)
22
+ end.string
23
+ end
24
+ end
25
+ end
@@ -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.3.0"
5
+ VERSION = "0.7.0"
6
6
  end
@@ -19,11 +19,12 @@ Gem::Specification.new do |spec|
19
19
  # Specify which files should be added to the gem when it is released.
20
20
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
21
21
  spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
22
- `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
22
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features|gem_rbs)/}) }
23
23
  end
24
24
  spec.bindir = "exe"
25
25
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
26
26
  spec.require_paths = ["lib"]
27
27
 
28
28
  spec.add_runtime_dependency 'parser'
29
+ spec.add_runtime_dependency 'rbs', '>= 1'
29
30
  end
@@ -1,3 +1,4 @@
1
1
  module FileUtils
2
2
  def self.cp_r: (Pathname, Pathname) -> untyped
3
+ def self.mkdir_p: (String | Array[String], ?untyped) -> Array[String]
3
4
  end
@@ -0,0 +1,6 @@
1
+ module Rake
2
+ class TaskLib
3
+ def desc: (String) -> void
4
+ def task: (Hash[Symbol, Symbol | Array[Symbol]]) ?{ () -> void } -> void
5
+ end
6
+ end
@@ -1,11 +1,11 @@
1
1
  module RbsRails::ActiveRecord
2
- def self.class_to_rbs: (untyped klass) -> untyped
2
+ def self.class_to_rbs: (untyped klass, ?dependencies: Array[String]) -> untyped
3
3
  end
4
4
 
5
5
  class RbsRails::ActiveRecord::Generator
6
6
  @parse_model_file: nil | Parser::AST::Node
7
7
 
8
- def initialize: (singleton(ActiveRecord::Base) klass) -> untyped
8
+ def initialize: (singleton(ActiveRecord::Base) klass, dependencies: Array[String]) -> untyped
9
9
 
10
10
  def generate: () -> String
11
11
 
@@ -17,6 +17,8 @@ class RbsRails::ActiveRecord::Generator
17
17
 
18
18
  def header: () -> String
19
19
 
20
+ def footer: () -> String
21
+
20
22
  def associations: () -> String
21
23
 
22
24
  def has_many: () -> String
@@ -55,5 +57,9 @@ class RbsRails::ActiveRecord::Generator
55
57
 
56
58
  def optional: (String) -> String
57
59
 
60
+ private
61
+
58
62
  attr_reader klass: singleton(ActiveRecord::Base)
63
+
64
+ attr_reader klass_name: String
59
65
  end
@@ -0,0 +1,9 @@
1
+ module RbsRails
2
+ class DependencyBuilder
3
+ attr_reader deps: Array[String]
4
+
5
+ def initialize: () -> void
6
+
7
+ def build: () -> (String | nil)
8
+ end
9
+ end
@@ -0,0 +1,26 @@
1
+ module RbsRails
2
+ class RakeTask < Rake::TaskLib
3
+ interface _Filter
4
+ def call: (Class) -> boolish
5
+ end
6
+ attr_accessor ignore_model_if: _Filter | nil
7
+
8
+ attr_accessor name: Symbol
9
+
10
+ attr_accessor signature_root_dir: Pathname
11
+
12
+ def initialize: (?::Symbol name) { (self) -> void } -> void
13
+
14
+ def def_all: () -> void
15
+
16
+ def def_copy_signature_files: () -> void
17
+
18
+ def def_generate_rbs_for_models: () -> void
19
+
20
+ def def_generate_rbs_for_path_helpers: () -> void
21
+
22
+ private
23
+
24
+ def setup_signature_root_dir!: () -> void
25
+ end
26
+ end
@@ -0,0 +1,11 @@
1
+ module RbsRails
2
+ module Util
3
+ MODULE_NAME: UnboundMethod
4
+
5
+ extend Util
6
+
7
+ def module_name: (Module) -> String
8
+
9
+ def format_rbs: (String) -> String
10
+ end
11
+ 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.3.0
4
+ version: 0.7.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-08-01 00:00:00.000000000 Z
11
+ date: 2020-12-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parser
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rbs
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '1'
27
41
  description: A RBS files generator for Rails application
28
42
  email:
29
43
  - kuwabara@pocke.me
@@ -31,42 +45,42 @@ executables: []
31
45
  extensions: []
32
46
  extra_rdoc_files: []
33
47
  files:
48
+ - ".github/workflows/ci.yml"
34
49
  - ".gitignore"
35
- - ".travis.yml"
50
+ - ".gitmodules"
51
+ - CHANGELOG.md
36
52
  - Gemfile
37
53
  - LICENSE
38
54
  - README.md
39
55
  - Rakefile
40
56
  - Steepfile
41
- - assets/sig/action_controller.rbs
42
57
  - assets/sig/action_mailer.rbs
43
- - assets/sig/active_record.rbs
44
58
  - assets/sig/builtin.rbs
45
59
  - assets/sig/capybara.rbs
46
60
  - assets/sig/concurrent.rbs
47
61
  - assets/sig/erb.rbs
48
62
  - assets/sig/erubi.rbs
49
- - assets/sig/generated/actionpack.rbs
50
- - assets/sig/generated/actionview.rbs
51
- - assets/sig/generated/activemodel.rbs
52
- - assets/sig/generated/activerecord-meta-programming.rbs
53
- - assets/sig/generated/activerecord.rbs
54
- - assets/sig/generated/activesupport.rbs
55
- - assets/sig/generated/railties.rbs
56
63
  - assets/sig/i18n.rbs
57
64
  - assets/sig/libxml.rbs
58
65
  - assets/sig/minitest.rbs
59
66
  - assets/sig/nokogiri.rbs
67
+ - assets/sig/pg.rbs
68
+ - assets/sig/que.rbs
69
+ - assets/sig/queue_classic.rbs
60
70
  - assets/sig/racc.rbs
61
71
  - assets/sig/rack-test.rbs
62
72
  - assets/sig/rack.rbs
63
73
  - assets/sig/rails.rbs
64
74
  - assets/sig/rdoc.rbs
75
+ - assets/sig/sidekiq.rbs
76
+ - assets/sig/sneakers.rbs
65
77
  - assets/sig/stdlib.rbs
78
+ - assets/sig/sucker_punch.rbs
66
79
  - assets/sig/thor.rbs
67
80
  - assets/sig/tzinfo.rbs
68
81
  - bin/add-type-params.rb
69
82
  - bin/console
83
+ - bin/gem_rbs
70
84
  - bin/postprocess.rb
71
85
  - bin/rbs
72
86
  - bin/rbs-prototype-rb.rb
@@ -74,14 +88,21 @@ files:
74
88
  - bin/to-ascii.rb
75
89
  - lib/rbs_rails.rb
76
90
  - lib/rbs_rails/active_record.rb
91
+ - lib/rbs_rails/dependency_builder.rb
77
92
  - lib/rbs_rails/path_helpers.rb
93
+ - lib/rbs_rails/rake_task.rb
94
+ - lib/rbs_rails/util.rb
78
95
  - lib/rbs_rails/version.rb
79
96
  - rbs_rails.gemspec
80
97
  - sig/fileutils.rbs
81
98
  - sig/parser.rbs
99
+ - sig/rake.rbs
82
100
  - sig/rbs_rails.rbs
83
101
  - sig/rbs_rails/active_record.rbs
102
+ - sig/rbs_rails/dependency_builder.rbs
84
103
  - sig/rbs_rails/path_helpers.rbs
104
+ - sig/rbs_rails/rake_task.rbs
105
+ - sig/rbs_rails/util.rbs
85
106
  - sig/rbs_rails/version.rbs
86
107
  homepage: https://github.com/pocke/rbs_rails
87
108
  licenses:
@@ -104,7 +125,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
104
125
  - !ruby/object:Gem::Version
105
126
  version: '0'
106
127
  requirements: []
107
- rubygems_version: 3.2.0.rc.1
128
+ rubygems_version: 3.1.4
108
129
  signing_key:
109
130
  specification_version: 4
110
131
  summary: A RBS files generator for Rails application
@@ -1,8 +0,0 @@
1
- language: ruby
2
-
3
- rvm:
4
- - 2.6.5
5
- - 2.7.0
6
- - ruby-head
7
-
8
- cache: bundler
@@ -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!: () -> 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