talented_tools 0.0.1 → 1.0.1

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