tapioca 0.4.27 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +14 -14
  3. data/README.md +2 -2
  4. data/Rakefile +5 -7
  5. data/exe/tapioca +2 -2
  6. data/lib/tapioca/cli.rb +256 -2
  7. data/lib/tapioca/compilers/dsl/aasm.rb +122 -0
  8. data/lib/tapioca/compilers/dsl/action_controller_helpers.rb +52 -12
  9. data/lib/tapioca/compilers/dsl/action_mailer.rb +6 -9
  10. data/lib/tapioca/compilers/dsl/active_job.rb +8 -12
  11. data/lib/tapioca/compilers/dsl/active_model_attributes.rb +131 -0
  12. data/lib/tapioca/compilers/dsl/active_record_associations.rb +33 -54
  13. data/lib/tapioca/compilers/dsl/active_record_columns.rb +10 -105
  14. data/lib/tapioca/compilers/dsl/active_record_enum.rb +8 -10
  15. data/lib/tapioca/compilers/dsl/active_record_scope.rb +7 -10
  16. data/lib/tapioca/compilers/dsl/active_record_typed_store.rb +5 -8
  17. data/lib/tapioca/compilers/dsl/active_resource.rb +9 -37
  18. data/lib/tapioca/compilers/dsl/active_storage.rb +98 -0
  19. data/lib/tapioca/compilers/dsl/active_support_concern.rb +108 -0
  20. data/lib/tapioca/compilers/dsl/active_support_current_attributes.rb +13 -8
  21. data/lib/tapioca/compilers/dsl/base.rb +96 -82
  22. data/lib/tapioca/compilers/dsl/config.rb +111 -0
  23. data/lib/tapioca/compilers/dsl/frozen_record.rb +5 -7
  24. data/lib/tapioca/compilers/dsl/identity_cache.rb +66 -29
  25. data/lib/tapioca/compilers/dsl/protobuf.rb +19 -69
  26. data/lib/tapioca/compilers/dsl/sidekiq_worker.rb +25 -12
  27. data/lib/tapioca/compilers/dsl/smart_properties.rb +19 -31
  28. data/lib/tapioca/compilers/dsl/state_machines.rb +56 -78
  29. data/lib/tapioca/compilers/dsl/url_helpers.rb +7 -10
  30. data/lib/tapioca/compilers/dsl_compiler.rb +22 -38
  31. data/lib/tapioca/compilers/requires_compiler.rb +2 -2
  32. data/lib/tapioca/compilers/sorbet.rb +26 -5
  33. data/lib/tapioca/compilers/symbol_table/symbol_generator.rb +138 -153
  34. data/lib/tapioca/compilers/symbol_table/symbol_loader.rb +4 -4
  35. data/lib/tapioca/compilers/todos_compiler.rb +1 -1
  36. data/lib/tapioca/config.rb +2 -0
  37. data/lib/tapioca/config_builder.rb +4 -2
  38. data/lib/tapioca/constant_locator.rb +6 -8
  39. data/lib/tapioca/gemfile.rb +2 -4
  40. data/lib/tapioca/generator.rb +124 -40
  41. data/lib/tapioca/generic_type_registry.rb +25 -98
  42. data/lib/tapioca/helpers/active_record_column_type_helper.rb +98 -0
  43. data/lib/tapioca/internal.rb +2 -9
  44. data/lib/tapioca/loader.rb +13 -33
  45. data/lib/tapioca/rbi_ext/model.rb +122 -0
  46. data/lib/tapioca/reflection.rb +131 -0
  47. data/lib/tapioca/sorbet_ext/fixed_hash_patch.rb +1 -1
  48. data/lib/tapioca/sorbet_ext/generic_name_patch.rb +72 -4
  49. data/lib/tapioca/sorbet_ext/name_patch.rb +1 -1
  50. data/lib/tapioca/version.rb +1 -1
  51. data/lib/tapioca.rb +2 -1
  52. metadata +34 -22
  53. data/lib/tapioca/cli/main.rb +0 -146
  54. data/lib/tapioca/core_ext/class.rb +0 -28
  55. data/lib/tapioca/core_ext/string.rb +0 -18
  56. data/lib/tapioca/rbi/model.rb +0 -405
  57. data/lib/tapioca/rbi/printer.rb +0 -410
  58. data/lib/tapioca/rbi/rewriters/group_nodes.rb +0 -106
  59. data/lib/tapioca/rbi/rewriters/nest_non_public_methods.rb +0 -65
  60. data/lib/tapioca/rbi/rewriters/nest_singleton_methods.rb +0 -42
  61. data/lib/tapioca/rbi/rewriters/sort_nodes.rb +0 -86
  62. data/lib/tapioca/rbi/visitor.rb +0 -21
@@ -13,7 +13,7 @@ module T
13
13
  end
14
14
  end
15
15
 
16
- "{#{entries.join(', ')}}"
16
+ "{#{entries.join(", ")}}"
17
17
  end
18
18
  end
19
19
  end
@@ -23,16 +23,16 @@ module T
23
23
  def type_member(variance = :invariant, fixed: nil, lower: T.untyped, upper: BasicObject)
24
24
  # `T::Generic#type_member` just instantiates a `T::Type::TypeMember` instance and returns it.
25
25
  # We use that when registering the type member and then later return it from this method.
26
- type_member = super
27
- Tapioca::GenericTypeRegistry.register_type_member(self, type_member, fixed, lower, upper)
26
+ type_member = Tapioca::TypeMember.new(variance, fixed, lower, upper)
27
+ Tapioca::GenericTypeRegistry.register_type_variable(self, type_member)
28
28
  type_member
29
29
  end
30
30
 
31
31
  def type_template(variance = :invariant, fixed: nil, lower: T.untyped, upper: BasicObject)
32
32
  # `T::Generic#type_template` just instantiates a `T::Type::TypeTemplate` instance and returns it.
33
33
  # We use that when registering the type template and then later return it from this method.
34
- type_template = super
35
- Tapioca::GenericTypeRegistry.register_type_template(self, type_template, fixed, lower, upper)
34
+ type_template = Tapioca::TypeTemplate.new(variance, fixed, lower, upper)
35
+ Tapioca::GenericTypeRegistry.register_type_variable(self, type_template)
36
36
  type_template
37
37
  end
38
38
  end
@@ -64,3 +64,71 @@ module T
64
64
  end
65
65
  end
66
66
  end
67
+
68
+ module Tapioca
69
+ class TypeMember < T::Types::TypeMember
70
+ extend T::Sig
71
+
72
+ sig { returns(T.nilable(String)) }
73
+ attr_accessor :name
74
+
75
+ sig { returns(T.untyped) }
76
+ attr_reader :fixed, :lower, :upper
77
+
78
+ sig { params(variance: Symbol, fixed: T.untyped, lower: T.untyped, upper: T.untyped).void }
79
+ def initialize(variance, fixed, lower, upper)
80
+ super(variance)
81
+ @fixed = fixed
82
+ @lower = lower
83
+ @upper = upper
84
+ end
85
+
86
+ sig { returns(String) }
87
+ def serialize
88
+ parts = []
89
+ parts << ":#{@variance}" unless @variance == :invariant
90
+ parts << "fixed: #{@fixed}" if @fixed
91
+ parts << "lower: #{@lower}" unless @lower == T.untyped
92
+ parts << "upper: #{@upper}" unless @upper == BasicObject
93
+
94
+ parameters = parts.join(", ")
95
+
96
+ serialized = +"type_member"
97
+ serialized << "(#{parameters})" unless parameters.empty?
98
+ serialized
99
+ end
100
+ end
101
+
102
+ class TypeTemplate < T::Types::TypeTemplate
103
+ extend T::Sig
104
+
105
+ sig { returns(T.nilable(String)) }
106
+ attr_accessor :name
107
+
108
+ sig { returns(T.untyped) }
109
+ attr_reader :fixed, :lower, :upper
110
+
111
+ sig { params(variance: Symbol, fixed: T.untyped, lower: T.untyped, upper: T.untyped).void }
112
+ def initialize(variance, fixed, lower, upper)
113
+ super(variance)
114
+ @fixed = fixed
115
+ @lower = lower
116
+ @upper = upper
117
+ end
118
+
119
+ sig { returns(String) }
120
+ def serialize
121
+ parts = []
122
+ parts << ":#{@variance}" unless @variance == :invariant
123
+ parts << "fixed: #{@fixed}" if @fixed
124
+ parts << "lower: #{@lower}" unless @lower == T.untyped
125
+ parts << "upper: #{@upper}" unless @upper == BasicObject
126
+
127
+ parameters = parts.join(", ")
128
+
129
+ serialized = +"type_template"
130
+ serialized << "(#{parameters})" unless parameters.empty?
131
+ serialized
132
+ end
133
+ end
134
+ end
@@ -6,7 +6,7 @@ module T
6
6
  class Simple
7
7
  module NamePatch
8
8
  def name
9
- @name ||= Module.instance_method(:name).bind(@raw_type).call.freeze
9
+ @name ||= ::Tapioca::Reflection.name_of(@raw_type).freeze
10
10
  end
11
11
  end
12
12
 
@@ -2,5 +2,5 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Tapioca
5
- VERSION = "0.4.27"
5
+ VERSION = "0.5.0"
6
6
  end
data/lib/tapioca.rb CHANGED
@@ -17,6 +17,7 @@ module Tapioca
17
17
  class Error < StandardError; end
18
18
  end
19
19
 
20
- require "tapioca/constant_locator"
20
+ require "tapioca/reflection"
21
21
  require "tapioca/compilers/dsl/base"
22
+ require "tapioca/helpers/active_record_column_type_helper"
22
23
  require "tapioca/version"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tapioca
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.27
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ufuk Kayserilioglu
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: exe
13
13
  cert_chain: []
14
- date: 2021-09-16 00:00:00.000000000 Z
14
+ date: 2021-09-07 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: bundler
@@ -42,47 +42,47 @@ dependencies:
42
42
  - !ruby/object:Gem::Version
43
43
  version: 0.12.2
44
44
  - !ruby/object:Gem::Dependency
45
- name: sorbet-static
45
+ name: rbi
46
46
  requirement: !ruby/object:Gem::Requirement
47
47
  requirements:
48
48
  - - ">="
49
49
  - !ruby/object:Gem::Version
50
- version: 0.4.4471
50
+ version: '0'
51
51
  type: :runtime
52
52
  prerelease: false
53
53
  version_requirements: !ruby/object:Gem::Requirement
54
54
  requirements:
55
55
  - - ">="
56
56
  - !ruby/object:Gem::Version
57
- version: 0.4.4471
57
+ version: '0'
58
58
  - !ruby/object:Gem::Dependency
59
- name: sorbet-runtime
59
+ name: sorbet-static
60
60
  requirement: !ruby/object:Gem::Requirement
61
61
  requirements:
62
62
  - - ">="
63
63
  - !ruby/object:Gem::Version
64
- version: '0'
64
+ version: 0.4.4471
65
65
  type: :runtime
66
66
  prerelease: false
67
67
  version_requirements: !ruby/object:Gem::Requirement
68
68
  requirements:
69
69
  - - ">="
70
70
  - !ruby/object:Gem::Version
71
- version: '0'
71
+ version: 0.4.4471
72
72
  - !ruby/object:Gem::Dependency
73
- name: parlour
73
+ name: sorbet-runtime
74
74
  requirement: !ruby/object:Gem::Requirement
75
75
  requirements:
76
76
  - - ">="
77
77
  - !ruby/object:Gem::Version
78
- version: 2.1.0
78
+ version: '0'
79
79
  type: :runtime
80
80
  prerelease: false
81
81
  version_requirements: !ruby/object:Gem::Requirement
82
82
  requirements:
83
83
  - - ">="
84
84
  - !ruby/object:Gem::Version
85
- version: 2.1.0
85
+ version: '0'
86
86
  - !ruby/object:Gem::Dependency
87
87
  name: spoom
88
88
  requirement: !ruby/object:Gem::Requirement
@@ -111,6 +111,20 @@ dependencies:
111
111
  - - ">="
112
112
  - !ruby/object:Gem::Version
113
113
  version: 0.19.2
114
+ - !ruby/object:Gem::Dependency
115
+ name: unparser
116
+ requirement: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ type: :runtime
122
+ prerelease: false
123
+ version_requirements: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - ">="
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
114
128
  description:
115
129
  email:
116
130
  - ruby@shopify.com
@@ -125,18 +139,22 @@ files:
125
139
  - exe/tapioca
126
140
  - lib/tapioca.rb
127
141
  - lib/tapioca/cli.rb
128
- - lib/tapioca/cli/main.rb
142
+ - lib/tapioca/compilers/dsl/aasm.rb
129
143
  - lib/tapioca/compilers/dsl/action_controller_helpers.rb
130
144
  - lib/tapioca/compilers/dsl/action_mailer.rb
131
145
  - lib/tapioca/compilers/dsl/active_job.rb
146
+ - lib/tapioca/compilers/dsl/active_model_attributes.rb
132
147
  - lib/tapioca/compilers/dsl/active_record_associations.rb
133
148
  - lib/tapioca/compilers/dsl/active_record_columns.rb
134
149
  - lib/tapioca/compilers/dsl/active_record_enum.rb
135
150
  - lib/tapioca/compilers/dsl/active_record_scope.rb
136
151
  - lib/tapioca/compilers/dsl/active_record_typed_store.rb
137
152
  - lib/tapioca/compilers/dsl/active_resource.rb
153
+ - lib/tapioca/compilers/dsl/active_storage.rb
154
+ - lib/tapioca/compilers/dsl/active_support_concern.rb
138
155
  - lib/tapioca/compilers/dsl/active_support_current_attributes.rb
139
156
  - lib/tapioca/compilers/dsl/base.rb
157
+ - lib/tapioca/compilers/dsl/config.rb
140
158
  - lib/tapioca/compilers/dsl/frozen_record.rb
141
159
  - lib/tapioca/compilers/dsl/identity_cache.rb
142
160
  - lib/tapioca/compilers/dsl/protobuf.rb
@@ -154,20 +172,14 @@ files:
154
172
  - lib/tapioca/config.rb
155
173
  - lib/tapioca/config_builder.rb
156
174
  - lib/tapioca/constant_locator.rb
157
- - lib/tapioca/core_ext/class.rb
158
- - lib/tapioca/core_ext/string.rb
159
175
  - lib/tapioca/gemfile.rb
160
176
  - lib/tapioca/generator.rb
161
177
  - lib/tapioca/generic_type_registry.rb
178
+ - lib/tapioca/helpers/active_record_column_type_helper.rb
162
179
  - lib/tapioca/internal.rb
163
180
  - lib/tapioca/loader.rb
164
- - lib/tapioca/rbi/model.rb
165
- - lib/tapioca/rbi/printer.rb
166
- - lib/tapioca/rbi/rewriters/group_nodes.rb
167
- - lib/tapioca/rbi/rewriters/nest_non_public_methods.rb
168
- - lib/tapioca/rbi/rewriters/nest_singleton_methods.rb
169
- - lib/tapioca/rbi/rewriters/sort_nodes.rb
170
- - lib/tapioca/rbi/visitor.rb
181
+ - lib/tapioca/rbi_ext/model.rb
182
+ - lib/tapioca/reflection.rb
171
183
  - lib/tapioca/sorbet_ext/fixed_hash_patch.rb
172
184
  - lib/tapioca/sorbet_ext/generic_name_patch.rb
173
185
  - lib/tapioca/sorbet_ext/name_patch.rb
@@ -185,7 +197,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
185
197
  requirements:
186
198
  - - ">="
187
199
  - !ruby/object:Gem::Version
188
- version: '2.4'
200
+ version: '2.6'
189
201
  required_rubygems_version: !ruby/object:Gem::Requirement
190
202
  requirements:
191
203
  - - ">="
@@ -1,146 +0,0 @@
1
- # typed: true
2
- # frozen_string_literal: true
3
-
4
- module Tapioca
5
- module Cli
6
- class Main < Thor
7
- include(Thor::Actions)
8
-
9
- class_option :prerequire,
10
- aliases: ["--pre", "-b"],
11
- banner: "file",
12
- desc: "A file to be required before Bundler.require is called"
13
- class_option :postrequire,
14
- aliases: ["--post", "-a"],
15
- banner: "file",
16
- desc: "A file to be required after Bundler.require is called"
17
- class_option :outdir,
18
- aliases: ["--out", "-o"],
19
- banner: "directory",
20
- desc: "The output directory for generated RBI files"
21
- class_option :generate_command,
22
- aliases: ["--cmd", "-c"],
23
- banner: "command",
24
- desc: "The command to run to regenerate RBI files"
25
- class_option :exclude,
26
- aliases: ["-x"],
27
- type: :array,
28
- banner: "gem [gem ...]",
29
- desc: "Excludes the given gem(s) from RBI generation"
30
- class_option :typed_overrides,
31
- aliases: ["--typed", "-t"],
32
- type: :hash,
33
- banner: "gem:level [gem:level ...]",
34
- desc: "Overrides for typed sigils for generated gem RBIs"
35
-
36
- map T.unsafe(%w[--version -v] => :__print_version)
37
-
38
- desc "init", "initializes folder structure"
39
- def init
40
- create_config
41
- create_post_require
42
- generate_binstub
43
- end
44
-
45
- desc "require", "generate the list of files to be required by tapioca"
46
- def require
47
- Tapioca.silence_warnings do
48
- generator.build_requires
49
- end
50
- end
51
-
52
- desc "todo", "generate the list of unresolved constants"
53
- def todo
54
- Tapioca.silence_warnings do
55
- generator.build_todos
56
- end
57
- end
58
-
59
- desc "dsl [constant...]", "generate RBIs for dynamic methods"
60
- option :generators,
61
- type: :array,
62
- aliases: ["--gen", "-g"],
63
- banner: "generator [generator ...]",
64
- desc: "Only run supplied DSL generators"
65
- option :verify,
66
- type: :boolean,
67
- default: false,
68
- desc: "Verifies RBIs are up-to-date"
69
- option :quiet,
70
- aliases: ["-q"],
71
- type: :boolean,
72
- desc: "Supresses file creation output"
73
- def dsl(*constants)
74
- Tapioca.silence_warnings do
75
- generator.build_dsl(constants, should_verify: options[:verify], quiet: options[:quiet])
76
- end
77
- end
78
-
79
- desc "generate [gem...]", "generate RBIs from gems"
80
- def generate(*gems)
81
- Tapioca.silence_warnings do
82
- generator.build_gem_rbis(gems)
83
- end
84
- end
85
-
86
- desc "sync", "sync RBIs to Gemfile"
87
- def sync
88
- Tapioca.silence_warnings do
89
- generator.sync_rbis_with_gemfile
90
- end
91
- end
92
-
93
- desc "--version, -v", "show version"
94
- def __print_version
95
- puts "Tapioca v#{Tapioca::VERSION}"
96
- end
97
-
98
- private
99
-
100
- def create_config
101
- create_file(Config::SORBET_CONFIG, skip: true) do
102
- <<~CONTENT
103
- --dir
104
- .
105
- CONTENT
106
- end
107
- end
108
-
109
- def create_post_require
110
- create_file(Config::DEFAULT_POSTREQUIRE, skip: true) do
111
- <<~CONTENT
112
- # typed: false
113
- # frozen_string_literal: true
114
-
115
- # Add your extra requires here
116
- CONTENT
117
- end
118
- end
119
-
120
- def generate_binstub
121
- bin_stub_exists = File.exist?("bin/tapioca")
122
- installer = Bundler::Installer.new(Bundler.root, Bundler.definition)
123
- spec = Bundler.definition.specs.find { |s| s.name == "tapioca" }
124
- installer.generate_bundler_executable_stubs(spec, { force: true })
125
- if bin_stub_exists
126
- shell.say_status(:force, "bin/tapioca", :yellow)
127
- else
128
- shell.say_status(:create, "bin/tapioca", :green)
129
- end
130
- end
131
-
132
- no_commands do
133
- def self.exit_on_failure?
134
- true
135
- end
136
-
137
- def generator
138
- current_command = T.must(current_command_chain.first)
139
- @generator ||= Generator.new(
140
- ConfigBuilder.from_options(current_command, options)
141
- )
142
- end
143
- end
144
- end
145
- end
146
- end
@@ -1,28 +0,0 @@
1
- # typed: strict
2
- # frozen_string_literal: true
3
-
4
- class Class
5
- extend T::Sig
6
-
7
- # Returns an array with all classes that are < than its receiver.
8
- #
9
- # class C; end
10
- # C.descendants # => []
11
- #
12
- # class B < C; end
13
- # C.descendants # => [B]
14
- #
15
- # class A < B; end
16
- # C.descendants # => [B, A]
17
- #
18
- # class D < C; end
19
- # C.descendants # => [B, A, D]
20
- sig { returns(T::Array[Class]) }
21
- def descendants
22
- result = ObjectSpace.each_object(singleton_class).reject do |k|
23
- T.cast(k, Module).singleton_class? || k == self
24
- end
25
-
26
- T.cast(result, T::Array[Class])
27
- end
28
- end