Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 3 additions & 13 deletions lib/tapioca/dsl/compilers/json_api_client_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,17 +138,7 @@ def type_for(property)
type = ::JsonApiClient::Schema::TypeFactory.type_for(property.type)
return "T.untyped" if type.nil?

sorbet_type = if type.respond_to?(:sorbet_type)
line, file = type.method(:sorbet_type).source_location

$stderr.puts <<~MESSAGE
WARNING: `#sorbet_type` is deprecated. Please rename your method to `#__tapioca_type`."

Defined on line #{line} of #{file}
MESSAGE

type.sorbet_type
elsif type.respond_to?(:__tapioca_type)
tapioca_type = if type.respond_to?(:__tapioca_type)
type.__tapioca_type
elsif type == ::JsonApiClient::Schema::Types::Integer
"::Integer"
Expand All @@ -167,9 +157,9 @@ def type_for(property)
end

if property.default.nil?
as_nilable_type(sorbet_type)
as_nilable_type(tapioca_type)
else
sorbet_type
tapioca_type
end
end

Expand Down
67 changes: 0 additions & 67 deletions spec/tapioca/dsl/compilers/json_api_client_resource_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -368,73 +368,6 @@ def tag_count=(tag_count); end

assert_equal(expected, rbi_for(:Post))
end

it "prints a warning that #sorbet_type is deprecated" do
add_ruby_file("post.rb", <<~RUBY)
class CustomType
def self.sorbet_type
"Integer"
end
end

class Post < JsonApiClient::Resource
property :comment_count, type: :custom_type
property :tag_count, type: :custom_type, default: 0
end
RUBY

expected = <<~RBI
# typed: strong

class Post
include JsonApiClientResourceGeneratedMethods

module JsonApiClientResourceGeneratedMethods
sig { returns(T.nilable(Integer)) }
def comment_count; end

sig { params(comment_count: T.nilable(Integer)).returns(T.nilable(Integer)) }
def comment_count=(comment_count); end

sig { returns(Integer) }
def tag_count; end

sig { params(tag_count: Integer).returns(Integer) }
def tag_count=(tag_count); end
end
end
RBI

assert_output(nil, /WARNING: `#sorbet_type` is deprecated./) do
assert_equal(expected, rbi_for(:Post))
end
end

it "does not crash if the source location #sorbet_type is unknown" do
add_ruby_file("post.rb", <<~RUBY)
class CustomType
def self.sorbet_type
"Integer"
end

def self.method(name)
m = super
# Fake the source location, as if this was defined in a C extension.
def m.source_location
nil
end
m
end
end

class Post < JsonApiClient::Resource
property :comment_count, type: :custom_type
property :tag_count, type: :custom_type, default: 0
end
RUBY

rbi_for(:Post) # Should not raise
end
end
end
end
Expand Down
Loading