souls 0.44.3 → 0.45.0
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 -2
- data/lib/souls/api/generate/application.rb +145 -143
- data/lib/souls/api/generate/connection.rb +1 -1
- data/lib/souls/api/generate/edge.rb +1 -1
- data/lib/souls/api/generate/model.rb +1 -1
- data/lib/souls/api/generate/mutation.rb +221 -219
- data/lib/souls/api/generate/policy.rb +1 -1
- data/lib/souls/api/generate/query.rb +49 -47
- data/lib/souls/api/generate/resolver.rb +123 -121
- data/lib/souls/api/generate/rspec_factory.rb +49 -47
- data/lib/souls/api/generate/rspec_model.rb +1 -1
- data/lib/souls/api/generate/rspec_mutation.rb +215 -213
- data/lib/souls/api/generate/rspec_policy.rb +1 -1
- data/lib/souls/api/generate/rspec_query.rb +134 -132
- data/lib/souls/api/generate/rspec_resolver.rb +159 -157
- data/lib/souls/api/generate/type.rb +4 -4
- data/lib/souls/cli/gcloud/sql/index.rb +13 -3
- 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 +1 -1
@@ -1,7 +1,7 @@
|
|
1
1
|
module Souls
|
2
2
|
module Api::Generate
|
3
3
|
## Generate Rspec Model
|
4
|
-
def self.rspec_model(class_name: "
|
4
|
+
def self.rspec_model(class_name: "user")
|
5
5
|
file_dir = "./spec/models/"
|
6
6
|
FileUtils.mkdir_p(file_dir) unless Dir.exist?(file_dir)
|
7
7
|
file_path = "./spec/models/#{class_name}_spec.rb"
|
@@ -1,270 +1,272 @@
|
|
1
1
|
module Souls
|
2
2
|
module Api::Generate
|
3
3
|
## Generate Rspec Mutation
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
describe "#{class_name.camelize}
|
12
|
-
|
4
|
+
class << self
|
5
|
+
def rspec_mutation_head(class_name: "user")
|
6
|
+
file_dir = "./spec/mutations/base/"
|
7
|
+
FileUtils.mkdir_p(file_dir) unless Dir.exist?(file_dir)
|
8
|
+
file_path = "./spec/mutations/base/#{class_name.singularize}_spec.rb"
|
9
|
+
File.open(file_path, "w") do |f|
|
10
|
+
f.write(<<~TEXT)
|
11
|
+
RSpec.describe \"#{class_name.camelize} Mutation テスト\" do
|
12
|
+
describe "#{class_name.camelize} データを登録する" do
|
13
|
+
TEXT
|
14
|
+
end
|
13
15
|
end
|
14
|
-
end
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
17
|
+
def rspec_mutation_after_head(class_name: "user")
|
18
|
+
file_path = "./spec/mutations/base/#{class_name.singularize}_spec.rb"
|
19
|
+
path = "./db/schema.rb"
|
20
|
+
@on = false
|
21
|
+
@user_exist = false
|
22
|
+
@relation_params = []
|
23
|
+
File.open(file_path, "a") do |new_line|
|
24
|
+
File.open(path, "r") do |f|
|
25
|
+
f.each_line.with_index do |line, _i|
|
26
|
+
if @on
|
27
|
+
if line.include?("t.index") || line.strip == "end"
|
28
|
+
if @relation_params.empty?
|
29
|
+
new_line.write(<<-TEXT)
|
30
|
+
let(:#{class_name}) { FactoryBot.attributes_for(:#{class_name}) }
|
30
31
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
32
|
+
let(:mutation) do
|
33
|
+
%(mutation {
|
34
|
+
create#{class_name.camelize}(input: {
|
35
|
+
TEXT
|
36
|
+
else
|
37
|
+
new_line.write(<<-TEXT)
|
38
|
+
let(:#{class_name}) { FactoryBot.attributes_for(:#{class_name}, #{@relation_params.join(', ')}) }
|
38
39
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
40
|
+
let(:mutation) do
|
41
|
+
%(mutation {
|
42
|
+
create#{class_name.camelize}(input: {
|
43
|
+
TEXT
|
44
|
+
end
|
45
|
+
break
|
46
|
+
end
|
47
|
+
_, name = line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
|
48
|
+
case name
|
49
|
+
when "user_id"
|
50
|
+
relation_col = name.gsub("_id", "")
|
51
|
+
new_line.write(" let(:#{relation_col}) { FactoryBot.create(:#{relation_col}) }\n")
|
52
|
+
when /$*_id\z/
|
53
|
+
relation_col = name.gsub("_id", "")
|
54
|
+
@relation_params << "#{name}: get_global_key(\"#{name.singularize.camelize.gsub(
|
55
|
+
'Id',
|
56
|
+
''
|
57
|
+
)}\", #{relation_col}.id)"
|
58
|
+
new_line.write(" let(:#{relation_col}) { FactoryBot.create(:#{relation_col}) }\n")
|
43
59
|
end
|
44
|
-
break
|
45
|
-
end
|
46
|
-
_, name = line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
|
47
|
-
case name
|
48
|
-
when "user_id"
|
49
|
-
relation_col = name.gsub("_id", "")
|
50
|
-
new_line.write(" let(:#{relation_col}) { FactoryBot.create(:#{relation_col}) }\n")
|
51
|
-
when /$*_id\z/
|
52
|
-
relation_col = name.gsub("_id", "")
|
53
|
-
@relation_params << "#{name}: get_global_key(\"#{name.singularize.camelize.gsub(
|
54
|
-
'Id',
|
55
|
-
''
|
56
|
-
)}\", #{relation_col}.id)"
|
57
|
-
new_line.write(" let(:#{relation_col}) { FactoryBot.create(:#{relation_col}) }\n")
|
58
60
|
end
|
61
|
+
@on = true if table_check(line: line, class_name: class_name)
|
59
62
|
end
|
60
|
-
@on = true if table_check(line: line, class_name: class_name)
|
61
63
|
end
|
62
64
|
end
|
63
65
|
end
|
64
|
-
end
|
65
66
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
67
|
+
def rspec_mutation_params(class_name: "user")
|
68
|
+
file_path = "./spec/mutations/base/#{class_name.singularize}_spec.rb"
|
69
|
+
path = "./db/schema.rb"
|
70
|
+
@on = false
|
71
|
+
@user_exist = false
|
72
|
+
File.open(file_path, "a") do |new_line|
|
73
|
+
File.open(path, "r") do |f|
|
74
|
+
f.each_line.with_index do |line, _i|
|
75
|
+
if @on
|
76
|
+
if line.include?("t.index") || line.strip == "end"
|
77
|
+
new_line.write(
|
78
|
+
" }) {\n #{class_name.singularize.camelize(:lower)}Edge {\n node {\n"
|
79
|
+
)
|
80
|
+
new_line.write(" id\n")
|
81
|
+
break
|
82
|
+
end
|
83
|
+
type, name = line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
|
84
|
+
array_true = line.include?("array: true")
|
85
|
+
case name
|
86
|
+
when "created_at", "updated_at"
|
87
|
+
next
|
88
|
+
when "user_id"
|
89
|
+
@user_exist = true
|
90
|
+
when /$*_id\z/
|
91
|
+
camel = name.singularize.camelize(:lower)
|
92
|
+
new_line.write(
|
93
|
+
" #{camel}: \"\#{#{class_name.singularize}[:#{name.singularize.underscore}]}\"\n"
|
94
|
+
)
|
95
|
+
else
|
96
|
+
camel = name.singularize.camelize(:lower)
|
97
|
+
camels = name.pluralize.camelize(:lower)
|
98
|
+
case type
|
99
|
+
when "string", "text", "date", "datetime"
|
100
|
+
if array_true
|
101
|
+
new_line.write(
|
102
|
+
" #{camels}: \#{#{class_name.singularize}[:#{name.pluralize.underscore}]}\n"
|
103
|
+
)
|
104
|
+
else
|
105
|
+
new_line.write(
|
106
|
+
" #{camel}: \"\#{#{class_name.singularize}[:#{name.singularize.underscore}]}\"\n"
|
107
|
+
)
|
108
|
+
end
|
109
|
+
when "bigint", "integer", "float", "boolean"
|
104
110
|
new_line.write(
|
105
|
-
" #{camel}:
|
111
|
+
" #{camel}: \#{#{class_name.singularize}[:#{name.singularize.underscore}]}\n"
|
106
112
|
)
|
107
113
|
end
|
108
|
-
when "bigint", "integer", "float", "boolean"
|
109
|
-
new_line.write(
|
110
|
-
" #{camel}: \#{#{class_name.singularize}[:#{name.singularize.underscore}]}\n"
|
111
|
-
)
|
112
114
|
end
|
113
115
|
end
|
116
|
+
@on = true if table_check(line: line, class_name: class_name)
|
114
117
|
end
|
115
|
-
@on = true if table_check(line: line, class_name: class_name)
|
116
118
|
end
|
117
119
|
end
|
118
120
|
end
|
119
|
-
end
|
120
121
|
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
122
|
+
def rspec_mutation_params_response(class_name: "user")
|
123
|
+
file_path = "./spec/mutations/base/#{class_name.singularize}_spec.rb"
|
124
|
+
path = "./db/schema.rb"
|
125
|
+
@on = false
|
126
|
+
File.open(file_path, "a") do |new_line|
|
127
|
+
File.open(path, "r") do |f|
|
128
|
+
f.each_line.with_index do |line, _i|
|
129
|
+
if @on
|
130
|
+
if line.include?("t.index") || line.strip == "end"
|
131
|
+
if @user_exist
|
132
|
+
new_line.write(<<-TEXT)
|
133
|
+
}
|
132
134
|
}
|
133
135
|
}
|
134
136
|
}
|
135
|
-
|
136
|
-
|
137
|
-
end
|
138
|
-
|
139
|
-
subject(:result) do
|
140
|
-
context = {
|
141
|
-
user: user
|
142
|
-
}
|
143
|
-
SoulsApiSchema.execute(mutation, context: context).as_json
|
144
|
-
end
|
137
|
+
)
|
138
|
+
end
|
145
139
|
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
raise StandardError, result
|
140
|
+
subject(:result) do
|
141
|
+
context = {
|
142
|
+
user: user
|
143
|
+
}
|
144
|
+
SoulsApiSchema.execute(mutation, context: context).as_json
|
152
145
|
end
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
146
|
+
|
147
|
+
it "return #{class_name.camelize} Data" do
|
148
|
+
begin
|
149
|
+
a1 = result.dig("data", "create#{class_name.singularize.camelize}", "#{class_name.singularize.camelize(:lower)}Edge", "node")
|
150
|
+
raise unless a1.present?
|
151
|
+
rescue
|
152
|
+
raise StandardError, result
|
153
|
+
end
|
154
|
+
expect(a1).to include(
|
155
|
+
"id" => be_a(String),
|
156
|
+
TEXT
|
157
|
+
else
|
158
|
+
new_line.write(<<-TEXT)
|
159
|
+
}
|
158
160
|
}
|
159
161
|
}
|
160
162
|
}
|
161
|
-
|
162
|
-
|
163
|
-
end
|
164
|
-
|
165
|
-
subject(:result) do
|
166
|
-
SoulsApiSchema.execute(mutation).as_json
|
167
|
-
end
|
163
|
+
)
|
164
|
+
end
|
168
165
|
|
169
|
-
|
170
|
-
|
171
|
-
a1 = result.dig("data", "create#{class_name.singularize.camelize}", "#{class_name.singularize.camelize(:lower)}Edge", "node")
|
172
|
-
raise unless a1.present?
|
173
|
-
rescue
|
174
|
-
raise StandardError, result
|
166
|
+
subject(:result) do
|
167
|
+
SoulsApiSchema.execute(mutation).as_json
|
175
168
|
end
|
176
|
-
|
177
|
-
|
178
|
-
|
169
|
+
|
170
|
+
it "return #{class_name.camelize} Data" do
|
171
|
+
begin
|
172
|
+
a1 = result.dig("data", "create#{class_name.singularize.camelize}", "#{class_name.singularize.camelize(:lower)}Edge", "node")
|
173
|
+
raise unless a1.present?
|
174
|
+
rescue
|
175
|
+
raise StandardError, result
|
176
|
+
end
|
177
|
+
expect(a1).to include(
|
178
|
+
"id" => be_a(String),
|
179
|
+
TEXT
|
180
|
+
end
|
181
|
+
break
|
179
182
|
end
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
when "user_id", "created_at", "updated_at", /$*_id\z/
|
186
|
-
next
|
187
|
-
else
|
188
|
-
if array_true
|
189
|
-
new_line.write(" #{name.pluralize.camelize(:lower)}\n")
|
183
|
+
_, name = line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
|
184
|
+
array_true = line.include?("array: true")
|
185
|
+
case name
|
186
|
+
when "user_id", "created_at", "updated_at", /$*_id\z/
|
187
|
+
next
|
190
188
|
else
|
191
|
-
|
189
|
+
if array_true
|
190
|
+
new_line.write(" #{name.pluralize.camelize(:lower)}\n")
|
191
|
+
else
|
192
|
+
new_line.write(" #{name.singularize.camelize(:lower)}\n")
|
193
|
+
end
|
192
194
|
end
|
193
195
|
end
|
196
|
+
@on = true if table_check(line: line, class_name: class_name)
|
194
197
|
end
|
195
|
-
@on = true if table_check(line: line, class_name: class_name)
|
196
198
|
end
|
197
199
|
end
|
198
200
|
end
|
199
|
-
end
|
200
201
|
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
202
|
+
def rspec_mutation_end(class_name: "user")
|
203
|
+
file_path = "./spec/mutations/base/#{class_name.singularize}_spec.rb"
|
204
|
+
path = "./db/schema.rb"
|
205
|
+
@on = false
|
206
|
+
File.open(file_path, "a") do |new_line|
|
207
|
+
File.open(path, "r") do |f|
|
208
|
+
f.each_line.with_index do |line, _i|
|
209
|
+
if @on
|
210
|
+
if line.include?("t.index") || line.strip == "end"
|
211
|
+
new_line.write(<<~TEXT)
|
212
|
+
)
|
213
|
+
end
|
212
214
|
end
|
213
215
|
end
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
216
|
+
TEXT
|
217
|
+
break
|
218
|
+
end
|
219
|
+
type, name = line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
|
220
|
+
field ||= type_check(type)
|
221
|
+
array_true = line.include?("array: true")
|
222
|
+
case name
|
223
|
+
when "user_id", "created_at", "updated_at", /$*_id\z/
|
224
|
+
next
|
225
|
+
else
|
226
|
+
case type
|
227
|
+
when "text", "date", "datetime"
|
228
|
+
if array_true
|
229
|
+
new_line.write(" \"#{name.pluralize.camelize(:lower)}\" => be_all(String),\n")
|
230
|
+
else
|
231
|
+
new_line.write(" \"#{name.singularize.camelize(:lower)}\" => be_a(String),\n")
|
232
|
+
end
|
233
|
+
when "boolean"
|
234
|
+
if array_true
|
235
|
+
new_line.write(" \"#{name.pluralize.camelize(:lower)}\" => be_all([true, false]),\n")
|
236
|
+
else
|
237
|
+
new_line.write(" \"#{name.singularize.camelize(:lower)}\" => be_in([true, false]),\n")
|
238
|
+
end
|
239
|
+
when "string", "bigint", "integer", "float"
|
240
|
+
if array_true
|
241
|
+
new_line.write(" \"#{name.pluralize.camelize(:lower)}\" => be_all(#{field}),\n")
|
242
|
+
else
|
243
|
+
new_line.write(" \"#{name.singularize.camelize(:lower)}\" => be_a(#{field}),\n")
|
244
|
+
end
|
243
245
|
end
|
244
246
|
end
|
245
247
|
end
|
248
|
+
@on = true if table_check(line: line, class_name: class_name)
|
246
249
|
end
|
247
|
-
@on = true if table_check(line: line, class_name: class_name)
|
248
250
|
end
|
249
251
|
end
|
252
|
+
file_path
|
250
253
|
end
|
251
|
-
file_path
|
252
|
-
end
|
253
254
|
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
255
|
+
def rspec_mutation(class_name: "user")
|
256
|
+
singularized_class_name = class_name.singularize
|
257
|
+
file_path = "./spec/mutations/base/#{singularized_class_name}_spec.rb"
|
258
|
+
return "RspecMutation already exist! #{file_path}" if File.exist?(file_path)
|
258
259
|
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
260
|
+
rspec_mutation_head(class_name: singularized_class_name)
|
261
|
+
rspec_mutation_after_head(class_name: singularized_class_name)
|
262
|
+
rspec_mutation_params(class_name: singularized_class_name)
|
263
|
+
rspec_mutation_params_response(class_name: singularized_class_name)
|
264
|
+
rspec_mutation_end(class_name: singularized_class_name)
|
265
|
+
puts(Paint % ["Created file! : %{white_text}", :green, { white_text: [file_path.to_s, :white] }])
|
266
|
+
file_path
|
267
|
+
rescue StandardError => e
|
268
|
+
raise(StandardError, e)
|
269
|
+
end
|
268
270
|
end
|
269
271
|
end
|
270
272
|
end
|