From 7ceae6b0a3e1eb4a15ccf0bb314dfd710842bef0 Mon Sep 17 00:00:00 2001 From: Joel Drapper Date: Thu, 13 Feb 2025 13:41:51 +0000 Subject: [PATCH] Raise an error if you try to extend `Phlex::Kit` in a class --- lib/phlex/kit.rb | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/phlex/kit.rb b/lib/phlex/kit.rb index 5efd53d4..941d9114 100644 --- a/lib/phlex/kit.rb +++ b/lib/phlex/kit.rb @@ -24,7 +24,16 @@ def respond_to_missing?(name, include_private = false) end def self.extended(mod) - mod.include(LazyLoader) + case mod + when Class + raise Phlex::ArgumentError.new(<<~MESSAGE) + `Phlex::Kit` was extended into #{mod.name}. + + You should only extend modules with `Phlex::Kit` as it is not compatible with classes. + MESSAGE + else + mod.include(LazyLoader) + end end def method_missing(name, ...) @@ -52,7 +61,7 @@ def const_added(name) case constant when Class if constant < Phlex::SGML - constant.include(self) + constant.include(me) constant = nil @@ -74,7 +83,7 @@ def const_added(name) end end when Module - constant.extend(Phlex::Kit) unless Class === constant + constant.extend(Phlex::Kit) end super