souls 0.29.4 → 0.29.8
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/exe/souls +7 -0
- data/lib/souls.rb +92 -7
- data/lib/souls/api.rb +1 -0
- data/lib/souls/api/generate/application.rb +4 -3
- data/lib/souls/api/generate/migration.rb +31 -4
- data/lib/souls/api/generate/type.rb +1 -1
- data/lib/souls/api/update.rb +10 -0
- data/lib/souls/api/update/mutation.rb +79 -0
- data/lib/souls/api/update/resolver.rb +72 -0
- data/lib/souls/api/update/rspec_factory.rb +50 -0
- data/lib/souls/api/update/rspec_mutation.rb +97 -0
- data/lib/souls/api/update/type.rb +50 -0
- data/lib/souls/version.rb +1 -1
- data/lib/souls/versions/.souls_api_version +1 -1
- data/lib/souls/versions/.souls_worker_version +1 -1
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 850fd970ee0932d65bed38e8bc32570a029ad30f6a936d7cb38e0515659164e2
|
4
|
+
data.tar.gz: 79c5e659716710e31c369050de2dff5c8c8b36e9ff52f8a54cdbd43dfda4a5b9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 454d9847007e1390fb7fd0ee3a544a37c2a022e0fefa48b912efde577e2c8f897a03d0e3f5f57399fcefadaa320578090e7a6a0f23ee267caf4a2aaf2847d307
|
7
|
+
data.tar.gz: a6576810a7fb39d97fbc310039a643fd2dbc65124279965de480863f38163b0fa18bd7d1eb16713f04065834507984178bf5b6f3762de228158acf8ca99a30f1
|
data/exe/souls
CHANGED
@@ -20,6 +20,12 @@ 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)
|
23
29
|
else
|
24
30
|
puts(Paint["Comannd doesn't exist.Check you command again!...", :red])
|
25
31
|
end
|
@@ -160,5 +166,6 @@ begin
|
|
160
166
|
puts(Paint["Welcome to SOULs!", :green])
|
161
167
|
end
|
162
168
|
rescue StandardError => e
|
169
|
+
puts(e.backtrace)
|
163
170
|
puts(Paint[e, :red])
|
164
171
|
end
|
data/lib/souls.rb
CHANGED
@@ -332,15 +332,100 @@ module Souls
|
|
332
332
|
}
|
333
333
|
end
|
334
334
|
|
335
|
-
def
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
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
|
-
|
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
|
-
|
427
|
+
end
|
428
|
+
response
|
344
429
|
end
|
345
430
|
|
346
431
|
def configure
|
data/lib/souls/api.rb
CHANGED
@@ -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
|
|
@@ -1,9 +1,36 @@
|
|
1
1
|
module Souls
|
2
2
|
module Api
|
3
|
-
module
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
module Generate
|
4
|
+
class << self
|
5
|
+
def create_migration(class_name: "user")
|
6
|
+
pluralized_class_name = class_name.underscore.pluralize
|
7
|
+
system("rake db:create_migration NAME=create_#{pluralized_class_name}")
|
8
|
+
end
|
9
|
+
|
10
|
+
def add_column(class_name: "user")
|
11
|
+
pluralized_class_name = class_name.underscore.pluralize
|
12
|
+
system("rake db:create_migration NAME=add_column_to_#{pluralized_class_name}")
|
13
|
+
end
|
14
|
+
|
15
|
+
def rename_column(class_name: "user")
|
16
|
+
pluralized_class_name = class_name.underscore.pluralize
|
17
|
+
system("rake db:create_migration NAME=rename_column_to_#{pluralized_class_name}")
|
18
|
+
end
|
19
|
+
|
20
|
+
def change_column(class_name: "user")
|
21
|
+
pluralized_class_name = class_name.underscore.pluralize
|
22
|
+
system("rake db:create_migration NAME=change_column_to_#{pluralized_class_name}")
|
23
|
+
end
|
24
|
+
|
25
|
+
def remove_column(class_name: "user")
|
26
|
+
pluralized_class_name = class_name.underscore.pluralize
|
27
|
+
system("rake db:create_migration NAME=remove_column_to_#{pluralized_class_name}")
|
28
|
+
end
|
29
|
+
|
30
|
+
def drop_table(class_name: "user")
|
31
|
+
pluralized_class_name = class_name.underscore.pluralize
|
32
|
+
system("rake db:create_migration NAME=drop_table_to_#{pluralized_class_name}")
|
33
|
+
end
|
7
34
|
end
|
8
35
|
end
|
9
36
|
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 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]
|
61
|
+
end
|
62
|
+
elsif action == "argument" && line.include?("argument")
|
63
|
+
args << line.split(",")[0].gsub("argument :", "").strip
|
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 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] 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,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 +1 @@
|
|
1
|
-
0.8.
|
1
|
+
0.8.8
|
@@ -1 +1 @@
|
|
1
|
-
0.8.
|
1
|
+
0.8.8
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: souls
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.29.
|
4
|
+
version: 0.29.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- POPPIN-FUMI
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: exe
|
12
12
|
cert_chain: []
|
13
|
-
date: 2021-08-
|
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,12 @@ 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/type.rb
|
123
129
|
- lib/souls/docker.rb
|
124
130
|
- lib/souls/docker/docker.rb
|
125
131
|
- lib/souls/gcloud.rb
|