souls 0.44.6 → 0.45.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -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: "souls")
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
- def self.rspec_mutation_head(class_name: "souls")
5
- file_dir = "./spec/mutations/base/"
6
- FileUtils.mkdir_p(file_dir) unless Dir.exist?(file_dir)
7
- file_path = "./spec/mutations/base/#{class_name.singularize}_spec.rb"
8
- File.open(file_path, "w") do |f|
9
- f.write(<<~TEXT)
10
- RSpec.describe \"#{class_name.camelize} Mutation テスト\" do
11
- describe "#{class_name.camelize} データを登録する" do
12
- TEXT
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
- def self.rspec_mutation_after_head(class_name: "souls")
17
- file_path = "./spec/mutations/base/#{class_name.singularize}_spec.rb"
18
- path = "./db/schema.rb"
19
- @on = false
20
- @user_exist = false
21
- @relation_params = []
22
- File.open(file_path, "a") do |new_line|
23
- File.open(path, "r") do |f|
24
- f.each_line.with_index do |line, _i|
25
- if @on
26
- if line.include?("t.index") || line.strip == "end"
27
- if @relation_params.empty?
28
- new_line.write(<<-TEXT)
29
- let(:#{class_name}) { FactoryBot.attributes_for(:#{class_name}) }
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
- let(:mutation) do
32
- %(mutation {
33
- create#{class_name.camelize}(input: {
34
- TEXT
35
- else
36
- new_line.write(<<-TEXT)
37
- let(:#{class_name}) { FactoryBot.attributes_for(:#{class_name}, #{@relation_params.join(', ')}) }
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
- let(:mutation) do
40
- %(mutation {
41
- create#{class_name.camelize}(input: {
42
- TEXT
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
- def self.rspec_mutation_params(class_name: "souls")
67
- file_path = "./spec/mutations/base/#{class_name.singularize}_spec.rb"
68
- path = "./db/schema.rb"
69
- @on = false
70
- @user_exist = false
71
- File.open(file_path, "a") do |new_line|
72
- File.open(path, "r") do |f|
73
- f.each_line.with_index do |line, _i|
74
- if @on
75
- if line.include?("t.index") || line.strip == "end"
76
- new_line.write(
77
- " }) {\n #{class_name.singularize.camelize(:lower)}Edge {\n node {\n"
78
- )
79
- new_line.write(" id\n")
80
- break
81
- end
82
- type, name = line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
83
- array_true = line.include?("array: true")
84
- case name
85
- when "created_at", "updated_at"
86
- next
87
- when "user_id"
88
- @user_exist = true
89
- when /$*_id\z/
90
- camel = name.singularize.camelize(:lower)
91
- new_line.write(
92
- " #{camel}: \"\#{#{class_name.singularize}[:#{name.singularize.underscore}]}\"\n"
93
- )
94
- else
95
- camel = name.singularize.camelize(:lower)
96
- camels = name.pluralize.camelize(:lower)
97
- case type
98
- when "string", "text", "date", "datetime"
99
- if array_true
100
- new_line.write(
101
- " #{camels}: \#{#{class_name.singularize}[:#{name.pluralize.underscore}]}\n"
102
- )
103
- else
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}: \"\#{#{class_name.singularize}[:#{name.singularize.underscore}]}\"\n"
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
- def self.rspec_mutation_params_response(class_name: "souls")
122
- file_path = "./spec/mutations/base/#{class_name.singularize}_spec.rb"
123
- path = "./db/schema.rb"
124
- @on = false
125
- File.open(file_path, "a") do |new_line|
126
- File.open(path, "r") do |f|
127
- f.each_line.with_index do |line, _i|
128
- if @on
129
- if line.include?("t.index") || line.strip == "end"
130
- if @user_exist
131
- new_line.write(<<-TEXT)
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
- it "return #{class_name.camelize} Data" do
147
- begin
148
- a1 = result.dig("data", "create#{class_name.singularize.camelize}", "#{class_name.singularize.camelize(:lower)}Edge", "node")
149
- raise unless a1.present?
150
- rescue
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
- expect(a1).to include(
154
- "id" => be_a(String),
155
- TEXT
156
- else
157
- new_line.write(<<-TEXT)
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
- it "return #{class_name.camelize} Data" do
170
- begin
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
- expect(a1).to include(
177
- "id" => be_a(String),
178
- TEXT
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
- break
181
- end
182
- _, name = line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
183
- array_true = line.include?("array: true")
184
- case name
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
- new_line.write(" #{name.singularize.camelize(:lower)}\n")
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
- def self.rspec_mutation_end(class_name: "souls")
202
- file_path = "./spec/mutations/base/#{class_name.singularize}_spec.rb"
203
- path = "./db/schema.rb"
204
- @on = false
205
- File.open(file_path, "a") do |new_line|
206
- File.open(path, "r") do |f|
207
- f.each_line.with_index do |line, _i|
208
- if @on
209
- if line.include?("t.index") || line.strip == "end"
210
- new_line.write(<<~TEXT)
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
- end
215
- TEXT
216
- break
217
- end
218
- type, name = line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
219
- field ||= type_check(type)
220
- array_true = line.include?("array: true")
221
- case name
222
- when "user_id", "created_at", "updated_at", /$*_id\z/
223
- next
224
- else
225
- case type
226
- when "text", "date", "datetime"
227
- if array_true
228
- new_line.write(" \"#{name.pluralize.camelize(:lower)}\" => be_all(String),\n")
229
- else
230
- new_line.write(" \"#{name.singularize.camelize(:lower)}\" => be_a(String),\n")
231
- end
232
- when "boolean"
233
- if array_true
234
- new_line.write(" \"#{name.pluralize.camelize(:lower)}\" => be_all([true, false]),\n")
235
- else
236
- new_line.write(" \"#{name.singularize.camelize(:lower)}\" => be_in([true, false]),\n")
237
- end
238
- when "string", "bigint", "integer", "float"
239
- if array_true
240
- new_line.write(" \"#{name.pluralize.camelize(:lower)}\" => be_all(#{field}),\n")
241
- else
242
- new_line.write(" \"#{name.singularize.camelize(:lower)}\" => be_a(#{field}),\n")
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
- def self.rspec_mutation(class_name: "souls")
255
- singularized_class_name = class_name.singularize
256
- file_path = "./spec/mutations/base/#{singularized_class_name}_spec.rb"
257
- return "RspecMutation already exist! #{file_path}" if File.exist?(file_path)
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
- rspec_mutation_head(class_name: singularized_class_name)
260
- rspec_mutation_after_head(class_name: singularized_class_name)
261
- rspec_mutation_params(class_name: singularized_class_name)
262
- rspec_mutation_params_response(class_name: singularized_class_name)
263
- rspec_mutation_end(class_name: singularized_class_name)
264
- puts(Paint % ["Created file! : %{white_text}", :green, { white_text: [file_path.to_s, :white] }])
265
- file_path
266
- rescue StandardError => e
267
- raise(StandardError, e)
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