souls 0.29.5 → 0.29.9

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 44391155b6c710dd11e6074752dddd6d495f07abceb9df857b53663a9747fcba
4
- data.tar.gz: bcb6cd5b60ffb949afdb56f2ded4036373bfde9e4d2cce9e408d77fbaa3485c0
3
+ metadata.gz: 0f42d2f3d6688e319d41d7128bf8c8aec080ba33e7639d61d3ac4595f5326da1
4
+ data.tar.gz: 425c1e53138e2a8e3a9d87fb826b1ac1f68d92897df45d61d5051074e7fce6a8
5
5
  SHA512:
6
- metadata.gz: 6fc03249c993388b8f199ad94d8db48859e7306e5128cbc5cf540882f0852cee3f8a0e71242b7619936a00d264f1d2bc8aba7fe5b8901b3e6f532f28d9c1db8a
7
- data.tar.gz: 3411cd55b57ccb9d3fe676159d4060291f3c06578973c8d27e5746de4b95fea4f9102cc7cccd86bc5373f1e92c34e56e94aa5ff65ac93dbc2844f28b2ac0525e
6
+ metadata.gz: 13e648f545612ff19102ef78b873180fcba30d893973b0217322e9a6aed65898c18fa67fdad23b9395f611cc2e16b267b7ae805ef5b34fb7aa44ec75a524ff11
7
+ data.tar.gz: 0f7856f28928f36bd31f659dc5f7679c7027e2fb1590a8efe6be9a529dced80674055507c87ec245e22f6e1d0b9a811c88e6fa178ba4db14f15f0308da9a4b48
data/exe/souls CHANGED
@@ -20,6 +20,13 @@ begin
20
20
  Souls::Api::Generate.public_send(method_name, class_name: class_name)
21
21
  Whirly.status = "Done!"
22
22
  end
23
+ when "schema:update"
24
+ class_name = ARGV[2]
25
+ Souls::Api::Update.create_mutation(class_name: class_name)
26
+ Souls::Api::Update.update_mutation(class_name: class_name)
27
+ Souls::Api::Update.rspec_factory(class_name: class_name)
28
+ Souls::Api::Update.rspec_mutation(class_name: class_name)
29
+ Souls::Api::Update.rspec_resolver(class_name: class_name)
23
30
  else
24
31
  puts(Paint["Comannd doesn't exist.Check you command again!...", :red])
25
32
  end
@@ -160,5 +167,6 @@ begin
160
167
  puts(Paint["Welcome to SOULs!", :green])
161
168
  end
162
169
  rescue StandardError => e
170
+ puts(e.backtrace)
163
171
  puts(Paint[e, :red])
164
172
  end
data/lib/souls.rb CHANGED
@@ -332,15 +332,100 @@ module Souls
332
332
  }
333
333
  end
334
334
 
335
- def detect_change
336
- git_status = `git status`
337
- result =
338
- %w[api worker].map do |service_name|
339
- next unless git_status.include?("apps/#{service_name}/")
335
+ def check_schema(class_name: "user")
336
+ schema_data = get_columns_num(class_name: class_name)
337
+ create_migration_data = get_create_migration_type(class_name: class_name)
338
+ add_migration_data = get_migration_type(class_name: class_name, action: "add")
339
+ remove_migration_data = get_migration_type(class_name: class_name, action: "remove")
340
+ migration_data = create_migration_data + add_migration_data - remove_migration_data
341
+ return "Already Up to date!" if schema_data.size == migration_data.size
340
342
 
341
- service_name
343
+ schema_data - migration_data
344
+ end
345
+
346
+ def get_columns_num(class_name: "user")
347
+ file_path = "./db/schema.rb"
348
+ class_check_flag = false
349
+ cols = []
350
+ File.open(file_path, "r") do |f|
351
+ f.each_line.with_index do |line, _i|
352
+ class_check_flag = true if line.include?("create_table") && line.include?(class_name)
353
+ if class_check_flag == true && !line.include?("create_table")
354
+ return cols if line.include?("t.index") || line.strip == "end"
355
+
356
+ types = Souls::Api::Generate.get_type_and_name(line)
357
+ array = line.include?("array: true")
358
+ cols << { column_name: types[1], type: types[0], array: array }
359
+ end
360
+ end
361
+ end
362
+ cols
363
+ end
364
+
365
+ def get_create_migration_type(class_name: "user")
366
+ pluralized_class_name = class_name.pluralize
367
+ file_path = Dir["db/migrate/*_create_#{pluralized_class_name}.rb"][0]
368
+
369
+ class_check_flag = false
370
+ response = [
371
+ { column_name: "created_at", type: "datetime", array: false },
372
+ { column_name: "updated_at", type: "datetime", array: false }
373
+ ]
374
+ File.open(file_path) do |f|
375
+ f.each_line do |line|
376
+ class_check_flag = true if line.include?("create_table")
377
+ next unless class_check_flag == true && !line.include?("create_table")
378
+ return response if line.include?("t.timestamps") || line.strip == "end"
379
+
380
+ types = Souls::Api::Generate.get_type_and_name(line)
381
+ types.map { |n| n.gsub!(":", "") }
382
+ array = line.include?("array: true")
383
+ response << { column_name: types[1], type: types[0], array: array }
384
+ end
385
+ end
386
+ end
387
+
388
+ def get_migration_type(class_name: "user", action: "add")
389
+ pluralized_class_name = class_name.pluralize
390
+ file_paths = Dir["db/migrate/*_#{action}_column_to_#{pluralized_class_name}.rb"]
391
+
392
+ new_columns =
393
+ file_paths.map do |file_path|
394
+ get_col_name_and_type(class_name: class_name, file_path: file_path, action: action)
395
+ end
396
+ new_columns.flatten
397
+ end
398
+
399
+ def get_last_migration_type(class_name: "user", action: "add")
400
+ pluralized_class_name = class_name.pluralize
401
+ file_paths = Dir["db/migrate/*_#{action}_column_to_#{pluralized_class_name}.rb"]
402
+
403
+ file_paths.max
404
+ resoponse = get_col_name_and_type(class_name: class_name, file_path: file_paths.max, action: action)
405
+ resoponse.flatten
406
+ end
407
+
408
+ def get_col_name_and_type(
409
+ class_name: "user", file_path: "db/migrate/20210816094410_add_column_to_users.rb", action: "add"
410
+ )
411
+ pluralized_class_name = class_name.pluralize
412
+ response = []
413
+ File.open(file_path) do |line|
414
+ line.each_line do |file_line|
415
+ next unless file_line.include?("#{action}_column")
416
+
417
+ array = file_line.include?("array: true")
418
+ types = file_line.split(",").map(&:strip)
419
+ types.map { |n| n.gsub!(":", "") }
420
+ types[0].gsub!("#{action}_column ", "")
421
+ unless types[0].to_s == pluralized_class_name
422
+ raise(StandardError, "Wrong class_name!Please Check your migration file!")
423
+ end
424
+
425
+ response << { column_name: types[1], type: types[2], array: array }
342
426
  end
343
- result.compact
427
+ end
428
+ response
344
429
  end
345
430
 
346
431
  def configure
data/lib/souls/api.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require_relative "./api/generate"
2
+ require_relative "./api/update"
2
3
  module Souls
3
4
  module Api
4
5
  end
@@ -76,14 +76,14 @@ module Souls
76
76
 
77
77
  def self.get_test_type(type)
78
78
  {
79
- bigint: 1,
79
+ bigint: "rand(1..10)",
80
80
  float: 4.2,
81
81
  string: '"MyString"',
82
82
  text: '"MyString"',
83
83
  datetime: "Time.now",
84
- date: "Time.now",
84
+ date: "Time.now.strftime('%F')",
85
85
  boolean: false,
86
- integer: 1
86
+ integer: "rand(1..10)"
87
87
  }[type.to_sym]
88
88
  end
89
89
 
@@ -113,6 +113,7 @@ module Souls
113
113
  policy(class_name: singularized_class_name)
114
114
  rspec_policy(class_name: singularized_class_name)
115
115
  rescue StandardError => e
116
+ puts(e.backtrace)
116
117
  raise(StandardError, e)
117
118
  end
118
119
 
@@ -9,27 +9,27 @@ module Souls
9
9
 
10
10
  def add_column(class_name: "user")
11
11
  pluralized_class_name = class_name.underscore.pluralize
12
- system("rake db:create_migration NAME=add_#{pluralized_class_name}")
12
+ system("rake db:create_migration NAME=add_column_to_#{pluralized_class_name}")
13
13
  end
14
14
 
15
15
  def rename_column(class_name: "user")
16
16
  pluralized_class_name = class_name.underscore.pluralize
17
- system("rake db:create_migration NAME=rename_#{pluralized_class_name}")
17
+ system("rake db:create_migration NAME=rename_column_to_#{pluralized_class_name}")
18
18
  end
19
19
 
20
20
  def change_column(class_name: "user")
21
21
  pluralized_class_name = class_name.underscore.pluralize
22
- system("rake db:create_migration NAME=change_#{pluralized_class_name}")
22
+ system("rake db:create_migration NAME=change_column_to_#{pluralized_class_name}")
23
23
  end
24
24
 
25
25
  def remove_column(class_name: "user")
26
26
  pluralized_class_name = class_name.underscore.pluralize
27
- system("rake db:create_migration NAME=remove_#{pluralized_class_name}")
27
+ system("rake db:create_migration NAME=remove_column_to_#{pluralized_class_name}")
28
28
  end
29
29
 
30
30
  def drop_table(class_name: "user")
31
31
  pluralized_class_name = class_name.underscore.pluralize
32
- system("rake db:create_migration NAME=drop_#{pluralized_class_name}")
32
+ system("rake db:create_migration NAME=drop_table_to_#{pluralized_class_name}")
33
33
  end
34
34
  end
35
35
  end
@@ -1,5 +1,5 @@
1
1
  module Souls
2
- module Generate
2
+ module Api::Generate
3
3
  class << self
4
4
  ## Generate Type
5
5
  def create_type_head(class_name: "souls")
@@ -0,0 +1,11 @@
1
+ require_relative "./update/mutation"
2
+ require_relative "./update/resolver"
3
+ require_relative "./update/type"
4
+ require_relative "./update/rspec_factory"
5
+ require_relative "./update/rspec_mutation"
6
+ require_relative "./update/rspec_resolver"
7
+
8
+ module Souls
9
+ module Api::Update
10
+ end
11
+ end
@@ -0,0 +1,79 @@
1
+ module Souls
2
+ module Api
3
+ module Update
4
+ class << self
5
+ def create_mutation(class_name: "user")
6
+ singularized_class_name = class_name.singularize.underscore
7
+ new_cols = Souls.get_last_migration_type(class_name: singularized_class_name, action: "add")
8
+ dir_name = "./app/graphql/mutations/base/#{singularized_class_name}"
9
+ new_file_path = "tmp/create_mutation.rb"
10
+ file_path = "#{dir_name}/create_#{singularized_class_name}.rb"
11
+ argument = false
12
+ File.open(file_path) do |f|
13
+ File.open(new_file_path, "w") do |new_line|
14
+ f.each_line do |line|
15
+ new_line.write(line)
16
+ next unless line.include?("argument") && !argument
17
+
18
+ new_cols.each do |col|
19
+ type = col[:array] ? "[#{col[:type].camelize}]" : col[:type].camelize
20
+ args = check_mutation_argument(class_name: class_name)
21
+ unless args.include?(col[:column_name])
22
+ new_line.write(" argument :#{col[:column_name]}, #{type}, required: false\n")
23
+ end
24
+ end
25
+ argument = true
26
+ end
27
+ end
28
+ end
29
+ FileUtils.rm(file_path)
30
+ FileUtils.mv(new_file_path, file_path)
31
+ puts(Paint % ["Updated file! : %{white_text}", :green, { white_text: [file_path.to_s, :white] }])
32
+ end
33
+
34
+ def update_update_mutation(class_name: "user")
35
+ singularized_class_name = class_name.singularize.underscore
36
+ new_cols = Souls.get_last_migration_type(class_name: singularized_class_name, action: "add")
37
+ dir_name = "./app/graphql/mutations/base/#{singularized_class_name}"
38
+ new_file_path = "tmp/update_mutation.rb"
39
+ file_path = "#{dir_name}/update_#{singularized_class_name}.rb"
40
+ argument = false
41
+ File.open(file_path) do |f|
42
+ File.open(new_file_path, "w") do |new_line|
43
+ f.each_line do |line|
44
+ new_line.write(line)
45
+ next unless line.include?("argument") && !argument
46
+
47
+ new_cols.each do |col|
48
+ type = Souls::Api::Generate.type_check(col[:type])
49
+ type = "[#{type}]" if col[:array]
50
+ args = check_mutation_argument(class_name: class_name, action: "update")
51
+ unless args.include?(col[:column_name])
52
+ new_line.write(" argument :#{col[:column_name]}, #{type}, required: false\n")
53
+ end
54
+ end
55
+ argument = true
56
+ end
57
+ end
58
+ end
59
+ FileUtils.rm(file_path)
60
+ FileUtils.mv(new_file_path, file_path)
61
+ puts(Paint % ["Updated file! : %{white_text}", :green, { white_text: [file_path.to_s, :white] }])
62
+ end
63
+
64
+ def check_mutation_argument(class_name: "user", action: "create")
65
+ singularized_class_name = class_name.singularize.underscore
66
+ dir_name = "./app/graphql/mutations/base/#{singularized_class_name}"
67
+ file_path = "#{dir_name}/#{action}_#{singularized_class_name}.rb"
68
+ args = []
69
+ File.open(file_path) do |f|
70
+ f.each_line do |line|
71
+ args << line.split(",")[0].gsub("argument :", "").strip.underscore if line.include?("argument")
72
+ end
73
+ end
74
+ args
75
+ end
76
+ end
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,72 @@
1
+ module Souls
2
+ module Api
3
+ module Update
4
+ class << self
5
+ def resolver(class_name: "user")
6
+ singularized_class_name = class_name.singularize.underscore
7
+ new_cols = Souls.get_last_migration_type(class_name: singularized_class_name, action: "add")
8
+ dir_name = "./app/graphql/resolvers"
9
+ new_file_path = "tmp/update_resolver.rb"
10
+ file_path = "#{dir_name}/#{singularized_class_name}_search.rb"
11
+ args = check_resolver_argument(class_name: class_name)
12
+ scope_args = check_resolver_argument(class_name: class_name, action: "scope")
13
+ argument = false
14
+ scope = false
15
+ File.open(file_path) do |f|
16
+ File.open(new_file_path, "w") do |new_line|
17
+ f.each_line do |line|
18
+ new_line.write(line)
19
+ if line.include?("argument") && !argument
20
+ new_cols.each do |col|
21
+ type = Souls::Api::Generate.type_check(col[:type])
22
+ type = "[#{type}]" if col[:array]
23
+ add_line = " argument :#{col[:column_name]}, #{type}, required: false\n"
24
+ new_line.write(add_line) unless args.include?(col[:column_name])
25
+ end
26
+ argument = true
27
+ elsif line.include?("scope = ::") && !scope
28
+ new_cols.each do |col|
29
+ type = Souls::Api::Generate.type_check(col[:type])
30
+ type = "[#{type}]" if col[:array]
31
+
32
+ if type.include?("[")
33
+ add_line = " scope = scope.where('#{col[:column_name]} @> ARRAY[?]::#{col[:type]}[]', value[:#{col[:column_name]}]) if value[:#{col[:column_name]}]\n"
34
+ else
35
+ add_line = " scope = scope.where(#{col[:column_name]}: value[:#{col[:column_name]}]) if value[:#{col[:column_name]}]\n"
36
+ end
37
+ new_line.write(add_line) unless scope_args.include?(col[:column_name])
38
+ end
39
+ scope = true
40
+ end
41
+ end
42
+ end
43
+ end
44
+ FileUtils.rm(file_path)
45
+ FileUtils.mv(new_file_path, file_path)
46
+ puts(Paint % ["Updated file! : %{white_text}", :green, { white_text: [file_path.to_s, :white] }])
47
+ end
48
+
49
+ def check_resolver_argument(class_name: "user", action: "argument")
50
+ singularized_class_name = class_name.singularize.underscore
51
+ dir_name = "./app/graphql/resolvers"
52
+ file_path = "#{dir_name}/#{singularized_class_name}_search.rb"
53
+ args = []
54
+ File.open(file_path) do |f|
55
+ f.each_line do |line|
56
+ if action == "scope" && line.include?("scope = scope.where")
57
+ args << if line.include?("is_deleted")
58
+ "is_deleted"
59
+ else
60
+ line.to_s.match(/if value\[:(.+)\]/)[1].underscore
61
+ end
62
+ elsif action == "argument" && line.include?("argument")
63
+ args << line.split(",")[0].gsub("argument :", "").strip.underscore
64
+ end
65
+ end
66
+ end
67
+ args
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,50 @@
1
+ module Souls
2
+ module Api
3
+ module Update
4
+ class << self
5
+ def rspec_factory(class_name: "user")
6
+ singularized_class_name = class_name.singularize.underscore
7
+ pluralized_class_name = class_name.pluralize.underscore
8
+ new_cols = Souls.get_last_migration_type(class_name: singularized_class_name, action: "add")
9
+ dir_name = "./spec/factories"
10
+ new_file_path = "tmp/create_factory.rb"
11
+ file_path = "#{dir_name}/#{pluralized_class_name}.rb"
12
+ argument = false
13
+ File.open(file_path) do |f|
14
+ File.open(new_file_path, "w") do |new_line|
15
+ f.each_line do |line|
16
+ new_line.write(line)
17
+ next unless line.include?("{") && !argument
18
+
19
+ new_cols.each do |col|
20
+ type = Souls::Api::Generate.get_test_type(col[:type])
21
+ type = "[#{type}]" if col[:array]
22
+ args = check_factory_argument(class_name: class_name)
23
+
24
+ new_line.write(" #{col[:column_name]} { #{type} }\n") unless args.include?(col[:column_name])
25
+ end
26
+ argument = true
27
+ end
28
+ end
29
+ end
30
+ FileUtils.rm(file_path)
31
+ FileUtils.mv(new_file_path, file_path)
32
+ puts(Paint % ["Updated file! : %{white_text}", :green, { white_text: [file_path.to_s, :white] }])
33
+ end
34
+
35
+ def check_factory_argument(class_name: "user")
36
+ pluralized_class_name = class_name.pluralize.underscore
37
+ dir_name = "./spec/factories"
38
+ file_path = "#{dir_name}/#{pluralized_class_name}.rb"
39
+ args = []
40
+ File.open(file_path) do |f|
41
+ f.each_line do |line|
42
+ args << line.split("{")[0].strip.underscore if line.include?("{")
43
+ end
44
+ end
45
+ args
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,97 @@
1
+ module Souls
2
+ module Api
3
+ module Update
4
+ class << self
5
+ def rspec_mutation(class_name: "user")
6
+ singularized_class_name = class_name.singularize.underscore
7
+ new_cols = Souls.get_last_migration_type(class_name: singularized_class_name, action: "add")
8
+ dir_name = "./spec/mutations/base"
9
+ new_file_path = "tmp/rspec_mutation.rb"
10
+ file_path = "#{dir_name}/#{singularized_class_name}_spec.rb"
11
+ argument = false
12
+ node_res = false
13
+ test_res = false
14
+ File.open(file_path) do |f|
15
+ File.open(new_file_path, "w") do |new_line|
16
+ f.each_line do |line|
17
+ new_line.write(line)
18
+ node_res = true if line.include?("node {")
19
+ test_res = true if line.include?("include(")
20
+ node_res = false if node_res && line.include?("}")
21
+ test_res = false if test_res && line.strip == ")"
22
+
23
+ if line.include?('#{') && !argument
24
+ new_cols.each do |col|
25
+ type = Souls::Api::Generate.type_check(col[:type])
26
+ if type == "String" && !col[:array]
27
+ type_line = " #{col[:column_name].singularize.camelize(:lower)}: \"\#{#{class_name.singularize}[:#{col[:column_name].singularize.underscore}]}\"\n"
28
+ else
29
+ type_line = " #{col[:column_name].singularize.camelize(:lower)}: \#{#{class_name.singularize}[:#{col[:column_name].singularize.underscore}]}\n"
30
+ end
31
+ args = check_rspec_mutation_argument(class_name: class_name)
32
+ new_line.write(type_line) unless args.include?(col[:column_name].singularize.underscore)
33
+ end
34
+ argument = true
35
+ elsif node_res && !line.include?("{")
36
+ node_args = check_rspec_mutation_argument(class_name: class_name, action: "node_args")
37
+ new_cols.each do |col|
38
+ new_line.write(" #{col[:column_name]}\n") unless node_args.include?(col[:column_name])
39
+ end
40
+ node_res = false
41
+ elsif test_res && line.include?("=> be_")
42
+ test_args = check_rspec_mutation_argument(class_name: class_name, action: "test_args")
43
+ new_cols.each do |col|
44
+ type = Souls::Api::Generate.type_check(col[:type])
45
+ text =
46
+ case type
47
+ when "String"
48
+ col[:array] ? "be_all(String)" : "be_a(String)"
49
+ when "Integer", "Float"
50
+ col[:array] ? "be_all(Integer)" : "be_a(Integer)"
51
+ when "Boolean"
52
+ col[:array] ? "be_all([true, false])" : "be_in([true, false])"
53
+ else
54
+ col[:array] ? "be_all(String)" : "be_a(String)"
55
+ end
56
+ unless test_args.include?(col[:column_name])
57
+ new_line.write(" \"#{col[:column_name]}\" => #{text},\n")
58
+ end
59
+ end
60
+ test_res = false
61
+ end
62
+ end
63
+ end
64
+ end
65
+ FileUtils.rm(file_path)
66
+ FileUtils.mv(new_file_path, file_path)
67
+ puts(Paint % ["Updated file! : %{white_text}", :green, { white_text: [file_path.to_s, :white] }])
68
+ end
69
+
70
+ def check_rspec_mutation_argument(class_name: "user", action: "argument")
71
+ singularized_class_name = class_name.singularize.underscore
72
+ dir_name = "./spec/mutations/base"
73
+ file_path = "#{dir_name}/#{singularized_class_name}_spec.rb"
74
+ node_res = false
75
+ test_res = false
76
+ args = []
77
+ File.open(file_path) do |f|
78
+ f.each_line do |line|
79
+ node_res = true if line.include?("node {")
80
+ test_res = true if line.include?("include(")
81
+ node_res = false if node_res && line.include?("}")
82
+ test_res = false if test_res && line.strip == ")"
83
+ if action == "node_args"
84
+ args << line.strip.underscore if node_res && !line.include?("{")
85
+ elsif action == "test_args"
86
+ args << line.split("\"")[1].underscore if test_res && line.include?("=> be_")
87
+ elsif line.include?('#{')
88
+ args << line.split(":")[0].strip.underscore
89
+ end
90
+ end
91
+ end
92
+ args
93
+ end
94
+ end
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,85 @@
1
+ module Souls
2
+ module Api
3
+ module Update
4
+ class << self
5
+ def rspec_resolver(class_name: "user")
6
+ singularized_class_name = class_name.singularize.underscore
7
+ new_cols = Souls.get_last_migration_type(class_name: singularized_class_name, action: "add")
8
+ dir_name = "./spec/resolvers"
9
+ new_file_path = "tmp/rspec_resolver.rb"
10
+ file_path = "#{dir_name}/#{singularized_class_name}_search_spec.rb"
11
+ node_res = false
12
+ test_res = false
13
+ File.open(file_path) do |f|
14
+ File.open(new_file_path, "w") do |new_line|
15
+ f.each_line do |line|
16
+ new_line.write(line)
17
+ node_res = true if line.include?("node {")
18
+ test_res = true if line.include?("include(")
19
+ node_res = false if node_res && line.include?("}")
20
+ test_res = false if test_res && line.strip == ")"
21
+
22
+ if node_res && !line.include?("{")
23
+ node_args = check_rspec_resolver_argument(class_name: class_name, action: "node_args")
24
+ new_cols.each do |col|
25
+ new_line.write(" #{col[:column_name].camelize}\n") unless node_args.include?(col[:column_name])
26
+ end
27
+ node_res = false
28
+ elsif test_res && line.include?("=> be_")
29
+ test_args = check_rspec_resolver_argument(class_name: class_name, action: "test_args")
30
+ new_cols.each do |col|
31
+ type = Souls::Api::Generate.type_check(col[:type])
32
+ p type
33
+ text =
34
+ case type
35
+ when "String"
36
+ col[:array] ? "be_all(String)" : "be_a(String)"
37
+ when "Integer", "Float"
38
+ col[:array] ? "be_all(Integer)" : "be_a(Integer)"
39
+ when "Boolean"
40
+ col[:array] ? "be_all([true, false])" : "be_in([true, false])"
41
+ else
42
+ col[:array] ? "be_all(String)" : "be_a(String)"
43
+ end
44
+ unless test_args.include?(col[:column_name])
45
+ new_line.write(" \"#{col[:column_name]}\" => #{text},\n")
46
+ end
47
+ end
48
+ test_res = false
49
+ end
50
+ end
51
+ end
52
+ end
53
+ FileUtils.rm(file_path)
54
+ FileUtils.mv(new_file_path, file_path)
55
+ puts(Paint % ["Updated file! : %{white_text}", :green, { white_text: [file_path.to_s, :white] }])
56
+ end
57
+
58
+ def check_rspec_resolver_argument(class_name: "user", action: "node_args")
59
+ singularized_class_name = class_name.singularize.underscore
60
+ dir_name = "./spec/resolvers"
61
+ file_path = "#{dir_name}/#{singularized_class_name}_search_spec.rb"
62
+ node_res = false
63
+ test_res = false
64
+ args = []
65
+ File.open(file_path) do |f|
66
+ f.each_line do |line|
67
+ node_res = true if line.include?("node {")
68
+ test_res = true if line.include?("include(")
69
+ node_res = false if node_res && line.include?("}")
70
+ test_res = false if test_res && line.strip == ")"
71
+ if action == "node_args"
72
+ args << line.strip.underscore if node_res && !line.include?("{")
73
+ elsif action == "test_args"
74
+ args << line.split("\"")[1].underscore if test_res && line.include?("=> be_")
75
+ elsif line.include?('#{')
76
+ args << line.split(":")[0].strip.underscore
77
+ end
78
+ end
79
+ end
80
+ args
81
+ end
82
+ end
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,50 @@
1
+ module Souls
2
+ module Api
3
+ module Update
4
+ class << self
5
+ def type(class_name: "user")
6
+ singularized_class_name = class_name.singularize.underscore
7
+ new_cols = Souls.get_last_migration_type(class_name: singularized_class_name, action: "add")
8
+ dir_name = "./app/graphql/types"
9
+ new_file_path = "tmp/create_type.rb"
10
+ file_path = "#{dir_name}/#{singularized_class_name}_type.rb"
11
+ argument = false
12
+ File.open(file_path) do |f|
13
+ File.open(new_file_path, "w") do |new_line|
14
+ f.each_line do |line|
15
+ new_line.write(line)
16
+ next unless line.include?("field") && !argument
17
+
18
+ new_cols.each do |col|
19
+ type = Souls::Api::Generate.type_check(col[:type])
20
+ type = "[#{type}]" if col[:array]
21
+ args = check_type_argument(class_name: class_name)
22
+ unless args.include?(col[:column_name])
23
+ new_line.write(" field :#{col[:column_name]}, #{type}, null: true\n")
24
+ end
25
+ end
26
+ argument = true
27
+ end
28
+ end
29
+ end
30
+ FileUtils.rm(file_path)
31
+ FileUtils.mv(new_file_path, file_path)
32
+ puts(Paint % ["Updated file! : %{white_text}", :green, { white_text: [file_path.to_s, :white] }])
33
+ end
34
+
35
+ def check_type_argument(class_name: "user")
36
+ singularized_class_name = class_name.singularize.underscore
37
+ dir_name = "./app/graphql/types"
38
+ file_path = "#{dir_name}/#{singularized_class_name}_type.rb"
39
+ args = []
40
+ File.open(file_path) do |f|
41
+ f.each_line do |line|
42
+ args << line.split(",")[0].gsub("field :", "").strip if line.include?(" field :")
43
+ end
44
+ end
45
+ args
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
data/lib/souls/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  module Souls
2
- VERSION = "0.29.5".freeze
2
+ VERSION = "0.29.9".freeze
3
3
  public_constant :VERSION
4
4
  end
@@ -1 +1 @@
1
- 0.8.5
1
+ 0.8.9
@@ -1 +1 @@
1
- 0.8.5
1
+ 0.8.9
metadata CHANGED
@@ -1,16 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: souls
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.29.5
4
+ version: 0.29.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - POPPIN-FUMI
8
8
  - KishiTheMechanic
9
9
  - James Neve
10
- autorequire:
10
+ autorequire:
11
11
  bindir: exe
12
12
  cert_chain: []
13
- date: 2021-08-16 00:00:00.000000000 Z
13
+ date: 2021-08-17 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport
@@ -120,6 +120,13 @@ files:
120
120
  - lib/souls/api/generate/rspec_query.rb
121
121
  - lib/souls/api/generate/rspec_resolver.rb
122
122
  - lib/souls/api/generate/type.rb
123
+ - lib/souls/api/update.rb
124
+ - lib/souls/api/update/mutation.rb
125
+ - lib/souls/api/update/resolver.rb
126
+ - lib/souls/api/update/rspec_factory.rb
127
+ - lib/souls/api/update/rspec_mutation.rb
128
+ - lib/souls/api/update/rspec_resolver.rb
129
+ - lib/souls/api/update/type.rb
123
130
  - lib/souls/docker.rb
124
131
  - lib/souls/docker/docker.rb
125
132
  - lib/souls/gcloud.rb
@@ -145,7 +152,7 @@ metadata:
145
152
  homepage_uri: https://souls.elsoul.nl
146
153
  source_code_uri: https://github.com/elsoul/souls
147
154
  changelog_uri: https://github.com/elsoul/souls
148
- post_install_message:
155
+ post_install_message:
149
156
  rdoc_options: []
150
157
  require_paths:
151
158
  - lib
@@ -161,7 +168,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
161
168
  version: '0'
162
169
  requirements: []
163
170
  rubygems_version: 3.2.22
164
- signing_key:
171
+ signing_key:
165
172
  specification_version: 4
166
173
  summary: SOULs is a Serverless Application Framework with Ruby GraphQL. SOULs has
167
174
  3 strains, API, Worker, and Frontend. It can be used in combination according to