souls 0.18.0 → 0.20.3
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/.gitignore +0 -1
- data/.rubocop.yml +3 -0
- data/Gemfile.lock +2 -1
- data/README.md +8 -10
- data/Rakefile +17 -0
- data/db/schema.rb +67 -0
- data/exe/souls +33 -35
- data/lib/souls.rb +19 -40
- data/lib/souls/generate/application.rb +156 -0
- data/lib/souls/generate/model.rb +20 -0
- data/lib/souls/generate/mutation.rb +276 -0
- data/lib/souls/generate/policy.rb +51 -0
- data/lib/souls/generate/query.rb +56 -0
- data/lib/souls/generate/resolver.rb +153 -0
- data/lib/souls/generate/rspec_factory.rb +63 -0
- data/lib/souls/generate/rspec_model.rb +23 -0
- data/lib/souls/generate/rspec_mutation.rb +247 -0
- data/lib/souls/generate/rspec_policy.rb +50 -0
- data/lib/souls/generate/rspec_query.rb +169 -0
- data/lib/souls/generate/rspec_resolver.rb +189 -0
- data/lib/souls/generate/type.rb +83 -0
- data/lib/souls/init.rb +9 -1138
- data/lib/souls/version.rb +1 -1
- data/souls.gemspec +1 -1
- metadata +23 -10
- data/lib/souls/generate.rb +0 -520
data/lib/souls/version.rb
CHANGED
data/souls.gemspec
CHANGED
@@ -7,7 +7,7 @@ Gem::Specification.new do |spec|
|
|
7
7
|
spec.email = ["f.kawasaki@elsoul.nl", "s.kishi@elsoul.nl", "jamesoneve@gmail.com"]
|
8
8
|
|
9
9
|
spec.summary = "SOULS is a GraphQL Based Web Application Framework for Microservices on Multi Cloud Platform such as Google Cloud Platform, Amazon Web Services, and Alibaba Cloud. Auto deploy with scalable condition. You can focus on business logic. No more infra problems."
|
10
|
-
spec.description = "SOULS is a Web Application Framework for Microservices on Multi Cloud Platform such as Google Cloud Platform, Amazon Web Services, and Alibaba Cloud. Auto deploy with scalable condition. You can focus on business logic. No more infra problems."
|
10
|
+
spec.description = "SOULS is a GraphQL Based Web Application Framework for Microservices on Multi Cloud Platform such as Google Cloud Platform, Amazon Web Services, and Alibaba Cloud. Auto deploy with scalable condition. You can focus on business logic. No more infra problems."
|
11
11
|
spec.homepage = "https://github.com/elsoul/souls"
|
12
12
|
spec.license = "Apache-2.0"
|
13
13
|
spec.required_ruby_version = Gem::Requirement.new(">= 3.0.0")
|
metadata
CHANGED
@@ -1,21 +1,21 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: souls
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.20.3
|
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-
|
13
|
+
date: 2021-05-20 00:00:00.000000000 Z
|
14
14
|
dependencies: []
|
15
|
-
description: SOULS is a Web Application Framework for Microservices
|
16
|
-
Platform such as Google Cloud Platform, Amazon Web Services, and
|
17
|
-
Auto deploy with scalable condition. You can focus on business logic.
|
18
|
-
problems.
|
15
|
+
description: SOULS is a GraphQL Based Web Application Framework for Microservices
|
16
|
+
on Multi Cloud Platform such as Google Cloud Platform, Amazon Web Services, and
|
17
|
+
Alibaba Cloud. Auto deploy with scalable condition. You can focus on business logic.
|
18
|
+
No more infra problems.
|
19
19
|
email:
|
20
20
|
- f.kawasaki@elsoul.nl
|
21
21
|
- s.kishi@elsoul.nl
|
@@ -41,9 +41,22 @@ files:
|
|
41
41
|
- bin/console
|
42
42
|
- bin/setup
|
43
43
|
- config/souls.rb
|
44
|
+
- db/schema.rb
|
44
45
|
- exe/souls
|
45
46
|
- lib/souls.rb
|
46
|
-
- lib/souls/generate.rb
|
47
|
+
- lib/souls/generate/application.rb
|
48
|
+
- lib/souls/generate/model.rb
|
49
|
+
- lib/souls/generate/mutation.rb
|
50
|
+
- lib/souls/generate/policy.rb
|
51
|
+
- lib/souls/generate/query.rb
|
52
|
+
- lib/souls/generate/resolver.rb
|
53
|
+
- lib/souls/generate/rspec_factory.rb
|
54
|
+
- lib/souls/generate/rspec_model.rb
|
55
|
+
- lib/souls/generate/rspec_mutation.rb
|
56
|
+
- lib/souls/generate/rspec_policy.rb
|
57
|
+
- lib/souls/generate/rspec_query.rb
|
58
|
+
- lib/souls/generate/rspec_resolver.rb
|
59
|
+
- lib/souls/generate/type.rb
|
47
60
|
- lib/souls/init.rb
|
48
61
|
- lib/souls/version.rb
|
49
62
|
- rbs/init.rbs
|
@@ -55,7 +68,7 @@ metadata:
|
|
55
68
|
homepage_uri: https://github.com/elsoul/souls
|
56
69
|
source_code_uri: https://github.com/elsoul/souls
|
57
70
|
changelog_uri: https://github.com/elsoul/souls
|
58
|
-
post_install_message:
|
71
|
+
post_install_message:
|
59
72
|
rdoc_options: []
|
60
73
|
require_paths:
|
61
74
|
- lib
|
@@ -71,7 +84,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
71
84
|
version: '0'
|
72
85
|
requirements: []
|
73
86
|
rubygems_version: 3.2.3
|
74
|
-
signing_key:
|
87
|
+
signing_key:
|
75
88
|
specification_version: 4
|
76
89
|
summary: SOULS is a GraphQL Based Web Application Framework for Microservices on Multi
|
77
90
|
Cloud Platform such as Google Cloud Platform, Amazon Web Services, and Alibaba Cloud.
|
data/lib/souls/generate.rb
DELETED
@@ -1,520 +0,0 @@
|
|
1
|
-
module Souls
|
2
|
-
module Init
|
3
|
-
class << self
|
4
|
-
def get_type_and_name line
|
5
|
-
line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
|
6
|
-
end
|
7
|
-
|
8
|
-
def node_type class_name: "souls"
|
9
|
-
file_path = "./app/graphql/types/#{class_name.singularize}_node_type.rb"
|
10
|
-
File.open(file_path, "w") do |f|
|
11
|
-
f.write <<~EOS
|
12
|
-
module Types
|
13
|
-
class #{class_name.camelize}NodeType < GraphQL::Schema::Object
|
14
|
-
field :node, Types::#{class_name.camelize}Type, null: true
|
15
|
-
end
|
16
|
-
end
|
17
|
-
EOS
|
18
|
-
end
|
19
|
-
[file_path]
|
20
|
-
end
|
21
|
-
|
22
|
-
def policy class_name: "souls"
|
23
|
-
dir_name = "./app/policies"
|
24
|
-
FileUtils.mkdir_p dir_name unless Dir.exist? dir_name
|
25
|
-
file_path = "./app/policies/#{class_name.singularize}_policy.rb"
|
26
|
-
File.open(file_path, "w") do |f|
|
27
|
-
f.write <<~EOS
|
28
|
-
class #{class_name.camelize}Policy < ApplicationPolicy
|
29
|
-
def show?
|
30
|
-
true
|
31
|
-
end
|
32
|
-
|
33
|
-
def index?
|
34
|
-
true
|
35
|
-
end
|
36
|
-
|
37
|
-
def create?
|
38
|
-
staff_permissions?
|
39
|
-
end
|
40
|
-
|
41
|
-
def update?
|
42
|
-
staff_permissions?
|
43
|
-
end
|
44
|
-
|
45
|
-
def delete?
|
46
|
-
staff_permissions?
|
47
|
-
end
|
48
|
-
|
49
|
-
private
|
50
|
-
|
51
|
-
def staff_permissions?
|
52
|
-
@user.master? or @user.admin? or @user.staff?
|
53
|
-
end
|
54
|
-
|
55
|
-
def admin_permissions?
|
56
|
-
@user.master? or @user.admin?
|
57
|
-
end
|
58
|
-
end
|
59
|
-
EOS
|
60
|
-
end
|
61
|
-
[file_path]
|
62
|
-
end
|
63
|
-
|
64
|
-
def rspec_policy class_name: "souls"
|
65
|
-
dir_name = "./spec/policies"
|
66
|
-
FileUtils.mkdir_p dir_name unless Dir.exist? dir_name
|
67
|
-
file_path = "./spec/policies/#{class_name}_policy_spec.rb"
|
68
|
-
File.open(file_path, "w") do |new_line|
|
69
|
-
new_line.write <<~EOS
|
70
|
-
describe #{class_name.camelize}Policy do
|
71
|
-
subject { described_class.new(user, #{class_name.underscore}) }
|
72
|
-
|
73
|
-
let(:#{class_name.underscore}) { FactoryBot.create(:#{class_name.underscore}) }
|
74
|
-
|
75
|
-
context "being a visitor" do
|
76
|
-
let(:user) { FactoryBot.create(:user) }
|
77
|
-
|
78
|
-
it { is_expected.to permit_action(:index) }
|
79
|
-
it { is_expected.to permit_action(:show) }
|
80
|
-
it { is_expected.to forbid_actions([:create, :update, :delete]) }
|
81
|
-
end
|
82
|
-
|
83
|
-
context "being a retailer" do
|
84
|
-
let(:user) { FactoryBot.create(:user, user_role: 1) }
|
85
|
-
|
86
|
-
it { is_expected.to permit_action(:index) }
|
87
|
-
it { is_expected.to permit_action(:show) }
|
88
|
-
it { is_expected.to forbid_actions([:create, :update, :delete]) }
|
89
|
-
end
|
90
|
-
|
91
|
-
context "being a staff" do
|
92
|
-
let(:user) { FactoryBot.create(:user, user_role: 3) }
|
93
|
-
|
94
|
-
it { is_expected.to permit_actions([:create, :update, :delete]) }
|
95
|
-
end
|
96
|
-
|
97
|
-
context "being an administrator" do
|
98
|
-
let(:user) { FactoryBot.create(:user, user_role: 4) }
|
99
|
-
|
100
|
-
it { is_expected.to permit_actions([:create, :update, :delete]) }
|
101
|
-
end
|
102
|
-
end
|
103
|
-
EOS
|
104
|
-
end
|
105
|
-
[file_path]
|
106
|
-
end
|
107
|
-
|
108
|
-
def resolver_head class_name: "souls"
|
109
|
-
FileUtils.mkdir_p "./app/graphql/resolvers" unless Dir.exist? "./app/graphql/resolvers"
|
110
|
-
file_path = "./app/graphql/resolvers/#{class_name.singularize}_search.rb"
|
111
|
-
@relation_params = []
|
112
|
-
return ["Resolver already exist! #{file_path}"] if File.exist? file_path
|
113
|
-
File.open(file_path, "w") do |f|
|
114
|
-
f.write <<~EOS
|
115
|
-
module Resolvers
|
116
|
-
class #{class_name.camelize}Search < Base
|
117
|
-
include SearchObject.module(:graphql)
|
118
|
-
scope { ::#{class_name.camelize}.all }
|
119
|
-
type Types::#{class_name.camelize}Type.connection_type, null: false
|
120
|
-
description "Search #{class_name.camelize}"
|
121
|
-
|
122
|
-
class #{class_name.camelize}Filter < ::Types::BaseInputObject
|
123
|
-
argument :OR, [self], required: false
|
124
|
-
EOS
|
125
|
-
end
|
126
|
-
end
|
127
|
-
|
128
|
-
def resolver_params class_name: "souls"
|
129
|
-
file_path = "./app/graphql/resolvers/#{class_name.singularize}_search.rb"
|
130
|
-
path = "./db/schema.rb"
|
131
|
-
@on = false
|
132
|
-
@user_exist = false
|
133
|
-
@relation_params = []
|
134
|
-
File.open(file_path, "a") do |new_line|
|
135
|
-
File.open(path, "r") do |f|
|
136
|
-
f.each_line.with_index do |line, i|
|
137
|
-
if @on
|
138
|
-
if line.include?("end") || line.include?("t.index")
|
139
|
-
break
|
140
|
-
end
|
141
|
-
field = "[String]" if line.include?("array: true")
|
142
|
-
type, name = get_type_and_name(line)
|
143
|
-
field ||= type_check type
|
144
|
-
case name
|
145
|
-
when "user_id"
|
146
|
-
@user_exist = true
|
147
|
-
when /$*_id\z/
|
148
|
-
@relation_params << name
|
149
|
-
new_line.write " argument :#{name}, String, required: false\n"
|
150
|
-
when "created_at", "updated_at"
|
151
|
-
next
|
152
|
-
else
|
153
|
-
new_line.write " argument :#{name}, #{field}, required: false\n"
|
154
|
-
end
|
155
|
-
end
|
156
|
-
@on = true if table_check(line: line, class_name: class_name)
|
157
|
-
end
|
158
|
-
end
|
159
|
-
end
|
160
|
-
end
|
161
|
-
|
162
|
-
def resolver_after_params class_name: "souls"
|
163
|
-
file_path = "./app/graphql/resolvers/#{class_name.singularize}_search.rb"
|
164
|
-
File.open(file_path, "a") do |f|
|
165
|
-
f.write <<-EOS
|
166
|
-
argument :start_date, String, required: false
|
167
|
-
argument :end_date, String, required: false
|
168
|
-
end
|
169
|
-
|
170
|
-
option :filter, type: #{class_name.camelize}Filter, with: :apply_filter
|
171
|
-
option :first, type: types.Int, with: :apply_first
|
172
|
-
option :skip, type: types.Int, with: :apply_skip
|
173
|
-
|
174
|
-
def apply_filter(scope, value)
|
175
|
-
branches = normalize_filters(value).inject { |a, b| a.or(b) }
|
176
|
-
scope.merge branches
|
177
|
-
end
|
178
|
-
|
179
|
-
def normalize_filters(value, branches = [])
|
180
|
-
scope = ::#{class_name.camelize}.all
|
181
|
-
EOS
|
182
|
-
end
|
183
|
-
end
|
184
|
-
|
185
|
-
def resolver_before_end class_name: "souls"
|
186
|
-
file_path = "./app/graphql/resolvers/#{class_name.singularize}_search.rb"
|
187
|
-
path = "./db/schema.rb"
|
188
|
-
@on = false
|
189
|
-
@user_exist = false
|
190
|
-
@relation_params = []
|
191
|
-
File.open(file_path, "a") do |new_line|
|
192
|
-
File.open(path, "r") do |f|
|
193
|
-
f.each_line.with_index do |line, i|
|
194
|
-
if @on
|
195
|
-
if line.include?("end") || line.include?("t.index")
|
196
|
-
break
|
197
|
-
end
|
198
|
-
type, name = get_type_and_name(line)
|
199
|
-
if line.include?("array: true")
|
200
|
-
new_line.write " scope = scope.where(\"#{name} @> ARRAY[?]::text[]\", value[:#{name}]) if value[:#{name}]\n"
|
201
|
-
next
|
202
|
-
end
|
203
|
-
case name
|
204
|
-
when "user_id"
|
205
|
-
@user_exist = true
|
206
|
-
when /$*_id\z/
|
207
|
-
@relation_params << name
|
208
|
-
new_line.write " scope = scope.where(#{name}: decode_global_key(value[:#{name}])) if value[:#{name}]\n"
|
209
|
-
when "created_at", "updated_at"
|
210
|
-
next
|
211
|
-
else
|
212
|
-
case type
|
213
|
-
when "boolean"
|
214
|
-
new_line.write " scope = scope.where(#{name}: value[:#{name}]) unless value[:#{name}].nil?\n"
|
215
|
-
else
|
216
|
-
new_line.write " scope = scope.where(#{name}: value[:#{name}]) if value[:#{name}]\n"
|
217
|
-
end
|
218
|
-
end
|
219
|
-
end
|
220
|
-
@on = true if table_check(line: line, class_name: class_name)
|
221
|
-
end
|
222
|
-
end
|
223
|
-
end
|
224
|
-
end
|
225
|
-
|
226
|
-
def resolver_end class_name: "souls"
|
227
|
-
file_path = "./app/graphql/resolvers/#{class_name.singularize}_search.rb"
|
228
|
-
File.open(file_path, "a") do |f|
|
229
|
-
f.write <<~EOS
|
230
|
-
scope = scope.where("created_at >= ?", value[:start_date]) if value[:start_date]
|
231
|
-
scope = scope.where("created_at <= ?", value[:end_date]) if value[:end_date]
|
232
|
-
#{' '}
|
233
|
-
branches << scope
|
234
|
-
#{' '}
|
235
|
-
value[:OR].inject(branches) { |s, v| normalize_filters(v, s) } if value[:OR].present?
|
236
|
-
#{' '}
|
237
|
-
branches
|
238
|
-
end
|
239
|
-
end
|
240
|
-
end
|
241
|
-
EOS
|
242
|
-
end
|
243
|
-
[file_path]
|
244
|
-
end
|
245
|
-
|
246
|
-
def resolver class_name: "souls"
|
247
|
-
singularized_class_name = class_name.singularize.underscore
|
248
|
-
resolver_head class_name: singularized_class_name
|
249
|
-
resolver_params class_name: singularized_class_name
|
250
|
-
resolver_after_params class_name: singularized_class_name
|
251
|
-
resolver_before_end class_name: singularized_class_name
|
252
|
-
resolver_end class_name: singularized_class_name
|
253
|
-
end
|
254
|
-
|
255
|
-
def job class_name: "send_mail"
|
256
|
-
file_path = "./app/jobs/#{class_name.singularize}_job.rb"
|
257
|
-
return ["Job already exist! #{file_path}"] if File.exist? file_path
|
258
|
-
File.open(file_path, "w") do |f|
|
259
|
-
f.write <<~EOS
|
260
|
-
class #{class_name.camelize}
|
261
|
-
|
262
|
-
def perform **args
|
263
|
-
# write task code here
|
264
|
-
end
|
265
|
-
end
|
266
|
-
EOS
|
267
|
-
end
|
268
|
-
[file_path]
|
269
|
-
end
|
270
|
-
|
271
|
-
def rspec_resolver_head class_name: "souls"
|
272
|
-
file_path = "./spec/resolvers/#{class_name.singularize}_search_spec.rb"
|
273
|
-
puts file_path
|
274
|
-
File.open(file_path, "w") do |f|
|
275
|
-
f.write <<~EOS
|
276
|
-
RSpec.describe \"#{class_name.camelize}Search Resolver テスト\" do
|
277
|
-
describe "削除フラグ false の #{class_name.camelize} を返却する" do
|
278
|
-
EOS
|
279
|
-
end
|
280
|
-
end
|
281
|
-
|
282
|
-
def rspec_resolver_after_head class_name: "souls"
|
283
|
-
file_path = "./spec/resolvers/#{class_name.singularize}_search_spec.rb"
|
284
|
-
path = "./db/schema.rb"
|
285
|
-
@on = false
|
286
|
-
@user_exist = false
|
287
|
-
@relation_params = []
|
288
|
-
File.open(file_path, "a") do |new_line|
|
289
|
-
File.open(path, "r") do |f|
|
290
|
-
f.each_line.with_index do |line, i|
|
291
|
-
if @on
|
292
|
-
if line.include?("end") || line.include?("t.index")
|
293
|
-
if @relation_params.empty?
|
294
|
-
new_line.write <<-EOS
|
295
|
-
let!(:#{class_name}) { FactoryBot.create(:#{class_name}) }
|
296
|
-
|
297
|
-
let(:query) do
|
298
|
-
%(query {
|
299
|
-
#{class_name.singularize.camelize(:lower)}Search(filter: {
|
300
|
-
isDeleted: false
|
301
|
-
}) {
|
302
|
-
edges {
|
303
|
-
cursor
|
304
|
-
node {
|
305
|
-
id
|
306
|
-
EOS
|
307
|
-
else
|
308
|
-
new_line.write <<-EOS
|
309
|
-
let!(:#{class_name}) { FactoryBot.create(:#{class_name}, #{@relation_params.join(", ")}) }
|
310
|
-
|
311
|
-
let(:query) do
|
312
|
-
%(query {
|
313
|
-
#{class_name.singularize.camelize(:lower)}Search(filter: {
|
314
|
-
isDeleted: false
|
315
|
-
}) {
|
316
|
-
edges {
|
317
|
-
cursor
|
318
|
-
node {
|
319
|
-
id
|
320
|
-
EOS
|
321
|
-
end
|
322
|
-
break
|
323
|
-
end
|
324
|
-
_, name = line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
|
325
|
-
case name
|
326
|
-
when /$*_id\z/
|
327
|
-
relation_col = name.gsub("_id", "")
|
328
|
-
@relation_params << "#{name}: #{relation_col}.id"
|
329
|
-
new_line.write " let(:#{relation_col}) { FactoryBot.create(:#{relation_col}) }\n"
|
330
|
-
end
|
331
|
-
end
|
332
|
-
if table_check(line: line, class_name: class_name)
|
333
|
-
@on = true
|
334
|
-
end
|
335
|
-
end
|
336
|
-
end
|
337
|
-
end
|
338
|
-
end
|
339
|
-
|
340
|
-
def rspec_resolver_params class_name: "souls"
|
341
|
-
file_path = "./spec/resolvers/#{class_name.singularize}_search_spec.rb"
|
342
|
-
path = "./db/schema.rb"
|
343
|
-
@on = false
|
344
|
-
File.open(file_path, "a") do |new_line|
|
345
|
-
File.open(path, "r") do |f|
|
346
|
-
f.each_line.with_index do |line, i|
|
347
|
-
if @on
|
348
|
-
if line.include?("end") || line.include?("t.index")
|
349
|
-
new_line.write <<-EOS
|
350
|
-
}
|
351
|
-
}
|
352
|
-
nodes {
|
353
|
-
id
|
354
|
-
}
|
355
|
-
pageInfo {
|
356
|
-
endCursor
|
357
|
-
hasNextPage
|
358
|
-
startCursor
|
359
|
-
hasPreviousPage
|
360
|
-
}
|
361
|
-
}
|
362
|
-
}
|
363
|
-
)
|
364
|
-
end
|
365
|
-
|
366
|
-
subject(:result) do
|
367
|
-
SoulsApiSchema.execute(query).as_json
|
368
|
-
end
|
369
|
-
|
370
|
-
it "return #{class_name.camelize} Data" do
|
371
|
-
begin
|
372
|
-
a1 = result.dig("data", "#{class_name.singularize.camelize(:lower)}Search", "edges")[0]["node"]
|
373
|
-
raise unless a1.present?
|
374
|
-
rescue
|
375
|
-
raise StandardError, result
|
376
|
-
end
|
377
|
-
expect(a1).to include(
|
378
|
-
"id" => be_a(String),
|
379
|
-
EOS
|
380
|
-
break
|
381
|
-
end
|
382
|
-
_, name = line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
|
383
|
-
case name
|
384
|
-
when "user_id", "created_at", "updated_at", /$*_id\z/
|
385
|
-
next
|
386
|
-
else
|
387
|
-
new_line.write " #{name.camelize(:lower)}\n"
|
388
|
-
end
|
389
|
-
end
|
390
|
-
if table_check(line: line, class_name: class_name)
|
391
|
-
@on = true
|
392
|
-
end
|
393
|
-
end
|
394
|
-
end
|
395
|
-
end
|
396
|
-
end
|
397
|
-
|
398
|
-
def rspec_resolver_end class_name: "souls"
|
399
|
-
file_path = "./spec/resolvers/#{class_name.singularize}_search_spec.rb"
|
400
|
-
path = "./db/schema.rb"
|
401
|
-
@on = false
|
402
|
-
File.open(file_path, "a") do |new_line|
|
403
|
-
File.open(path, "r") do |f|
|
404
|
-
f.each_line.with_index do |line, i|
|
405
|
-
if @on
|
406
|
-
if line.include?("end") || line.include?("t.index")
|
407
|
-
new_line.write <<~EOS
|
408
|
-
)
|
409
|
-
end
|
410
|
-
end
|
411
|
-
end
|
412
|
-
EOS
|
413
|
-
break
|
414
|
-
end
|
415
|
-
type, name = line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
|
416
|
-
field ||= type_check type
|
417
|
-
array_true = line.include?("array: true")
|
418
|
-
case name
|
419
|
-
when "user_id", "created_at", "updated_at", /$*_id\z/
|
420
|
-
next
|
421
|
-
else
|
422
|
-
case type
|
423
|
-
when "text", "date", "datetime"
|
424
|
-
if array_true
|
425
|
-
new_line.write " \"#{name.camelize(:lower)}\" => be_all(String),\n"
|
426
|
-
else
|
427
|
-
new_line.write " \"#{name.camelize(:lower)}\" => be_a(String),\n"
|
428
|
-
end
|
429
|
-
when "boolean"
|
430
|
-
new_line.write " \"#{name.singularize.camelize(:lower)}\" => be_in([true, false]),\n"
|
431
|
-
when "string", "bigint", "integer", "float"
|
432
|
-
new_line.write " \"#{name.singularize.camelize(:lower)}\" => be_a(#{field}),\n"
|
433
|
-
end
|
434
|
-
end
|
435
|
-
end
|
436
|
-
if table_check(line: line, class_name: class_name)
|
437
|
-
@on = true
|
438
|
-
end
|
439
|
-
end
|
440
|
-
end
|
441
|
-
end
|
442
|
-
[file_path]
|
443
|
-
end
|
444
|
-
|
445
|
-
def rspec_resolver class_name: "souls"
|
446
|
-
singularized_class_name = class_name.singularize
|
447
|
-
file_path = "#{Dir.pwd}/spec/resolvers/#{singularized_class_name}_search_spec.rb"
|
448
|
-
return ["Resolver already exist! #{file_path}"] if File.exist? file_path
|
449
|
-
rspec_resolver_head class_name: singularized_class_name
|
450
|
-
rspec_resolver_after_head class_name: singularized_class_name
|
451
|
-
rspec_resolver_params class_name: singularized_class_name
|
452
|
-
rspec_resolver_end class_name: singularized_class_name
|
453
|
-
end
|
454
|
-
|
455
|
-
def add_delete class_name: "souls"
|
456
|
-
singularized_class_name = class_name.singularize.underscore
|
457
|
-
pluralized_class_name = class_name.pluralize.underscore
|
458
|
-
FileUtils.rm_rf "./app/graphql/mutations/#{singularized_class_name}"
|
459
|
-
FileUtils.rm "./app/graphql/queries/#{singularized_class_name}.rb"
|
460
|
-
FileUtils.rm "./app/graphql/queries/#{pluralized_class_name}.rb"
|
461
|
-
FileUtils.rm "./app/graphql/resolvers/#{singularized_class_name}_search.rb"
|
462
|
-
FileUtils.rm "./app/graphql/types/#{singularized_class_name}_type.rb"
|
463
|
-
FileUtils.rm "./app/graphql/types/#{singularized_class_name}_node_type.rb"
|
464
|
-
FileUtils.rm "./spec/factories/#{pluralized_class_name}.rb"
|
465
|
-
FileUtils.rm "./spec/mutations/#{singularized_class_name}_spec.rb"
|
466
|
-
FileUtils.rm "./spec/models/#{singularized_class_name}_spec.rb"
|
467
|
-
FileUtils.rm "./spec/queries/#{singularized_class_name}_spec.rb"
|
468
|
-
FileUtils.rm "./spec/resolvers/#{singularized_class_name}_search_spec.rb"
|
469
|
-
puts "deleted #{class_name.camelize} CRUD!"
|
470
|
-
rescue StandardError => error
|
471
|
-
puts error
|
472
|
-
end
|
473
|
-
|
474
|
-
def delete_all class_name: "souls"
|
475
|
-
singularized_class_name = class_name.singularize.underscore
|
476
|
-
pluralized_class_name = class_name.pluralize.underscore
|
477
|
-
FileUtils.rm "./app/models/#{singularized_class_name}.rb"
|
478
|
-
FileUtils.rm_rf "./app/graphql/mutations/#{singularized_class_name}"
|
479
|
-
FileUtils.rm "./app/graphql/queries/#{singularized_class_name}.rb"
|
480
|
-
FileUtils.rm "./app/graphql/queries/#{pluralized_class_name}.rb"
|
481
|
-
FileUtils.rm "./app/graphql/resolvers/#{singularized_class_name}_search.rb"
|
482
|
-
FileUtils.rm "./app/graphql/types/#{singularized_class_name}_type.rb"
|
483
|
-
FileUtils.rm "./app/graphql/types/#{singularized_class_name}_node_type.rb"
|
484
|
-
FileUtils.rm "./spec/factories/#{pluralized_class_name}.rb"
|
485
|
-
FileUtils.rm "./spec/mutations/#{singularized_class_name}_spec.rb"
|
486
|
-
FileUtils.rm "./spec/models/#{singularized_class_name}_spec.rb"
|
487
|
-
FileUtils.rm "./spec/queries/#{singularized_class_name}_spec.rb"
|
488
|
-
FileUtils.rm "./spec/resolvers/#{singularized_class_name}_search_spec.rb"
|
489
|
-
puts "deleted #{class_name.camelize} CRUD!"
|
490
|
-
rescue StandardError => error
|
491
|
-
puts error
|
492
|
-
end
|
493
|
-
|
494
|
-
def add_mutation class_name: "souls", file_name: "hoi"
|
495
|
-
singularized_class_name = class_name.singularize.underscore
|
496
|
-
"./app/graphql/mutations/#{singularized_class_name}/#{file_name}.rb"
|
497
|
-
end
|
498
|
-
|
499
|
-
def add_type class_name: "souls", file_name: "hoi"
|
500
|
-
singularized_class_name = class_name.singularize.underscore
|
501
|
-
"./app/graphql/types/#{file_name}.rb"
|
502
|
-
end
|
503
|
-
|
504
|
-
def add_edge class_name: "souls", file_name: "hoi"
|
505
|
-
singularized_class_name = class_name.singularize.underscore
|
506
|
-
"./app/graphql/types/#{file_name}.rb"
|
507
|
-
end
|
508
|
-
|
509
|
-
def add_connection class_name: "souls", file_name: "hoi"
|
510
|
-
singularized_class_name = class_name.singularize.underscore
|
511
|
-
"./app/graphql/types/#{file_name}.rb"
|
512
|
-
end
|
513
|
-
|
514
|
-
def add_rspec_mutation class_name: "souls", file_name: "hoi"
|
515
|
-
singularized_class_name = class_name.singularize.underscore
|
516
|
-
"./app/graphql/types/#{file_name}.rb"
|
517
|
-
end
|
518
|
-
end
|
519
|
-
end
|
520
|
-
end
|