Skip to content

Commit 5f2caba

Browse files
authored
Merge pull request #2499 from larouxn/drop_support_for_deprecated_sorbet_type
Drop support for >1 year deprecated `#sorbet_type` method
2 parents 3fbd33e + 3ce1a65 commit 5f2caba

File tree

2 files changed

+3
-80
lines changed

2 files changed

+3
-80
lines changed

lib/tapioca/dsl/compilers/json_api_client_resource.rb

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -138,17 +138,7 @@ def type_for(property)
138138
type = ::JsonApiClient::Schema::TypeFactory.type_for(property.type)
139139
return "T.untyped" if type.nil?
140140

141-
sorbet_type = if type.respond_to?(:sorbet_type)
142-
line, file = type.method(:sorbet_type).source_location
143-
144-
$stderr.puts <<~MESSAGE
145-
WARNING: `#sorbet_type` is deprecated. Please rename your method to `#__tapioca_type`."
146-
147-
Defined on line #{line} of #{file}
148-
MESSAGE
149-
150-
type.sorbet_type
151-
elsif type.respond_to?(:__tapioca_type)
141+
tapioca_type = if type.respond_to?(:__tapioca_type)
152142
type.__tapioca_type
153143
elsif type == ::JsonApiClient::Schema::Types::Integer
154144
"::Integer"
@@ -167,9 +157,9 @@ def type_for(property)
167157
end
168158

169159
if property.default.nil?
170-
as_nilable_type(sorbet_type)
160+
as_nilable_type(tapioca_type)
171161
else
172-
sorbet_type
162+
tapioca_type
173163
end
174164
end
175165

spec/tapioca/dsl/compilers/json_api_client_resource_spec.rb

Lines changed: 0 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -368,73 +368,6 @@ def tag_count=(tag_count); end
368368

369369
assert_equal(expected, rbi_for(:Post))
370370
end
371-
372-
it "prints a warning that #sorbet_type is deprecated" do
373-
add_ruby_file("post.rb", <<~RUBY)
374-
class CustomType
375-
def self.sorbet_type
376-
"Integer"
377-
end
378-
end
379-
380-
class Post < JsonApiClient::Resource
381-
property :comment_count, type: :custom_type
382-
property :tag_count, type: :custom_type, default: 0
383-
end
384-
RUBY
385-
386-
expected = <<~RBI
387-
# typed: strong
388-
389-
class Post
390-
include JsonApiClientResourceGeneratedMethods
391-
392-
module JsonApiClientResourceGeneratedMethods
393-
sig { returns(T.nilable(Integer)) }
394-
def comment_count; end
395-
396-
sig { params(comment_count: T.nilable(Integer)).returns(T.nilable(Integer)) }
397-
def comment_count=(comment_count); end
398-
399-
sig { returns(Integer) }
400-
def tag_count; end
401-
402-
sig { params(tag_count: Integer).returns(Integer) }
403-
def tag_count=(tag_count); end
404-
end
405-
end
406-
RBI
407-
408-
assert_output(nil, /WARNING: `#sorbet_type` is deprecated./) do
409-
assert_equal(expected, rbi_for(:Post))
410-
end
411-
end
412-
413-
it "does not crash if the source location #sorbet_type is unknown" do
414-
add_ruby_file("post.rb", <<~RUBY)
415-
class CustomType
416-
def self.sorbet_type
417-
"Integer"
418-
end
419-
420-
def self.method(name)
421-
m = super
422-
# Fake the source location, as if this was defined in a C extension.
423-
def m.source_location
424-
nil
425-
end
426-
m
427-
end
428-
end
429-
430-
class Post < JsonApiClient::Resource
431-
property :comment_count, type: :custom_type
432-
property :tag_count, type: :custom_type, default: 0
433-
end
434-
RUBY
435-
436-
rbi_for(:Post) # Should not raise
437-
end
438371
end
439372
end
440373
end

0 commit comments

Comments
 (0)