flickwerk 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4d2a4d44e16f6ffde47572e6eb07314095fb3699141f86042e612a9c6d096203
4
- data.tar.gz: eb5f26ce60eaf28bef486e7985cfcda0d5f818832a6f74c9a62df288984b4eec
3
+ metadata.gz: f5e0ab83481440a9b1050a5de6178a3b70d6f82745e0615f41cd467c3dea954c
4
+ data.tar.gz: 654d07fc6f2765164142c002dacfbebb73517f8a90c3ff5a42b57ed036f30c32
5
5
  SHA512:
6
- metadata.gz: 073d1b4b045bd85a5916377d562bcc8399e858dbd8a0961cc31a043a48e9a00f73784c1c733369c970d26cae265bbad94b2d92f165e98426a7a93b9f40522298
7
- data.tar.gz: 606f5c40e0d1270d2dd3861d2ce3b35918e41973e358c026fc146e10ff5c83b596d8dbaf3d5707af34133491cfc61811a81a89fb9f0276eeb2f30429c41ede24
6
+ metadata.gz: 3902ae52304b8d83e36ef895955d6425dd14594d8e871baa7497ceef02f7b8287aa0c5283823773c937bfb783dbf0b68390f971936750b59fdfec4fafdc0c470
7
+ data.tar.gz: 821e7be27c93ba058af9c262cb131bba535ad1c4d6041dae60e13f063853ffcb881d313260d7d8ea083810b21b4405f149852921b37e4779eb4f8960e4c5c35d
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/[USERNAME]/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).
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Flickwerk
4
- VERSION = "0.2.0"
4
+ VERSION = "0.2.1"
5
5
  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.2.0
4
+ version: 0.2.1
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-04 00:00:00.000000000 Z
11
+ date: 2024-12-16 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