flickwerk 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +21 -1
- data/exe/flickwerk +13 -0
- data/lib/flickwerk/patchify.rb +38 -0
- data/lib/flickwerk/railtie.rb +9 -5
- data/lib/flickwerk/version.rb +1 -1
- data/lib/flickwerk.rb +3 -1
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a2282cc97b8ee8bb05493ba03cf1ed27690fdffacf62bb8ff203b6db3bf6c36c
|
4
|
+
data.tar.gz: 943a5ae6ec43be5b7139ba5b578335339564cb0ab832a0038250a58e005e46cc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7a93c5ffc75887ee60dde2635995ac097b70fe6b068106be82a173106eeb9c8d122e38053f9e42880940434fde943adf6b2bc02fab3965da252819c1880f2a89
|
7
|
+
data.tar.gz: 28891d06643e9cc430a5b793704abe65baa14825af3bf49a52bcc07fa9e4c32bcdce56a97e0b8f16f70ce3b125c9dcf3efaf64d09b8e0cf21e44b18191b3cc5b
|
data/README.md
CHANGED
@@ -175,6 +175,26 @@ class MyGem::Engine
|
|
175
175
|
end
|
176
176
|
```
|
177
177
|
|
178
|
+
## Transitioning from app/decorators to app/patches
|
179
|
+
|
180
|
+
Due to the Rails Engine documentation telling people to put their patches in either `app/decorators` or `app/overrides`, that's where a lot of patches currently live. Flickwerk provides a script to help you move your "decorators" or "overrides" to `app/patches` and do the necessary changes in terms of file and constant names.
|
181
|
+
|
182
|
+
If your patches currently live in `app/decorators`, run
|
183
|
+
|
184
|
+
```sh
|
185
|
+
bundle exec flickwerk patchify
|
186
|
+
```
|
187
|
+
|
188
|
+
Flickwerk will now move your decorators and rename them.
|
189
|
+
|
190
|
+
If your patches currently live in `app/overrides`, use an argument:
|
191
|
+
|
192
|
+
```sh
|
193
|
+
bundle exec flickwerk patchify overrides
|
194
|
+
```
|
195
|
+
|
196
|
+
Now, run your tests and make sure your patches comply with Flickwerk's requirements.
|
197
|
+
|
178
198
|
## Considerations
|
179
199
|
|
180
200
|
### Aren't patches bad?
|
@@ -195,7 +215,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
195
215
|
|
196
216
|
## Contributing
|
197
217
|
|
198
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
218
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/friendlycart/flickwerk. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/flickwerk/blob/main/CODE_OF_CONDUCT.md).
|
199
219
|
|
200
220
|
## License
|
201
221
|
|
data/exe/flickwerk
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "bundler/setup"
|
5
|
+
require "flickwerk"
|
6
|
+
require "flickwerk/patchify"
|
7
|
+
|
8
|
+
case ARGV[0]
|
9
|
+
when "patchify"
|
10
|
+
Flickwerk::Patchify.call(ARGV[1])
|
11
|
+
else
|
12
|
+
raise ArgumentError, "Unknown command #{ARGV[0]}. Please use `patchify`."
|
13
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_support/core_ext/string"
|
4
|
+
|
5
|
+
module Flickwerk
|
6
|
+
class Patchify
|
7
|
+
PATCHES_DIR = "app/patches"
|
8
|
+
def self.call(directory_name)
|
9
|
+
directory_name ||= "decorators"
|
10
|
+
source_dir = "app/#{directory_name}"
|
11
|
+
suffix = directory_name.singularize
|
12
|
+
constant = suffix.camelize
|
13
|
+
|
14
|
+
Dir.glob("#{source_dir}/**/*_#{suffix}.rb").each do |file|
|
15
|
+
relative_path = file.sub(/^#{source_dir}\//, "")
|
16
|
+
target_file = relative_path.sub("_#{suffix}.rb", "_patch.rb")
|
17
|
+
target_path = File.join(PATCHES_DIR, File.dirname(relative_path))
|
18
|
+
|
19
|
+
# Create target directory if it doesn't exist
|
20
|
+
FileUtils.mkdir_p(target_path)
|
21
|
+
|
22
|
+
# Read and modify file content
|
23
|
+
content = File.read(file)
|
24
|
+
modified_content = content.gsub(/(\w+::)*\w+#{constant}\b/) do |match|
|
25
|
+
match.sub(constant, "Patch")
|
26
|
+
end
|
27
|
+
|
28
|
+
# Write to the new file
|
29
|
+
File.write(File.join(target_path, File.basename(target_file)), modified_content)
|
30
|
+
|
31
|
+
# Delete the original file
|
32
|
+
File.delete(file)
|
33
|
+
|
34
|
+
puts "Moved and updated: #{file} -> #{File.join(target_path, File.basename(target_file))}"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/lib/flickwerk/railtie.rb
CHANGED
@@ -10,13 +10,17 @@ class Flickwerk::Railtie < Rails::Railtie
|
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
-
initializer "flickwerk.find_patches"
|
14
|
-
|
15
|
-
Flickwerk
|
13
|
+
initializer "flickwerk.find_patches" do |app|
|
14
|
+
app.config.to_prepare do
|
15
|
+
Flickwerk.patch_paths.each do |path|
|
16
|
+
Flickwerk::PatchFinder.new(path).call
|
17
|
+
end
|
16
18
|
end
|
17
19
|
end
|
18
20
|
|
19
|
-
initializer "flickwerk.add_patches", after: "flickwerk.find_patches" do
|
20
|
-
|
21
|
+
initializer "flickwerk.add_patches", after: "flickwerk.find_patches" do |app|
|
22
|
+
app.config.to_prepare do
|
23
|
+
Flickwerk::PatchLoader.call
|
24
|
+
end
|
21
25
|
end
|
22
26
|
end
|
data/lib/flickwerk/version.rb
CHANGED
data/lib/flickwerk.rb
CHANGED
@@ -9,6 +9,7 @@ module Flickwerk
|
|
9
9
|
|
10
10
|
mattr_accessor :patch_paths, default: []
|
11
11
|
mattr_accessor :patches, default: Hash.new([])
|
12
|
+
mattr_accessor :aliases, default: {}
|
12
13
|
|
13
14
|
def self.included(engine)
|
14
15
|
engine.root.glob("app/patches/*").each do |path|
|
@@ -17,6 +18,7 @@ module Flickwerk
|
|
17
18
|
end
|
18
19
|
|
19
20
|
def self.patch(class_name, with:)
|
20
|
-
|
21
|
+
klass_name = aliases[class_name] || class_name
|
22
|
+
patches[klass_name] += [with]
|
21
23
|
end
|
22
24
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flickwerk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Martin Meyerhoff
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-12-
|
11
|
+
date: 2024-12-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|
@@ -27,7 +27,8 @@ dependencies:
|
|
27
27
|
description: Support for lazy loading patches in Rails engines
|
28
28
|
email:
|
29
29
|
- mamhoff@gmail.com
|
30
|
-
executables:
|
30
|
+
executables:
|
31
|
+
- flickwerk
|
31
32
|
extensions: []
|
32
33
|
extra_rdoc_files: []
|
33
34
|
files:
|
@@ -37,9 +38,11 @@ files:
|
|
37
38
|
- LICENSE.txt
|
38
39
|
- README.md
|
39
40
|
- Rakefile
|
41
|
+
- exe/flickwerk
|
40
42
|
- lib/flickwerk.rb
|
41
43
|
- lib/flickwerk/patch_finder.rb
|
42
44
|
- lib/flickwerk/patch_loader.rb
|
45
|
+
- lib/flickwerk/patchify.rb
|
43
46
|
- lib/flickwerk/railtie.rb
|
44
47
|
- lib/flickwerk/version.rb
|
45
48
|
- sig/flickwerk.rbs
|