tapioca 0.16.0 → 0.16.2

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: 3a448cd511151879e4eef761b28cc8f5b1904f0d57e560a38af09bdda9689f98
4
- data.tar.gz: 563c5e68f866444da629a4b206fed22b8a27531c36c0378d669886aa2a704eaf
3
+ metadata.gz: cc2c2c6ae059634316e511dce8839f7e4930b0263093e6250612aa7d6aae582d
4
+ data.tar.gz: 7ee41089cca733c46e3d3c9dca9384c1e8a516fd7ebb0fb347eb31935da8d3ee
5
5
  SHA512:
6
- metadata.gz: c847afeb5c173ad8b0c46a0f2fd214336150124fd96f0c729029ce492a5f4aea4bf5d26adfd64cf386486f22342b21f502cdbc52c68ca544a65c4bf6777dacee
7
- data.tar.gz: e25a62343cc4522d37e9508b4215f6efb9115b93e1e9ba38c71edf26da025126732b4762b834304d0e439c741d581f238e29e22dded9fcbf0415256041f8f849
6
+ metadata.gz: 00ecd9606853f9bf27821df7c20b74af4898d84d5b3a32472a5156c2d0ba353b4ab53e7ddc4d21474a2b1599409aecad05693ac6713100798a4cf77dc2d50b83
7
+ data.tar.gz: 4b8d2455cf3cd89c0744d4e266331ee61c3ca585380db1da348bafaa014fbeaa7483401100f1148f8c89fe21119c9a555e9af86be3699ba2733f48cab1929901
@@ -119,7 +119,14 @@ module Tapioca
119
119
  ) if @file_header
120
120
 
121
121
  rbi.root = Runtime::Trackers::Autoload.with_disabled_exits do
122
- Tapioca::Gem::Pipeline.new(gem, include_doc: @include_doc, include_loc: @include_loc).compile
122
+ Tapioca::Gem::Pipeline.new(
123
+ gem,
124
+ include_doc: @include_doc,
125
+ include_loc: @include_loc,
126
+ error_handler: ->(error) {
127
+ say_error(error, :bold, :red)
128
+ },
129
+ ).compile
123
130
  end
124
131
 
125
132
  merge_with_exported_rbi(gem, rbi) if @include_exported_rbis
@@ -1024,6 +1024,21 @@ module Tapioca
1024
1024
  end
1025
1025
  end
1026
1026
  end
1027
+
1028
+ # We are creating `#new` on the class itself since when called as `Model.new`
1029
+ # it doesn't allow for an array to be passed. If we kept it as a blanket it
1030
+ # would mean the passing any `T.untyped` value to the method would assume
1031
+ # the result is `T::Array` which is not the case majority of the time.
1032
+ model.create_method("new", class_method: true) do |method|
1033
+ method.add_opt_param("attributes", "nil")
1034
+ method.add_block_param("block")
1035
+
1036
+ method.add_sig do |sig|
1037
+ sig.add_param("attributes", "T.untyped")
1038
+ sig.add_param("block", "T.nilable(T.proc.params(object: #{constant_name}).void)")
1039
+ sig.return_type = constant_name
1040
+ end
1041
+ end
1027
1042
  end
1028
1043
 
1029
1044
  sig do
@@ -155,6 +155,8 @@ module Tapioca
155
155
  "::ActiveSupport::TimeWithZone"
156
156
  when ActiveRecord::Enum::EnumType
157
157
  "::String"
158
+ when ActiveRecord::Type::Binary
159
+ "::String"
158
160
  when ActiveRecord::Type::Serialized
159
161
  serialized_column_type(column_type)
160
162
  when ->(type) {
@@ -73,7 +73,7 @@ module Tapioca
73
73
  return unless method_owned_by_constant?(method, constant)
74
74
  return if @pipeline.symbol_in_payload?(symbol_name) && !@pipeline.method_in_gem?(method)
75
75
 
76
- signature = signature_of(method)
76
+ signature = lookup_signature_of(method)
77
77
  method = T.let(signature.method, UnboundMethod) if signature
78
78
 
79
79
  method_name = method.name.to_s
@@ -211,6 +211,18 @@ module Tapioca
211
211
  def ignore?(event)
212
212
  event.is_a?(Tapioca::Gem::ForeignScopeNodeAdded)
213
213
  end
214
+
215
+ sig { params(method: UnboundMethod).returns(T.untyped) }
216
+ def lookup_signature_of(method)
217
+ signature_of!(method)
218
+ rescue LoadError, StandardError => error
219
+ @pipeline.error_handler.call(<<~MSG)
220
+ Unable to compile signature for method: #{method.owner}##{method.name}
221
+ Exception raised when loading signature: #{error.inspect}
222
+ MSG
223
+
224
+ nil
225
+ end
214
226
  end
215
227
  end
216
228
  end
@@ -14,11 +14,14 @@ module Tapioca
14
14
  constant = event.constant
15
15
  return unless T::Enum > event.constant # rubocop:disable Style/InvertibleUnlessCondition
16
16
 
17
- enums = T.unsafe(constant).values.map do |enum_type|
18
- enum_type.instance_variable_get(:@const_name).to_s
17
+ enum_block = RBI::TEnumBlock.new
18
+
19
+ T.unsafe(constant).values.each do |enum_type|
20
+ enum_name = enum_type.instance_variable_get(:@const_name).to_s
21
+ enum_block << RBI::Const.new(enum_name, "new")
19
22
  end
20
23
 
21
- event.node << RBI::TEnumBlock.new(enums)
24
+ event.node << enum_block
22
25
  end
23
26
 
24
27
  sig { override.params(event: NodeAdded).returns(T::Boolean) }
@@ -13,12 +13,28 @@ module Tapioca
13
13
  sig { returns(Gemfile::GemSpec) }
14
14
  attr_reader :gem
15
15
 
16
- sig { params(gem: Gemfile::GemSpec, include_doc: T::Boolean, include_loc: T::Boolean).void }
17
- def initialize(gem, include_doc: false, include_loc: false)
16
+ sig { returns(T.proc.params(error: String).void) }
17
+ attr_reader :error_handler
18
+
19
+ sig do
20
+ params(
21
+ gem: Gemfile::GemSpec,
22
+ error_handler: T.proc.params(error: String).void,
23
+ include_doc: T::Boolean,
24
+ include_loc: T::Boolean,
25
+ ).void
26
+ end
27
+ def initialize(
28
+ gem,
29
+ error_handler:,
30
+ include_doc: false,
31
+ include_loc: false
32
+ )
18
33
  @root = T.let(RBI::Tree.new, RBI::Tree)
19
34
  @gem = gem
20
35
  @seen = T.let(Set.new, T::Set[String])
21
36
  @alias_namespace = T.let(Set.new, T::Set[String])
37
+ @error_handler = error_handler
22
38
 
23
39
  @events = T.let([], T::Array[Gem::Event])
24
40
 
@@ -230,7 +230,7 @@ module Tapioca
230
230
  # The `eager_load_paths` method still exists, but doesn't return all paths anymore and causes Tapioca to miss some
231
231
  # engine paths. The following commit is the change:
232
232
  # https://github.com/rails/rails/commit/ebfca905db14020589c22e6937382e6f8f687664
233
- sig { params(engine: T.class_of(Rails::Engine)).returns(T::Array[String]) }
233
+ T::Sig::WithoutRuntime.sig { params(engine: T.class_of(Rails::Engine)).returns(T::Array[String]) }
234
234
  def eager_load_paths(engine)
235
235
  config = engine.config
236
236
 
@@ -34,7 +34,7 @@ module Tapioca
34
34
  group_nodes: true,
35
35
  max_line_length: nil,
36
36
  nest_singleton_methods: true,
37
- nest_non_public_methods: true,
37
+ nest_non_public_members: true,
38
38
  sort_nodes: true,
39
39
  ),
40
40
  RBIFormatter,
@@ -41,7 +41,7 @@ module Tapioca
41
41
  @underlying_type = T.let(underlying_type, Module)
42
42
  end
43
43
 
44
- sig { params(obj: T.untyped).returns(T::Boolean) }
44
+ sig { override.params(obj: T.untyped).returns(T::Boolean) }
45
45
  def valid?(obj)
46
46
  obj.is_a?(@underlying_type)
47
47
  end
@@ -130,15 +130,20 @@ module Tapioca
130
130
  end
131
131
 
132
132
  sig { params(method: T.any(UnboundMethod, Method)).returns(T.untyped) }
133
- def signature_of(method)
133
+ def signature_of!(method)
134
134
  T::Utils.signature_for_method(method)
135
+ end
136
+
137
+ sig { params(method: T.any(UnboundMethod, Method)).returns(T.untyped) }
138
+ def signature_of(method)
139
+ signature_of!(method)
135
140
  rescue LoadError, StandardError
136
141
  nil
137
142
  end
138
143
 
139
144
  sig { params(type: T::Types::Base).returns(String) }
140
145
  def name_of_type(type)
141
- type.to_s.gsub(/\bAttachedClass\b/, "T.attached_class")
146
+ type.to_s
142
147
  end
143
148
 
144
149
  sig { params(constant: Module, method: Symbol).returns(Method) }
@@ -65,7 +65,7 @@ module Tapioca
65
65
 
66
66
  private
67
67
 
68
- sig { returns(T::Array[T.class_of(Rails::Engine)]) }
68
+ T::Sig::WithoutRuntime.sig { returns(T::Array[T.class_of(Rails::Engine)]) }
69
69
  def engines
70
70
  @engines ||= T.let(
71
71
  if Object.const_defined?("Rails::Engine")
@@ -2,5 +2,5 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Tapioca
5
- VERSION = "0.16.0"
5
+ VERSION = "0.16.2"
6
6
  end
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.16.0
4
+ version: 0.16.2
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: 2024-08-06 00:00:00.000000000 Z
14
+ date: 2024-08-29 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: bundler
@@ -59,20 +59,14 @@ dependencies:
59
59
  name: rbi
60
60
  requirement: !ruby/object:Gem::Requirement
61
61
  requirements:
62
- - - ">="
63
- - !ruby/object:Gem::Version
64
- version: 0.1.14
65
- - - "<"
62
+ - - "~>"
66
63
  - !ruby/object:Gem::Version
67
64
  version: '0.2'
68
65
  type: :runtime
69
66
  prerelease: false
70
67
  version_requirements: !ruby/object:Gem::Requirement
71
68
  requirements:
72
- - - ">="
73
- - !ruby/object:Gem::Version
74
- version: 0.1.14
75
- - - "<"
69
+ - - "~>"
76
70
  - !ruby/object:Gem::Version
77
71
  version: '0.2'
78
72
  - !ruby/object:Gem::Dependency
@@ -290,7 +284,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
290
284
  - !ruby/object:Gem::Version
291
285
  version: '0'
292
286
  requirements: []
293
- rubygems_version: 3.5.16
287
+ rubygems_version: 3.5.17
294
288
  signing_key:
295
289
  specification_version: 4
296
290
  summary: A Ruby Interface file generator for gems, core types and the Ruby standard