-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathmigrate.rb
125 lines (91 loc) · 3.89 KB
/
migrate.rb
1
2
3
4
5
6
7
8
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
require "active_support/inflector"
def migrate_resources
# Get the directory path and the replacement string from the command line
dir_path = './app/avo/resources'
# replacement_string = ARGV[1]
# Get a list of all files in the directory
files = Dir.entries(dir_path)
# Loop through each file in the directory
files.each do |file|
# Skip over directories and hidden files
next if File.directory?(file) || file.start_with?(".")
# Get the file extension
file_ext = File.extname(file)
# Get the file name without the extension
file_name = File.basename(file, file_ext)
new_file_name = file_name.gsub("_resource", "")
# Read the contents of the file
file_contents = File.read("#{dir_path}/#{file}")
new_klass_def = "class Avo::Resources::#{new_file_name.to_s.classify} < Avo::BaseResource"
# puts ["new_klass_def->", new_klass_def].inspect
# Replace the string in the contents
new_contents = file_contents.gsub(/.*< Avo::BaseResource/, new_klass_def)
# Construct the new file name with the replacement string
new_file_name = "#{new_file_name}#{file_ext}"
# Write the updated contents to a new file with the new name
File.write("#{dir_path}/#{new_file_name}", new_contents)
# Delete the original file
File.delete("#{dir_path}/#{file}")
end
end
def migrate_actions
# Get the directory path and the replacement string from the command line
dir_path = './app/avo/actions'
# replacement_string = ARGV[1]
# Get a list of all files in the directory
files = Dir.entries(dir_path)
# Loop through each file in the directory
files.each do |file|
# Skip over directories and hidden files
next if File.directory?(file) || file.start_with?(".")
# Get the file extension
file_ext = File.extname(file)
# Get the file name without the extension
file_name = File.basename(file, file_ext)
new_file_name = file_name.gsub("_action", "")
# Read the contents of the file
file_contents = File.read("#{dir_path}/#{file}")
new_klass_def = "class Avo::Actions::#{new_file_name.to_s.classify} < Avo::BaseAction"
# puts ["new_klass_def->", new_klass_def].inspect
# Replace the string in the contents
new_contents = file_contents.gsub(/.*< Avo::BaseAction/, new_klass_def)
# Construct the new file name with the replacement string
new_file_name = "#{new_file_name}#{file_ext}"
# Write the updated contents to a new file with the new name
File.write("#{dir_path}/#{new_file_name}", new_contents)
# Delete the original file
File.delete("#{dir_path}/#{file}")
end
end
def migrate_filters
# Get the directory path and the replacement string from the command line
dir_path = './app/avo/filters'
# replacement_string = ARGV[1]
# Get a list of all files in the directory
files = Dir.entries(dir_path)
# Loop through each file in the directory
files.each do |file|
# Skip over directories and hidden files
next if File.directory?(file) || file.start_with?(".")
# Get the file extension
file_ext = File.extname(file)
# Get the file name without the extension
file_name = File.basename(file, file_ext)
new_file_name = file_name.gsub("_filter", "")
# Read the contents of the file
file_contents = File.read("#{dir_path}/#{file}")
new_klass_def = "class Avo::Filters::#{new_file_name.to_s.classify} < Avo::BaseFilter"
# puts ["new_klass_def->", new_klass_def].inspect
# Replace the string in the contents
new_contents = file_contents.gsub(/.*< Avo::BaseFilter/, new_klass_def)
# Construct the new file name with the replacement string
new_file_name = "#{new_file_name}#{file_ext}"
# Write the updated contents to a new file with the new name
File.write("#{dir_path}/#{new_file_name}", new_contents)
# Delete the original file
File.delete("#{dir_path}/#{file}")
end
end
# migrate_resources
# migrate_actions
migrate_filters