Skip to content

Commit

Permalink
Expect patched class to begin with capital letter
Browse files Browse the repository at this point in the history
In order to not consider a prepended base class a patch
we expect the patched class constant to begin with a capital
letter.
  • Loading branch information
tvdeyen committed Jan 22, 2025
1 parent 393b072 commit 60c8682
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
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.:]+?)(?:\.singleton_class)?\.prepend[\s(]/
DECORATED_CLASS_PATTERN = /(?:::)?(?<decorated_class>[A-Z][\w.:]+?)(?:\.singleton_class)?\.prepend[\s(]/

attr_reader :path, :autoloader

Expand Down
10 changes: 10 additions & 0 deletions test/dummy_app/app/patches/models/page_patch.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
module PagePatch
def self.prepended(base)
base.prepend(InstanceMethods)
end

def title
"Changed from Host app"
end

module InstanceMethods
def name
"Homepage"
end
end

::DummyCms::Page.prepend(self)
end
9 changes: 9 additions & 0 deletions test/test_flickwerk.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,13 @@ def boot
assert User
assert "The outer rim", User.address
end

test "prepended base class can be prepended" do
require "dummy_cms"

boot

assert DummyCms::Page
assert_equal [], Flickwerk.patches["base"]
end
end

0 comments on commit 60c8682

Please sign in to comment.