Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support patching singleton classes #5

Merged
merged 1 commit into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/flickwerk/patch_finder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module Flickwerk
class PatchFinder
DECORATED_CLASS_PATTERN = /(?:::)?(?<decorated_class>[\w.:]+)\.prepend[\s(]/
DECORATED_CLASS_PATTERN = /(?:::)?(?<decorated_class>[\w.:]+?)(?:\.singleton_class)?\.prepend[\s(]/

attr_reader :path, :autoloader

Expand Down
7 changes: 7 additions & 0 deletions test/dummy_app/app/patches/models/user_class_methods_patch.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module UserClassMethodsPatch
def address
"The outer rim"
end

DummyApp.user_class.singleton_class.prepend(self)
end
7 changes: 7 additions & 0 deletions test/test_flickwerk.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,11 @@ def boot
assert UI::Button.new.respond_to?(:click)
assert_equal "Button clicked!", UI::Button.new.click
end

test "singleton classes can be patched" do
boot

assert User
assert "The outer rim", User.address
end
end
Loading