diff --git a/lib/ruby_indexer/lib/ruby_indexer/enhancement.rb b/lib/ruby_indexer/lib/ruby_indexer/enhancement.rb index c6d59e857..f0f11d390 100644 --- a/lib/ruby_indexer/lib/ruby_indexer/enhancement.rb +++ b/lib/ruby_indexer/lib/ruby_indexer/enhancement.rb @@ -2,19 +2,17 @@ # frozen_string_literal: true module RubyIndexer - module Enhancement + class Enhancement extend T::Sig extend T::Helpers - interface! - - requires_ancestor { Object } + abstract! # The `on_extend` indexing enhancement is invoked whenever an extend is encountered in the code. It can be used to # register for an included callback, similar to what `ActiveSupport::Concern` does in order to auto-extend the # `ClassMethods` modules sig do - abstract.params( + overridable.params( index: Index, owner: T.nilable(Entry::Namespace), node: Prism::CallNode, @@ -28,7 +26,7 @@ module Enhancement def on_call_node_enter(index, owner, node, file_path, code_units_cache); end sig do - abstract.params( + overridable.params( index: Index, owner: T.nilable(Entry::Namespace), node: Prism::CallNode, diff --git a/lib/ruby_indexer/test/enhancements_test.rb b/lib/ruby_indexer/test/enhancements_test.rb index 551799fe7..e5dd106bd 100644 --- a/lib/ruby_indexer/test/enhancements_test.rb +++ b/lib/ruby_indexer/test/enhancements_test.rb @@ -6,9 +6,7 @@ module RubyIndexer class EnhancementTest < TestCase def test_enhancing_indexing_included_hook - enhancement_class = Class.new do - include Enhancement - + enhancement_class = Class.new(Enhancement) do def on_call_node_enter(index, owner, node, file_path, code_units_cache) return unless owner return unless node.name == :extend @@ -48,10 +46,6 @@ def on_call_node_enter(index, owner, node, file_path, code_units_cache) # Do nothing end end - - def on_call_node_leave(index, owner, node, file_path, code_units_cache) - # Do nothing - end end @index.register_enhancement(enhancement_class.new) @@ -102,9 +96,7 @@ class User < ActiveRecord::Base end def test_enhancing_indexing_configuration_dsl - enhancement_class = Class.new do - include Enhancement - + enhancement_class = Class.new(Enhancement) do def on_call_node_enter(index, owner, node, file_path, code_units_cache) return unless owner @@ -130,10 +122,6 @@ def on_call_node_enter(index, owner, node, file_path, code_units_cache) owner, )) end - - def on_call_node_leave(index, owner, node, file_path, code_units_cache) - # Do nothing - end end @index.register_enhancement(enhancement_class.new) @@ -169,17 +157,11 @@ class User < ActiveRecord::Base end def test_error_handling_in_on_call_node_enter_enhancement - enhancement_class = Class.new do - include Enhancement - + enhancement_class = Class.new(Enhancement) do def on_call_node_enter(index, owner, node, file_path, code_units_cache) raise "Error" end - def on_call_node_leave(index, owner, node, file_path, code_units_cache) - # Do nothing - end - class << self def name "TestEnhancement" @@ -210,13 +192,7 @@ def self.extended(base) end def test_error_handling_in_on_call_node_leave_enhancement - enhancement_class = Class.new do - include Enhancement - - def on_call_node_enter(index, owner, node, file_path, code_units_cache) - # Do nothing - end - + enhancement_class = Class.new(Enhancement) do def on_call_node_leave(index, owner, node, file_path, code_units_cache) raise "Error" end