Skip to content

Commit

Permalink
Raise an error if you try to extend Phlex::Kit in a class
Browse files Browse the repository at this point in the history
  • Loading branch information
joeldrapper committed Feb 13, 2025
1 parent a33f0b6 commit 7ceae6b
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions lib/phlex/kit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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, ...)
Expand Down Expand Up @@ -52,7 +61,7 @@ def const_added(name)
case constant
when Class
if constant < Phlex::SGML
constant.include(self)
constant.include(me)

constant = nil

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

0 comments on commit 7ceae6b

Please sign in to comment.