flickwerk 0.1.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: 8e651efd8959c74f5444b298eee3a2cd6025be555990fab13877af551bfb23c3
4
- data.tar.gz: a204baaa6ca697496c95cb17afa877c1be9c68f2e7bd8160ee68c94ddd41bfb3
3
+ metadata.gz: f5e0ab83481440a9b1050a5de6178a3b70d6f82745e0615f41cd467c3dea954c
4
+ data.tar.gz: 654d07fc6f2765164142c002dacfbebb73517f8a90c3ff5a42b57ed036f30c32
5
5
  SHA512:
6
- metadata.gz: e05aeceb1d30f4763a4f0fe31d064c3eed9251a51da3a8498ec2cdb92d1ebd658017ea39204b7553c2734d8f254b9a9fed19703e9c309b508e2bfc930789e0ba
7
- data.tar.gz: c960be6af80cf1d42b710c20c3815284197b93fad2ec1a688730dd2f058f5386c6d2416f4ba5a4ec45e6203538be2cfbcb8eb2d7defede7ea4c290ec163be5e9
6
+ metadata.gz: 3902ae52304b8d83e36ef895955d6425dd14594d8e871baa7497ceef02f7b8287aa0c5283823773c937bfb783dbf0b68390f971936750b59fdfec4fafdc0c470
7
+ data.tar.gz: 821e7be27c93ba058af9c262cb131bba535ad1c4d6041dae60e13f063853ffcb881d313260d7d8ea083810b21b4405f149852921b37e4779eb4f8960e4c5c35d
data/README.md CHANGED
@@ -129,7 +129,7 @@ class MyGem::Engine < Rails::Engine
129
129
  include Flickwerk
130
130
 
131
131
  initializer "my_gem.patch_user_class", before: "flickwerk.add_patches" do
132
- Flickwerk.patch(Spree.class_variable_get(:@@user_class), "MyGem::UserClassPatch"
132
+ Flickwerk.patch(Spree.class_variable_get(:@@user_class), "MyGem::UserClassPatch")
133
133
  end
134
134
  end
135
135
  ```
@@ -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
@@ -10,10 +10,13 @@ class Flickwerk::Railtie < Rails::Railtie
10
10
  end
11
11
  end
12
12
 
13
- initializer "flickwerk.add_patches", after: :setup_main_autoloader do
13
+ initializer "flickwerk.find_patches", after: :setup_main_autoloader do
14
14
  Flickwerk.patch_paths.each do |path|
15
15
  Flickwerk::PatchFinder.new(path).call
16
16
  end
17
+ end
18
+
19
+ initializer "flickwerk.add_patches", after: "flickwerk.find_patches" do
17
20
  Flickwerk::PatchLoader.call
18
21
  end
19
22
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Flickwerk
4
- VERSION = "0.1.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.1.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-02 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