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

Patchify: Allow patchifying file in lib/ #7

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
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,13 @@ Flickwerk will now move your decorators and rename them.
If your patches currently live in `app/overrides`, use an argument:

```sh
bundle exec flickwerk patchify overrides
bundle exec flickwerk patchify app/overrides
```

If you have patches in `lib`, they can be moved to `lib/patches`:

```sh
bundle exec flickwerk patchify lib/decorators lib/patches
```

Now, run your tests and make sure your patches comply with Flickwerk's requirements.
Expand Down
2 changes: 1 addition & 1 deletion exe/flickwerk
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require "flickwerk/patchify"

case ARGV[0]
when "patchify"
Flickwerk::Patchify.call(ARGV[1])
Flickwerk::Patchify.call(decorator_dir: ARGV[1] || "app/decorators", patches_dir: ARGV[2] || "app/patches")
else
raise ArgumentError, "Unknown command #{ARGV[0]}. Please use `patchify`."
end
12 changes: 5 additions & 7 deletions lib/flickwerk/patchify.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,15 @@

module Flickwerk
class Patchify
PATCHES_DIR = "app/patches"
def self.call(directory_name)
directory_name ||= "decorators"
source_dir = "app/#{directory_name}"
def self.call(decorator_dir:, patches_dir:)
directory_name = decorator_dir.split("/").last
suffix = directory_name.singularize
constant = suffix.camelize

Dir.glob("#{source_dir}/**/*_#{suffix}.rb").each do |file|
relative_path = file.sub(/^#{source_dir}\//, "")
Dir.glob("#{decorator_dir}/**/*_#{suffix}.rb").each do |file|
relative_path = file.sub(/^#{decorator_dir}\//, "")
target_file = relative_path.sub("_#{suffix}.rb", "_patch.rb")
target_path = File.join(PATCHES_DIR, File.dirname(relative_path))
target_path = File.join(patches_dir, File.dirname(relative_path))

# Create target directory if it doesn't exist
FileUtils.mkdir_p(target_path)
Expand Down
Loading