-
Notifications
You must be signed in to change notification settings - Fork 225
Description
I have checked that this feature is not already implemented
- This feature does not exist
Use case
For every Ruby DSL I can think of, false positives could be avoided by querying the index to understand the context of the call. For example, the belongs_to DSL method in Rails is only available on descendants of ActiveRecord::Base.
Unfortunately, it is not possible to query the index to check if the current context inherits from ActiveRecord::Base while still building the index.
Description
I think this problem could be solved by allowing you to store lazy “potential” entries in the index. Let’s say you pick up the method call belongs_to :user. You want to define the method user as a result of this, but only if the class inherits from ActiveRecord::Base.
What if you could add an entry like this?
@listener.add_lazy_method("user") do |index|
if index.linearized_ancestors_of(owner).include?("ActiveRecord::Base")
RubyIndex::Entry::Method.new(
# ...
)
end
endThe index could store that there is potentially a method called user and its signature is in this Proc.
At lookup time, once the indexing is completed, the proc could be executed and if it returns nil, the entry is ignored. Otherwise, the returned Method entry is used.
Implementation
No response