9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/flickwerk/patchify.rb', line 9
def self.call(decorator_dir:, patches_dir:)
directory_name = decorator_dir.split("/").last
suffix = directory_name.singularize
constant = suffix.camelize
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))
FileUtils.mkdir_p(target_path)
content = File.read(file)
modified_content = content.gsub(/(\w+::)*\w+#{constant}\b/) do |match|
match.sub(constant, "Patch")
end
File.write(File.join(target_path, File.basename(target_file)), modified_content)
File.delete(file)
puts "Moved and updated: #{file} -> #{File.join(target_path, File.basename(target_file))}"
end
end
|