souls 0.51.0 → 0.52.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.
- checksums.yaml +4 -4
- data/README.md +5 -1
- data/exe/souls +3 -200
- data/lib/souls/api/generate/application.rb +97 -94
- data/lib/souls/api/generate/connection.rb +5 -4
- data/lib/souls/api/generate/edge.rb +5 -4
- data/lib/souls/api/generate/index.rb +0 -1
- data/lib/souls/api/generate/manager.rb +9 -7
- data/lib/souls/api/generate/model.rb +16 -18
- data/lib/souls/api/generate/mutation.rb +217 -218
- data/lib/souls/api/generate/policy.rb +5 -5
- data/lib/souls/api/generate/query.rb +51 -51
- data/lib/souls/api/generate/resolver.rb +115 -115
- data/lib/souls/api/generate/rspec_factory.rb +53 -53
- data/lib/souls/api/generate/rspec_model.rb +5 -5
- data/lib/souls/api/generate/rspec_mutation.rb +178 -178
- data/lib/souls/api/generate/rspec_policy.rb +5 -5
- data/lib/souls/api/generate/rspec_query.rb +111 -111
- data/lib/souls/api/generate/rspec_resolver.rb +163 -163
- data/lib/souls/api/generate/type.rb +66 -66
- data/lib/souls/api/index.rb +7 -4
- data/lib/souls/api/update/index.rb +15 -0
- data/lib/souls/api/update/mutation.rb +68 -64
- data/lib/souls/api/update/resolver.rb +59 -60
- data/lib/souls/api/update/rspec_factory.rb +40 -39
- data/lib/souls/api/update/rspec_mutation.rb +84 -83
- data/lib/souls/api/update/rspec_resolver.rb +70 -69
- data/lib/souls/api/update/type.rb +39 -38
- data/lib/souls/cli/console/index.rb +13 -1
- data/lib/souls/cli/create/index.rb +98 -94
- data/lib/souls/cli/db/index.rb +122 -1
- data/lib/souls/cli/docker/index.rb +30 -38
- data/lib/souls/cli/gcloud/compute/index.rb +100 -98
- data/lib/souls/cli/gcloud/iam/index.rb +84 -69
- data/lib/souls/cli/gcloud/index.rb +36 -35
- data/lib/souls/cli/gcloud/pubsub/subscriptions.rb +40 -27
- data/lib/souls/cli/gcloud/pubsub/topics.rb +16 -10
- data/lib/souls/cli/gcloud/run/index.rb +23 -17
- data/lib/souls/cli/gcloud/sql/index.rb +66 -47
- data/lib/souls/cli/index.rb +3 -20
- data/lib/souls/cli/init/index.rb +140 -140
- data/lib/souls/cli/release/release.rb +106 -105
- data/lib/souls/cli/server/index.rb +12 -1
- data/lib/souls/cli/sync/conf.rb +39 -38
- data/lib/souls/cli/sync/model.rb +19 -20
- data/lib/souls/cli/sync/pubsub.rb +69 -70
- data/lib/souls/cli/upgrade/gemfile.rb +108 -0
- data/lib/souls/cli/upgrade/index.rb +1 -1
- data/lib/souls/cli.rb +57 -0
- data/lib/souls/index.rb +1 -5
- 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
- data/lib/souls/worker/generate/index.rb +1 -1
- data/lib/souls/worker/generate/job.rb +45 -0
- data/lib/souls/worker/generate/mailer.rb +38 -43
- data/lib/souls/worker/index.rb +3 -1
- data/lib/souls.rb +2 -0
- metadata +19 -5
- data/lib/souls/api/generate/migration.rb +0 -51
- data/lib/souls/cli/upgrade/gem_update.rb +0 -107
- data/lib/souls/worker/generate/mutation.rb +0 -44
@@ -1,32 +1,48 @@
|
|
1
1
|
module Souls
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
2
|
+
class Generate < Thor
|
3
|
+
desc "rspec_query [CLASS_NAME]", "Generate Rspec Query Test from schema.rb"
|
4
|
+
def rspec_query(class_name)
|
5
|
+
singularized_class_name = class_name.singularize
|
6
|
+
file_path = "./spec/queries/#{singularized_class_name}_spec.rb"
|
7
|
+
return "RspecQuery already exist! #{file_path}" if File.exist?(file_path)
|
8
|
+
|
9
|
+
rspec_query_head(class_name: singularized_class_name)
|
10
|
+
rspec_query_after_head(class_name: singularized_class_name)
|
11
|
+
rspec_query_params(class_name: singularized_class_name)
|
12
|
+
rspec_query_end(class_name: singularized_class_name)
|
13
|
+
puts(Paint % ["Created file! : %{white_text}", :green, { white_text: [file_path.to_s, :white] }])
|
14
|
+
file_path
|
15
|
+
rescue Thor::Error => e
|
16
|
+
raise(Thor::Error, e)
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def rspec_query_head(class_name: "user")
|
22
|
+
file_dir = "./spec/queries/"
|
23
|
+
FileUtils.mkdir_p(file_dir) unless Dir.exist?(file_dir)
|
24
|
+
file_path = "./spec/queries/#{class_name.singularize}_spec.rb"
|
25
|
+
File.open(file_path, "w") do |f|
|
26
|
+
f.write(<<~TEXT)
|
27
|
+
RSpec.describe \"#{class_name.camelize} Query テスト\" do
|
28
|
+
describe "#{class_name.camelize} データを取得する" do
|
29
|
+
TEXT
|
15
30
|
end
|
31
|
+
end
|
16
32
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
33
|
+
def rspec_query_after_head(class_name: "user")
|
34
|
+
file_path = "./spec/queries/#{class_name.singularize}_spec.rb"
|
35
|
+
path = "./db/schema.rb"
|
36
|
+
@on = false
|
37
|
+
@user_exist = false
|
38
|
+
@relation_params = []
|
39
|
+
File.open(file_path, "a") do |new_line|
|
40
|
+
File.open(path, "r") do |f|
|
41
|
+
f.each_line.with_index do |line, _i|
|
42
|
+
if @on
|
43
|
+
if line.include?("t.index") || line.strip == "end"
|
44
|
+
if @relation_params.empty?
|
45
|
+
new_line.write(<<-TEXT)
|
30
46
|
let!(:#{class_name}) { FactoryBot.create(:#{class_name}) }
|
31
47
|
|
32
48
|
let(:query) do
|
@@ -34,9 +50,9 @@ module Souls
|
|
34
50
|
%(query {
|
35
51
|
#{class_name.singularize.camelize(:lower)}(id: \\"\#{data_id}\\") {
|
36
52
|
id
|
37
|
-
|
38
|
-
|
39
|
-
|
53
|
+
TEXT
|
54
|
+
else
|
55
|
+
new_line.write(<<-TEXT)
|
40
56
|
let(:#{class_name}) { FactoryBot.create(:#{class_name}, #{@relation_params.join(', ')}) }
|
41
57
|
|
42
58
|
let(:query) do
|
@@ -44,34 +60,34 @@ module Souls
|
|
44
60
|
%(query {
|
45
61
|
#{class_name.singularize.camelize(:lower)}(id: \\"\#{data_id}\\") {
|
46
62
|
id
|
47
|
-
|
48
|
-
end
|
49
|
-
break
|
50
|
-
end
|
51
|
-
_, name = line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
|
52
|
-
case name
|
53
|
-
when /$*_id\z/
|
54
|
-
relation_col = name.gsub("_id", "")
|
55
|
-
@relation_params << "#{name}: #{relation_col}.id"
|
56
|
-
new_line.write(" let(:#{relation_col}) { FactoryBot.create(:#{relation_col}) }\n")
|
63
|
+
TEXT
|
57
64
|
end
|
65
|
+
break
|
66
|
+
end
|
67
|
+
_, name = line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
|
68
|
+
case name
|
69
|
+
when /$*_id\z/
|
70
|
+
relation_col = name.gsub("_id", "")
|
71
|
+
@relation_params << "#{name}: #{relation_col}.id"
|
72
|
+
new_line.write(" let(:#{relation_col}) { FactoryBot.create(:#{relation_col}) }\n")
|
58
73
|
end
|
59
|
-
@on = true if Souls.table_check(line: line, class_name: class_name)
|
60
74
|
end
|
75
|
+
@on = true if Souls.table_check(line: line, class_name: class_name)
|
61
76
|
end
|
62
77
|
end
|
63
78
|
end
|
79
|
+
end
|
64
80
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
81
|
+
def rspec_query_params(class_name: "user")
|
82
|
+
file_path = "./spec/queries/#{class_name.singularize}_spec.rb"
|
83
|
+
path = "./db/schema.rb"
|
84
|
+
@on = false
|
85
|
+
File.open(file_path, "a") do |new_line|
|
86
|
+
File.open(path, "r") do |f|
|
87
|
+
f.each_line.with_index do |line, _i|
|
88
|
+
if @on
|
89
|
+
if line.include?("t.index") || line.strip == "end"
|
90
|
+
new_line.write(<<-TEXT)
|
75
91
|
}
|
76
92
|
}
|
77
93
|
)
|
@@ -90,82 +106,66 @@ module Souls
|
|
90
106
|
end
|
91
107
|
expect(a1).to include(
|
92
108
|
"id" => be_a(String),
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
end
|
109
|
+
TEXT
|
110
|
+
break
|
111
|
+
end
|
112
|
+
_, name = line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
|
113
|
+
case name
|
114
|
+
when "user_id", "created_at", "updated_at", /$*_id\z/
|
115
|
+
next
|
116
|
+
else
|
117
|
+
new_line.write(" #{name.camelize(:lower)}\n")
|
103
118
|
end
|
104
|
-
@on = true if Souls.table_check(line: line, class_name: class_name)
|
105
119
|
end
|
120
|
+
@on = true if Souls.table_check(line: line, class_name: class_name)
|
106
121
|
end
|
107
122
|
end
|
108
123
|
end
|
124
|
+
end
|
109
125
|
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
end
|
126
|
+
def rspec_query_end(class_name: "user")
|
127
|
+
file_path = "./spec/queries/#{class_name.singularize}_spec.rb"
|
128
|
+
path = "./db/schema.rb"
|
129
|
+
@on = false
|
130
|
+
File.open(file_path, "a") do |new_line|
|
131
|
+
File.open(path, "r") do |f|
|
132
|
+
f.each_line.with_index do |line, _i|
|
133
|
+
if @on
|
134
|
+
if line.include?("t.index") || line.strip == "end"
|
135
|
+
new_line.write(<<~TEXT)
|
136
|
+
)
|
122
137
|
end
|
123
138
|
end
|
124
|
-
TEXT
|
125
|
-
break
|
126
|
-
end
|
127
|
-
type, name = line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
|
128
|
-
field ||= Souls.type_check(type)
|
129
|
-
array_true = line.include?("array: true")
|
130
|
-
case name
|
131
|
-
when "user_id", "created_at", "updated_at", /$*_id\z/
|
132
|
-
next
|
133
|
-
else
|
134
|
-
case type
|
135
|
-
when "text", "date", "datetime"
|
136
|
-
if array_true
|
137
|
-
new_line.write(" \"#{name.camelize(:lower)}\" => be_all(String),\n")
|
138
|
-
else
|
139
|
-
new_line.write(" \"#{name.camelize(:lower)}\" => be_a(String),\n")
|
140
|
-
end
|
141
|
-
when "boolean"
|
142
|
-
new_line.write(" \"#{name.singularize.camelize(:lower)}\" => be_in([true, false]),\n")
|
143
|
-
when "string", "bigint", "integer", "float"
|
144
|
-
new_line.write(" \"#{name.singularize.camelize(:lower)}\" => be_a(#{field}),\n")
|
145
139
|
end
|
140
|
+
TEXT
|
141
|
+
break
|
142
|
+
end
|
143
|
+
type, name = line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
|
144
|
+
field ||= Souls.type_check(type)
|
145
|
+
array_true = line.include?("array: true")
|
146
|
+
case name
|
147
|
+
when "user_id", "created_at", "updated_at", /$*_id\z/
|
148
|
+
next
|
149
|
+
else
|
150
|
+
case type
|
151
|
+
when "text", "date", "datetime"
|
152
|
+
if array_true
|
153
|
+
new_line.write(" \"#{name.camelize(:lower)}\" => be_all(String),\n")
|
154
|
+
else
|
155
|
+
new_line.write(" \"#{name.camelize(:lower)}\" => be_a(String),\n")
|
156
|
+
end
|
157
|
+
when "boolean"
|
158
|
+
new_line.write(" \"#{name.singularize.camelize(:lower)}\" => be_in([true, false]),\n")
|
159
|
+
when "string", "bigint", "integer", "float"
|
160
|
+
new_line.write(" \"#{name.singularize.camelize(:lower)}\" => be_a(#{field}),\n")
|
146
161
|
end
|
147
162
|
end
|
148
|
-
@on = true if Souls.table_check(line: line, class_name: class_name)
|
149
163
|
end
|
164
|
+
@on = true if Souls.table_check(line: line, class_name: class_name)
|
150
165
|
end
|
151
166
|
end
|
152
|
-
file_path
|
153
|
-
end
|
154
|
-
|
155
|
-
def rspec_query(class_name: "user")
|
156
|
-
singularized_class_name = class_name.singularize
|
157
|
-
file_path = "./spec/queries/#{singularized_class_name}_spec.rb"
|
158
|
-
return "RspecQuery already exist! #{file_path}" if File.exist?(file_path)
|
159
|
-
|
160
|
-
rspec_query_head(class_name: singularized_class_name)
|
161
|
-
rspec_query_after_head(class_name: singularized_class_name)
|
162
|
-
rspec_query_params(class_name: singularized_class_name)
|
163
|
-
rspec_query_end(class_name: singularized_class_name)
|
164
|
-
puts(Paint % ["Created file! : %{white_text}", :green, { white_text: [file_path.to_s, :white] }])
|
165
|
-
file_path
|
166
|
-
rescue StandardError => e
|
167
|
-
raise(StandardError, e)
|
168
167
|
end
|
168
|
+
file_path
|
169
169
|
end
|
170
170
|
end
|
171
171
|
end
|
@@ -1,198 +1,198 @@
|
|
1
1
|
module Souls
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
2
|
+
class Generate < Thor
|
3
|
+
desc "rspec_resolver [CLASS_NAME]", "Generate Rspec Resolver Test from schema.rb"
|
4
|
+
def rspec_resolver(class_name)
|
5
|
+
singularized_class_name = class_name.singularize
|
6
|
+
file_path = "./spec/resolvers/#{singularized_class_name}_search_spec.rb"
|
7
|
+
return "Resolver already exist! #{file_path}" if File.exist?(file_path)
|
8
|
+
|
9
|
+
rspec_resolver_head(class_name: singularized_class_name)
|
10
|
+
rspec_resolver_after_head(class_name: singularized_class_name)
|
11
|
+
rspec_resolver_params(class_name: singularized_class_name)
|
12
|
+
rspec_resolver_end(class_name: singularized_class_name)
|
13
|
+
puts(Paint % ["Created file! : %{white_text}", :green, { white_text: [file_path.to_s, :white] }])
|
14
|
+
file_path
|
15
|
+
rescue Thor::Error => e
|
16
|
+
raise(Thor::Error, e)
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def rspec_resolver_head(class_name: "user")
|
22
|
+
file_dir = "./spec/resolvers/"
|
23
|
+
FileUtils.mkdir_p(file_dir) unless Dir.exist?(file_dir)
|
24
|
+
file_path = "./spec/resolvers/#{class_name.singularize}_search_spec.rb"
|
25
|
+
File.open(file_path, "w") do |f|
|
26
|
+
f.write(<<~TEXT)
|
27
|
+
RSpec.describe \"#{class_name.camelize}Search Resolver テスト\" do
|
28
|
+
describe "削除フラグ false の #{class_name.camelize} を返却する" do
|
29
|
+
TEXT
|
15
30
|
end
|
31
|
+
end
|
16
32
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
33
|
+
def rspec_resolver_after_head(class_name: "user")
|
34
|
+
file_path = "./spec/resolvers/#{class_name.singularize}_search_spec.rb"
|
35
|
+
path = "./db/schema.rb"
|
36
|
+
@on = false
|
37
|
+
@user_exist = false
|
38
|
+
@relation_params = []
|
39
|
+
File.open(file_path, "a") do |new_line|
|
40
|
+
File.open(path, "r") do |f|
|
41
|
+
f.each_line.with_index do |line, _i|
|
42
|
+
if @on
|
43
|
+
if line.include?("t.index") || line.strip == "end"
|
44
|
+
if @relation_params.empty?
|
45
|
+
new_line.write(<<-TEXT)
|
46
|
+
let!(:#{class_name}) { FactoryBot.create(:#{class_name}) }
|
31
47
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
48
|
+
let(:query) do
|
49
|
+
%(query {
|
50
|
+
#{class_name.singularize.camelize(:lower)}Search(filter: {
|
51
|
+
isDeleted: false
|
52
|
+
}) {
|
53
|
+
edges {
|
54
|
+
cursor
|
55
|
+
node {
|
56
|
+
id
|
57
|
+
TEXT
|
58
|
+
else
|
59
|
+
new_line.write(<<-TEXT)
|
60
|
+
let!(:#{class_name}) { FactoryBot.create(:#{class_name}, #{@relation_params.join(', ')}) }
|
45
61
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
end
|
57
|
-
break
|
58
|
-
end
|
59
|
-
_, name = line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
|
60
|
-
case name
|
61
|
-
when /$*_id\z/
|
62
|
-
relation_col = name.gsub("_id", "")
|
63
|
-
@relation_params << "#{name}: #{relation_col}.id"
|
64
|
-
new_line.write(" let(:#{relation_col}) { FactoryBot.create(:#{relation_col}) }\n")
|
62
|
+
let(:query) do
|
63
|
+
%(query {
|
64
|
+
#{class_name.singularize.camelize(:lower)}Search(filter: {
|
65
|
+
isDeleted: false
|
66
|
+
}) {
|
67
|
+
edges {
|
68
|
+
cursor
|
69
|
+
node {
|
70
|
+
id
|
71
|
+
TEXT
|
65
72
|
end
|
73
|
+
break
|
74
|
+
end
|
75
|
+
_, name = line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
|
76
|
+
case name
|
77
|
+
when /$*_id\z/
|
78
|
+
relation_col = name.gsub("_id", "")
|
79
|
+
@relation_params << "#{name}: #{relation_col}.id"
|
80
|
+
new_line.write(" let(:#{relation_col}) { FactoryBot.create(:#{relation_col}) }\n")
|
66
81
|
end
|
67
|
-
@on = true if Souls.table_check(line: line, class_name: class_name)
|
68
82
|
end
|
83
|
+
@on = true if Souls.table_check(line: line, class_name: class_name)
|
69
84
|
end
|
70
85
|
end
|
71
86
|
end
|
87
|
+
end
|
72
88
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
}
|
84
|
-
}
|
85
|
-
nodes {
|
86
|
-
id
|
87
|
-
}
|
88
|
-
pageInfo {
|
89
|
-
endCursor
|
90
|
-
hasNextPage
|
91
|
-
startCursor
|
92
|
-
hasPreviousPage
|
89
|
+
def rspec_resolver_params(class_name: "user")
|
90
|
+
file_path = "./spec/resolvers/#{class_name.singularize}_search_spec.rb"
|
91
|
+
path = "./db/schema.rb"
|
92
|
+
@on = false
|
93
|
+
File.open(file_path, "a") do |new_line|
|
94
|
+
File.open(path, "r") do |f|
|
95
|
+
f.each_line.with_index do |line, _i|
|
96
|
+
if @on
|
97
|
+
if line.include?("t.index") || line.strip == "end"
|
98
|
+
new_line.write(<<-TEXT)
|
93
99
|
}
|
94
100
|
}
|
101
|
+
nodes {
|
102
|
+
id
|
103
|
+
}
|
104
|
+
pageInfo {
|
105
|
+
endCursor
|
106
|
+
hasNextPage
|
107
|
+
startCursor
|
108
|
+
hasPreviousPage
|
109
|
+
}
|
95
110
|
}
|
96
|
-
|
97
|
-
|
111
|
+
}
|
112
|
+
)
|
113
|
+
end
|
98
114
|
|
99
|
-
|
100
|
-
|
101
|
-
|
115
|
+
subject(:result) do
|
116
|
+
SoulsApiSchema.execute(query).as_json
|
117
|
+
end
|
102
118
|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
end
|
119
|
+
it "return #{class_name.camelize} Data" do
|
120
|
+
begin
|
121
|
+
a1 = result.dig("data", "#{class_name.singularize.camelize(:lower)}Search", "edges")[0]["node"]
|
122
|
+
raise unless a1.present?
|
123
|
+
rescue
|
124
|
+
raise StandardError, result
|
125
|
+
end
|
126
|
+
expect(a1).to include(
|
127
|
+
"id" => be_a(String),
|
128
|
+
TEXT
|
129
|
+
break
|
130
|
+
end
|
131
|
+
_, name = line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
|
132
|
+
case name
|
133
|
+
when "user_id", "created_at", "updated_at", /$*_id\z/
|
134
|
+
next
|
135
|
+
else
|
136
|
+
new_line.write(" #{name.camelize(:lower)}\n")
|
122
137
|
end
|
123
|
-
@on = true if Souls.table_check(line: line, class_name: class_name)
|
124
138
|
end
|
139
|
+
@on = true if Souls.table_check(line: line, class_name: class_name)
|
125
140
|
end
|
126
141
|
end
|
127
142
|
end
|
143
|
+
end
|
128
144
|
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
end
|
145
|
+
def rspec_resolver_end(class_name: "user")
|
146
|
+
file_path = "./spec/resolvers/#{class_name.singularize}_search_spec.rb"
|
147
|
+
path = "./db/schema.rb"
|
148
|
+
@on = false
|
149
|
+
File.open(file_path, "a") do |new_line|
|
150
|
+
File.open(path, "r") do |f|
|
151
|
+
f.each_line.with_index do |line, _i|
|
152
|
+
if @on
|
153
|
+
if line.include?("t.index") || line.strip == "end"
|
154
|
+
new_line.write(<<~TEXT)
|
155
|
+
)
|
141
156
|
end
|
142
157
|
end
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
158
|
+
end
|
159
|
+
TEXT
|
160
|
+
break
|
161
|
+
end
|
162
|
+
type, name = line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
|
163
|
+
field ||= Souls.type_check(type)
|
164
|
+
array_true = line.include?("array: true")
|
165
|
+
case name
|
166
|
+
when "user_id", "created_at", "updated_at", /$*_id\z/
|
167
|
+
next
|
168
|
+
else
|
169
|
+
case type
|
170
|
+
when "text", "date", "datetime"
|
171
|
+
if array_true
|
172
|
+
new_line.write(" \"#{name.camelize(:lower)}\" => be_all(String),\n")
|
173
|
+
else
|
174
|
+
new_line.write(" \"#{name.camelize(:lower)}\" => be_a(String),\n")
|
175
|
+
end
|
176
|
+
when "boolean"
|
177
|
+
if array_true
|
178
|
+
new_line.write(" \"#{name.camelize(:lower)}\" => be_all([true, false]),\n")
|
179
|
+
else
|
180
|
+
new_line.write(" \"#{name.singularize.camelize(:lower)}\" => be_in([true, false]),\n")
|
181
|
+
end
|
182
|
+
when "string", "bigint", "integer", "float"
|
183
|
+
if array_true
|
184
|
+
new_line.write(" \"#{name.camelize(:lower)}\" => be_all(#{field}),\n")
|
185
|
+
else
|
186
|
+
new_line.write(" \"#{name.singularize.camelize(:lower)}\" => be_a(#{field}),\n")
|
172
187
|
end
|
173
188
|
end
|
174
189
|
end
|
175
|
-
@on = true if Souls.table_check(line: line, class_name: class_name)
|
176
190
|
end
|
191
|
+
@on = true if Souls.table_check(line: line, class_name: class_name)
|
177
192
|
end
|
178
193
|
end
|
179
|
-
file_path
|
180
|
-
end
|
181
|
-
|
182
|
-
def rspec_resolver(class_name: "user")
|
183
|
-
singularized_class_name = class_name.singularize
|
184
|
-
file_path = "./spec/resolvers/#{singularized_class_name}_search_spec.rb"
|
185
|
-
return "Resolver already exist! #{file_path}" if File.exist?(file_path)
|
186
|
-
|
187
|
-
rspec_resolver_head(class_name: singularized_class_name)
|
188
|
-
rspec_resolver_after_head(class_name: singularized_class_name)
|
189
|
-
rspec_resolver_params(class_name: singularized_class_name)
|
190
|
-
rspec_resolver_end(class_name: singularized_class_name)
|
191
|
-
puts(Paint % ["Created file! : %{white_text}", :green, { white_text: [file_path.to_s, :white] }])
|
192
|
-
file_path
|
193
|
-
rescue StandardError => e
|
194
|
-
raise(StandardError, e)
|
195
194
|
end
|
195
|
+
file_path
|
196
196
|
end
|
197
197
|
end
|
198
198
|
end
|