Skip to content

Commit 7a6887b

Browse files
committed
Prevent crash during ActiveRecord const check
1 parent 8c0e73a commit 7a6887b

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

lib/ruby_lsp/ruby_lsp_rails/server.rb

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def execute(request, params)
8282
sig { params(model_name: String).returns(T::Hash[Symbol, T.untyped]) }
8383
def resolve_database_info_from_model(model_name)
8484
const = ActiveSupport::Inflector.safe_constantize(model_name)
85-
unless const && defined?(ActiveRecord) && const < ActiveRecord::Base && !const.abstract_class?
85+
unless active_record_model?(const)
8686
return {
8787
result: nil,
8888
}
@@ -104,6 +104,17 @@ def resolve_database_info_from_model(model_name)
104104
rescue => e
105105
{ error: e.full_message(highlight: false) }
106106
end
107+
108+
sig { params(const: T.untyped).returns(T::Boolean) }
109+
def active_record_model?(const)
110+
!!(
111+
const &&
112+
defined?(ActiveRecord) &&
113+
const.respond_to?(:<) &&
114+
const < ActiveRecord::Base &&
115+
!const.abstract_class?
116+
)
117+
end
107118
end
108119
end
109120
end

0 commit comments

Comments
 (0)