talented_tools 0.0.1 → 1.0.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/lib/talented_tools.rb +249 -2
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5c67604038fbd5dcd7138a27e2faf1678bb45a88ab10d2b98031a69b6ac33374
|
4
|
+
data.tar.gz: 23ea2ea84577b27759d677a3ea0ce604e0f6b94b3661627cf8c093a9dc70e054
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b1bbe8a29be2649a60ed24e4e16d101b65953b634121cb3f1cba8719835de644c50c60152658ba615adb065ba7923bc27ff2c7b31c3b7efd1215ec567020eb26
|
7
|
+
data.tar.gz: e02a5ebbd40899f6eb26d392a699c4fa3af5864483535483fa6548a90e6546e375860d18b9aef85e37b2d6a47d1c9f244474604f88f1c444b439d3236043dd4c
|
data/lib/talented_tools.rb
CHANGED
@@ -1,5 +1,252 @@
|
|
1
1
|
class TalentedTools
|
2
|
-
def
|
3
|
-
puts 'Hello world'
|
2
|
+
def initialize
|
4
3
|
end
|
4
|
+
|
5
|
+
def create_end_point(name)
|
6
|
+
format_name(name)
|
7
|
+
create_route
|
8
|
+
create_controllers
|
9
|
+
create_services
|
10
|
+
create_models
|
11
|
+
create_presenters
|
12
|
+
|
13
|
+
puts "Successfully created #{name} endpoint!"
|
14
|
+
end
|
15
|
+
|
16
|
+
def format_name(name)
|
17
|
+
@formated_camel_case = format_camel_case(name)
|
18
|
+
@singular_format = name.singularize
|
19
|
+
@plural_format = name.pluralize
|
20
|
+
@route_format = format_route_name(name)
|
21
|
+
end
|
22
|
+
|
23
|
+
def format_camel_case(name)
|
24
|
+
camel_case_names = []
|
25
|
+
|
26
|
+
split_name = name.split('_')
|
27
|
+
split_name.each do |t|
|
28
|
+
camel_case_names.push(t.capitalize)
|
29
|
+
end
|
30
|
+
result = camel_case_names.join(", ").gsub(", ", "")
|
31
|
+
|
32
|
+
result
|
33
|
+
end
|
34
|
+
|
35
|
+
def format_route_name(name)
|
36
|
+
return name unless name.include?("_")
|
37
|
+
result = name.gsub("_", "-")
|
38
|
+
|
39
|
+
result
|
40
|
+
end
|
41
|
+
|
42
|
+
def create_route
|
43
|
+
file_in = File.open("resources/templates/routes_base.rb", "r")
|
44
|
+
content = file_in.read
|
45
|
+
|
46
|
+
replacements = {
|
47
|
+
"singular" => "#{@singular_format}",
|
48
|
+
"plural" => "#{@plural_format}",
|
49
|
+
"route_format" => "#{@route_format}"
|
50
|
+
}
|
51
|
+
result = content.gsub(/#{Regexp.union(replacements.keys)}/, replacements)
|
52
|
+
file_in = File.open("tmp.txt", "a+")
|
53
|
+
file_in.write(result)
|
54
|
+
file_in.close
|
55
|
+
|
56
|
+
file_origin = File.open("tmp.txt", "r")
|
57
|
+
content = file_origin.read
|
58
|
+
file_origin.close
|
59
|
+
|
60
|
+
last_line = 0
|
61
|
+
file = File.open("config/routes.rb", "r+")
|
62
|
+
file.each { last_line = file.pos unless file.eof? }
|
63
|
+
file.seek(last_line, IO::SEEK_SET)
|
64
|
+
file.write("\n#{content}\n \n end")
|
65
|
+
file.close
|
66
|
+
|
67
|
+
system("rm -rf tmp.txt")
|
68
|
+
end
|
69
|
+
|
70
|
+
def create_controllers
|
71
|
+
constroller_base = File.open("resources/templates/controllers_base.rb")
|
72
|
+
content = constroller_base.read
|
73
|
+
|
74
|
+
replacements = {
|
75
|
+
"NameController" => "#{@formated_camel_case}Controller",
|
76
|
+
"NameService" => "#{@formated_camel_case.singularize}Service",
|
77
|
+
"NamePresenter" => "#{@formated_camel_case.singularize}Presenter",
|
78
|
+
"singular" => "#{@singular_format}",
|
79
|
+
"plural" => @plural_format,
|
80
|
+
}
|
81
|
+
result = content.gsub(/#{Regexp.union(replacements.keys)}/, replacements)
|
82
|
+
|
83
|
+
file_in = File.open("tmp.rb", "a+")
|
84
|
+
file_in.write(result)
|
85
|
+
file_in.close
|
86
|
+
|
87
|
+
file_content = File.read("tmp.rb")
|
88
|
+
|
89
|
+
File.write("app/controllers/#{@plural_format}_controller.rb", file_content)
|
90
|
+
|
91
|
+
system("rm -rf tmp.rb")
|
92
|
+
end
|
93
|
+
|
94
|
+
def create_services
|
95
|
+
name_class = @formated_camel_case.singularize
|
96
|
+
|
97
|
+
services_base = File.open("resources/templates/services_base.rb")
|
98
|
+
content = services_base.read
|
99
|
+
|
100
|
+
replacements = {
|
101
|
+
"Name" => name_class,
|
102
|
+
"singular" => @singular_format
|
103
|
+
}
|
104
|
+
result = content.gsub(/#{Regexp.union(replacements.keys)}/, replacements)
|
105
|
+
|
106
|
+
file_in = File.open("tmp.rb", "a+")
|
107
|
+
file_in.write(result)
|
108
|
+
file_in.close
|
109
|
+
|
110
|
+
file_content = File.read("tmp.rb")
|
111
|
+
|
112
|
+
File.write("app/services/#{@singular_format}_service.rb", file_content)
|
113
|
+
|
114
|
+
system("rm -rf tmp.rb")
|
115
|
+
end
|
116
|
+
|
117
|
+
def create_models
|
118
|
+
|
119
|
+
models_base = File.open("resources/templates/models_base.rb")
|
120
|
+
content = models_base.read
|
121
|
+
|
122
|
+
replacements = {
|
123
|
+
"ClassName" => @formated_camel_case.singularize,
|
124
|
+
"single" => @singular_format,
|
125
|
+
"plural" => @plural_format
|
126
|
+
}
|
127
|
+
result = content.gsub(/#{Regexp.union(replacements.keys)}/, replacements)
|
128
|
+
|
129
|
+
file_in = File.open("tmp.rb", "a+")
|
130
|
+
file_in.write(result)
|
131
|
+
file_in.close
|
132
|
+
|
133
|
+
file_content = File.read("tmp.rb")
|
134
|
+
|
135
|
+
File.write("app/models/#{@singular_format}.rb", file_content)
|
136
|
+
|
137
|
+
system("rm -rf tmp.rb")
|
138
|
+
end
|
139
|
+
|
140
|
+
def create_presenters
|
141
|
+
|
142
|
+
presenters_base = File.open("resources/templates/presenters_base.rb")
|
143
|
+
content = presenters_base.read
|
144
|
+
|
145
|
+
replacements = {
|
146
|
+
"ClassName" => @formated_camel_case.singularize,
|
147
|
+
"single" => @singular_format,
|
148
|
+
"plural" => @plural_format
|
149
|
+
}
|
150
|
+
result = content.gsub(/#{Regexp.union(replacements.keys)}/, replacements)
|
151
|
+
|
152
|
+
file_in = File.open("tmp.rb", "a+")
|
153
|
+
file_in.write(result)
|
154
|
+
file_in.close
|
155
|
+
|
156
|
+
file_content = File.read("tmp.rb")
|
157
|
+
|
158
|
+
File.write("app/presenters/#{@singular_format}_presenter.rb", file_content)
|
159
|
+
|
160
|
+
system("rm -rf tmp.rb")
|
161
|
+
end
|
162
|
+
|
163
|
+
# UNNATURAL IDEMPOTENCY_KEY
|
164
|
+
def implement_unnatural_key(end_point_name)
|
165
|
+
format_unnatural_end_point_name(end_point_name)
|
166
|
+
|
167
|
+
unnatural_implement_controller
|
168
|
+
unnatural_implement_services
|
169
|
+
end
|
170
|
+
|
171
|
+
def format_unnatural_end_point_name(end_point_name)
|
172
|
+
@end_point_name = end_point_name
|
173
|
+
@singular_end_point_name = end_point_name.singularize
|
174
|
+
end
|
175
|
+
|
176
|
+
def unnatural_implement_controller
|
177
|
+
constroller_base = File.open("app/controllers/#{@end_point_name}_controller.rb")
|
178
|
+
content = constroller_base.read
|
179
|
+
|
180
|
+
replacements = {
|
181
|
+
"#name_idempotency_unnatural_controller" => "idempotency_key = headers['x-idempotency-key']",
|
182
|
+
"name_create_controller_params" => "valid_params, idempotency_key: idempotency_key"
|
183
|
+
}
|
184
|
+
|
185
|
+
result = content.gsub(/#{Regexp.union(replacements.keys)}/, replacements)
|
186
|
+
|
187
|
+
File.write("app/controllers/#{@end_point_name}_controller.rb", result)
|
188
|
+
|
189
|
+
end
|
190
|
+
|
191
|
+
def unnatural_implement_services
|
192
|
+
service_base = File.open("app/services/#{@singular_end_point_name}_service.rb")
|
193
|
+
content = service_base.read
|
194
|
+
|
195
|
+
replacements = {
|
196
|
+
"#unnatural_services_create_nil_validate" => "return [@model, :idempotency_key_not_present] if idempotency_key.nil?",
|
197
|
+
"@model.idempotency_name" => "@idempotency_key"
|
198
|
+
}
|
199
|
+
|
200
|
+
result = content.gsub(/#{Regexp.union(replacements.keys)}/, replacements)
|
201
|
+
|
202
|
+
File.write("app/services/#{@singular_end_point_name}_service.rb", result)
|
203
|
+
|
204
|
+
end
|
205
|
+
|
206
|
+
# NATURAL IDEMPOTENCY_KEY
|
207
|
+
def implement_natural_key(end_point_name, idempotency_name)
|
208
|
+
format_natural_end_point_name(end_point_name)
|
209
|
+
format_natural_idempotency(idempotency_name)
|
210
|
+
|
211
|
+
natural_implement_controller
|
212
|
+
natural_implement_services
|
213
|
+
end
|
214
|
+
|
215
|
+
def format_natural_end_point_name(end_point_name)
|
216
|
+
@end_point_name = end_point_name
|
217
|
+
@singular_end_point_name = end_point_name.singularize
|
218
|
+
end
|
219
|
+
|
220
|
+
def format_natural_idempotency(idempotency_name)
|
221
|
+
@idempotency_name = idempotency_name
|
222
|
+
end
|
223
|
+
|
224
|
+
def natural_implement_controller
|
225
|
+
constroller_base = File.open("app/controllers/#{@end_point_name}_controller.rb")
|
226
|
+
content = constroller_base.read
|
227
|
+
|
228
|
+
replacements = {
|
229
|
+
"#name_idempotency_unnatural_controller" => " ",
|
230
|
+
"name_create_controller_params" => "valid_params"
|
231
|
+
}
|
232
|
+
|
233
|
+
result = content.gsub(/#{Regexp.union(replacements.keys)}/, replacements)
|
234
|
+
|
235
|
+
File.write("app/controllers/#{@end_point_name}_controller.rb", result)
|
236
|
+
end
|
237
|
+
|
238
|
+
def natural_implement_services
|
239
|
+
service_base = File.open("app/services/#{@singular_end_point_name}_service.rb")
|
240
|
+
content = service_base.read
|
241
|
+
|
242
|
+
replacements = {
|
243
|
+
"#unnatural_services_create_nil_validate" => " ",
|
244
|
+
"idempotency_name" => "#{@idempotency_name}"
|
245
|
+
}
|
246
|
+
|
247
|
+
result = content.gsub(/#{Regexp.union(replacements.keys)}/, replacements)
|
248
|
+
|
249
|
+
File.write("app/services/#{@singular_end_point_name}_service.rb", result)
|
250
|
+
end
|
251
|
+
|
5
252
|
end
|
metadata
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: talented_tools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sergio Manchini
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
date: 2023-05-07 00:00:00.000000000 Z
|
@@ -21,7 +21,7 @@ homepage: https://rubygems.org/gems/talented_tools
|
|
21
21
|
licenses:
|
22
22
|
- MIT
|
23
23
|
metadata: {}
|
24
|
-
post_install_message:
|
24
|
+
post_install_message:
|
25
25
|
rdoc_options: []
|
26
26
|
require_paths:
|
27
27
|
- lib
|
@@ -36,8 +36,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
36
36
|
- !ruby/object:Gem::Version
|
37
37
|
version: '0'
|
38
38
|
requirements: []
|
39
|
-
rubygems_version: 3.
|
40
|
-
signing_key:
|
39
|
+
rubygems_version: 3.1.4
|
40
|
+
signing_key:
|
41
41
|
specification_version: 4
|
42
42
|
summary: Initial test
|
43
43
|
test_files: []
|