Skip to content

Commit

Permalink
Change RubyIndexer::Enhancement into a class instead
Browse files Browse the repository at this point in the history
  • Loading branch information
st0012 committed Oct 22, 2024
1 parent 1365c8c commit 1b2b113
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 34 deletions.
10 changes: 4 additions & 6 deletions lib/ruby_indexer/lib/ruby_indexer/enhancement.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
32 changes: 4 additions & 28 deletions lib/ruby_indexer/test/enhancements_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand All @@ -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)
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 1b2b113

Please sign in to comment.