Skip to content

Commit

Permalink
Merge pull request #11 from friendlycart/fix-patch-regex
Browse files Browse the repository at this point in the history
Expect patched class to begin with capital letter
  • Loading branch information
tvdeyen authored Jan 22, 2025
2 parents 393b072 + bbb0972 commit 10f7df2
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 8 deletions.
26 changes: 21 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Ruby
name: CI

on:
push:
Expand All @@ -8,20 +8,36 @@ on:
pull_request:

jobs:
build:
test:
runs-on: ubuntu-latest
name: Ruby ${{ matrix.ruby }}
name: Test with Ruby ${{ matrix.ruby }}
strategy:
matrix:
ruby:
- '3.2.6'

steps:
- uses: actions/checkout@v4
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true
- name: Run the default task
- name: Run tests
run: bundle exec rake

lint:
runs-on: ubuntu-latest
name: Lint with Ruby ${{ matrix.ruby }}
strategy:
matrix:
ruby:
- '3.2.6'
steps:
- uses: actions/checkout@v4
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true
- name: Lint code
run: bundle exec rake standard
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ Minitest::TestTask.create

require "standard/rake"

task default: %i[test standard]
task default: %i[test]
2 changes: 1 addition & 1 deletion lib/flickwerk.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module Flickwerk
class Error < StandardError; end

mattr_accessor :patch_paths, default: []
mattr_accessor :patches, default: Hash.new([])
mattr_accessor :patches, default: Hash.new { [] }
mattr_accessor :aliases, default: {}

def self.included(engine)
Expand Down
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 10f7df2

Please sign in to comment.