talented_tools 1.0.2 → 1.0.3

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 +99 -1
  3. metadata +8 -8
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b7e66c36db9b2fe00984513144808b1b991ddfb8a21fb6fd4196a7580842e0e7
4
- data.tar.gz: 756ab6461aacd6873752f58d9c3717fe5c601bea14e509d691baf19abee28e41
3
+ metadata.gz: 76a828d5ceb2ab541e500f9e75231c95c237a95cc130c4b8c8e8e61c62d07f6b
4
+ data.tar.gz: fc94d36dfbc6fe9c8675acef1c6684aaa1da99ffb66996abf9bfeab75c94902a
5
5
  SHA512:
6
- metadata.gz: c63dd48077198c889978d6fc7e6cc4870a7eaa718044a9f903ad8bdba20ac2620e22e354cc65a08b2feb8b615b14598b49db59509f24ced995fad6ab0d17e03b
7
- data.tar.gz: 3feffc383a12107b707378fcce29dbec1d975224f076213871987517c203e1777886f33910f4c91531ccd0e10d64aad0d200a3c69fc07db90836b6f5e7df293e
6
+ metadata.gz: 4607e720e6ec102bba69fef6ffeb971a4ceec25dd29f768dd8e9ad6351aa5ba4dd4af8e0e77775f3258413d04954950f797276552556aa8e2af4384c49cef9b5
7
+ data.tar.gz: 0350ebab752a09ae8f7701677c8dc8f950fa6b2330e51b03c6f4094b97f7347bd5532a893f283adb9584223da27c4862f2bbee6f47b53b192546952026fb9891
@@ -251,4 +251,102 @@ class TalentedTools
251
251
  File.write("app/services/#{@singular_end_point_name}_service.rb", result)
252
252
  end
253
253
 
254
- end
254
+ # IMPLEMENT ATTRIBUTE
255
+ def find_all_method( end_point, attribute, greater_lower )
256
+ find_all_controller(end_point, attribute)
257
+ find_all_model(end_point, attribute)
258
+ find_methods(end_point, attribute)
259
+ if greater_lower.present?
260
+ greater_methods(end_point, attribute, greater_lower)
261
+ lower_methods(end_point, attribute, greater_lower)
262
+
263
+ end
264
+ end
265
+
266
+ def find_all_controller(end_point, attribute)
267
+ lines = File.readlines("app/controllers/#{end_point}_controller.rb")
268
+
269
+ target_index = lines.find_index { |line| line.include?("params.permit(") }
270
+
271
+ new_line = " :#{attribute},\n"
272
+ lines.insert(target_index + 1, new_line)
273
+ File.open("app/controllers/#{end_point}_controller.rb", 'w') do |file|
274
+ file.puts lines
275
+ end
276
+ end
277
+
278
+ def find_all_model(end_point, attribute)
279
+ file_contents = File.read("app/models/#{end_point.singularize}.rb")
280
+
281
+ target_word = " .by_not_deleted_at"
282
+ target_index = file_contents.index(target_word, file_contents.index(target_word))
283
+
284
+ new_line = "\n .by_#{attribute}(params[:""#{attribute}""])"
285
+ file_contents.insert(target_index + target_word.length, new_line)
286
+ File.write("app/models/#{end_point.singularize}.rb", file_contents)
287
+
288
+ target_word = " .by_not_deleted_at"
289
+ target_index = file_contents.index(target_word, file_contents.index(target_word))
290
+
291
+ new_line = "\n .by_#{attribute}(params[:""#{attribute}""])"
292
+ file_contents.insert(target_index + target_word.length, new_line)
293
+ File.write("app/models/#{end_point.singularize}.rb", file_contents)
294
+ end
295
+
296
+ def find_methods(end_point, attribute)
297
+ method = " def self.by_#{attribute}(#{attribute})\n return all unless #{attribute}.present?\n\n where(#{attribute}: #{attribute})\n end"
298
+
299
+ file = File.open("app/models/#{end_point.singularize}.rb", "r")
300
+ content = file.read
301
+ last_end_index = content.rindex(/\bend\b/)
302
+ new_content = content.insert(last_end_index -1, "\n#{method}\n")
303
+ file.close
304
+
305
+ File.open("app/models/#{end_point.singularize}.rb", "w") do |f|
306
+ f.write(new_content)
307
+ end
308
+ end
309
+
310
+ def greater_methods(end_point, attribute, greater_lower)
311
+ string_variable = "#{attribute} <= \#{payload}"
312
+
313
+ method = " def self.by_#{attribute}_gt(payload)\n return all unless payload.present?\n\n where(\""'VARIABLE'"\")\n end"
314
+
315
+ file = File.open("app/models/#{end_point.singularize}.rb", "r")
316
+ content = file.read
317
+ last_end_index = content.rindex(/\bend\b/)
318
+ new_content = content.insert(last_end_index -1, "\n#{method}\n")
319
+ file.close
320
+
321
+ File.open("app/models/#{end_point.singularize}.rb", "w") do |f|
322
+ f.write(new_content)
323
+ end
324
+
325
+ new_content = content.gsub("VARIABLE", string_variable)
326
+ File.write("app/models/#{end_point.singularize}.rb", new_content)
327
+
328
+ attribute_gt = "#{attribute}_gt"
329
+ find_all_controller(end_point, attribute_gt)
330
+ end
331
+
332
+ def lower_methods(end_point, attribute, greater_lower)
333
+ string_variable = "#{attribute} >= \#{payload}"
334
+
335
+ method = " def self.by_#{attribute}_lt(payload)\n return all unless payload.present?\n\n where(\""'VARIABLE'"\")\n end"
336
+ file = File.open("app/models/#{end_point.singularize}.rb", "r+")
337
+ content = file.read
338
+ last_end_index = content.rindex(/\bend\b/)
339
+ new_content = content.insert(last_end_index -1, "\n#{method}\n")
340
+ file.close
341
+
342
+ File.open("app/models/#{end_point.singularize}.rb", "w") do |f|
343
+ f.write(new_content)
344
+ end
345
+
346
+ new_content = content.gsub("VARIABLE", string_variable)
347
+ File.write("app/models/#{end_point.singularize}.rb", new_content)
348
+
349
+ attribute_lt = "#{attribute}_lt"
350
+ find_all_controller(end_point, attribute_lt)
351
+ end
352
+ 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: 1.0.2
4
+ version: 1.0.3
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-08 00:00:00.000000000 Z
11
+ date: 2023-05-09 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: A script that creates a full basic project
13
+ description: A simple hello world gem
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.1.4
40
- signing_key:
39
+ rubygems_version: 3.0.3.1
40
+ signing_key:
41
41
  specification_version: 4
42
- summary: Creates a full basic project
42
+ summary: Initial test
43
43
  test_files: []