diff --git a/lib/phlex.rb b/lib/phlex.rb index d13eddfa..2bb3a77c 100644 --- a/lib/phlex.rb +++ b/lib/phlex.rb @@ -5,13 +5,12 @@ module Phlex autoload :ArgumentError, "phlex/errors/argument_error" - autoload :DoubleRenderError, "phlex/errors/double_render_error" autoload :BlackHole, "phlex/black_hole" autoload :CSV, "phlex/csv" autoload :Callable, "phlex/callable" autoload :Context, "phlex/context" autoload :DeferredRender, "phlex/deferred_render" - autoload :ElementClobberingGuard, "phlex/element_clobbering_guard" + autoload :DoubleRenderError, "phlex/errors/double_render_error" autoload :Elements, "phlex/elements" autoload :Error, "phlex/error" autoload :FIFO, "phlex/fifo" diff --git a/lib/phlex/element_clobbering_guard.rb b/lib/phlex/element_clobbering_guard.rb deleted file mode 100644 index 99e7bec3..00000000 --- a/lib/phlex/element_clobbering_guard.rb +++ /dev/null @@ -1,18 +0,0 @@ -# frozen_string_literal: true - -# @api private -module Phlex::ElementClobberingGuard - def method_added(method_name) - if method_name[0] == "_" && __element_method__?(method_name[1..].to_sym) - raise Phlex::NameError.new("👋 Redefining the method `#{name}##{method_name}` is not a good idea.") - elsif method_name == :view_template - location = instance_method(method_name).source_location[0] - - if location[0] in "/" | "." - Phlex.__expand_attribute_cache__(location) - end - else - super - end - end -end diff --git a/lib/phlex/html.rb b/lib/phlex/html.rb index e7c671d9..eb9c2771 100644 --- a/lib/phlex/html.rb +++ b/lib/phlex/html.rb @@ -38,7 +38,4 @@ def filename def content_type "text/html" end - - # This should be extended after all method definitions - extend Phlex::ElementClobberingGuard end diff --git a/lib/phlex/sgml.rb b/lib/phlex/sgml.rb index d01122f3..ec501fcd 100644 --- a/lib/phlex/sgml.rb +++ b/lib/phlex/sgml.rb @@ -577,4 +577,16 @@ def __styles__(styles) buffer end end + + private_class_method def self.method_added(method_name) + if method_name == :view_template + location = instance_method(method_name).source_location[0] + + if location[0] in "/" | "." + Phlex.__expand_attribute_cache__(location) + end + else + super + end + end end diff --git a/lib/phlex/svg.rb b/lib/phlex/svg.rb index 3e6708e2..eb11b73f 100644 --- a/lib/phlex/svg.rb +++ b/lib/phlex/svg.rb @@ -12,7 +12,4 @@ def content_type def filename nil end - - # This should be extended after all method definitions - extend Phlex::ElementClobberingGuard end diff --git a/quickdraw/sgml/element_clobbering_guard.test.rb b/quickdraw/sgml/element_clobbering_guard.test.rb deleted file mode 100644 index 4aac7bfe..00000000 --- a/quickdraw/sgml/element_clobbering_guard.test.rb +++ /dev/null @@ -1,13 +0,0 @@ -# frozen_string_literal: true - -Example = Class.new(Phlex::HTML) - -test "raises if you try to redefine an underscored method" do - expect { Example.define_method(:_h1) { nil } }.to_raise(Phlex::NameError) -end - -test "doesn't raise if you define a new underscored method" do - expect { - Example.define_method(:_some_random_method) { nil } - }.not_to_raise -end