I noticed another kind of missing-definition problem while I was trying to use my working branch (mentioned in #20) in a Rails app: when some classes are generated automatically like ActiveRecord does, we have no chance to generate the definition today.
(I'll try to figure out some solutions, but LMK if you have already been working on it, or have any advice 🙏 )
For example, let's say we have active record models called User and Bookmark (a user has many bookmarks), and a method that returns an association of bookmarks.
class User < ApplicationRecord
has_many :bookmarks
end
class Bookmark < ApplicationRecord
belongs_to :user
end
class SomeClass
def initialize(user)
@user = user
end
def something_returns_association
@user.bookmarks
end
end
and run the following script:
trace = RBS::Trace.new
trace.enable do
user = User.create
p SomeClass.new(user).something_returns_association
end
trace.save_comments
trace.save_files out_dir: 'sig'
Then we will get the following comments in the User class:
class SomeClass
# @rbs (User) -> void
def initialize(user)
@user = user
end
# @rbs () -> Bookmark::ActiveRecord_Associations_CollectionProxy
def something_returns_association
@user.bookmarks
end
end
and an rbs file as follows:
class SomeClass
def initialize: (User) -> void
def something_returns_association: () -> Bookmark::ActiveRecord_Associations_CollectionProxy
end
However, since we don't have the definition of Bookmark::ActiveRecord_Associations_CollectionProxy, we will get the following error when steep check runs.
sig/app/models/some_class.rbs:4:43: [error] Cannot find type `Bookmark::ActiveRecord_Associations_CollectionProxy`
│ Diagnostic ID: RBS::UnknownTypeName
│
└ def something_returns_association: () -> Bookmark::ActiveRecord_Associations_CollectionProxy
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
I noticed another kind of missing-definition problem while I was trying to use my working branch (mentioned in #20) in a Rails app: when some classes are generated automatically like ActiveRecord does, we have no chance to generate the definition today.
(I'll try to figure out some solutions, but LMK if you have already been working on it, or have any advice 🙏 )
For example, let's say we have active record models called User and Bookmark (a user has many bookmarks), and a method that returns an association of bookmarks.
and run the following script:
Then we will get the following comments in the User class:
and an rbs file as follows:
However, since we don't have the definition of
Bookmark::ActiveRecord_Associations_CollectionProxy, we will get the following error whensteep checkruns.