souls 0.17.9 → 0.20.2
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 -2
- data/README.md +8 -10
- data/Rakefile +17 -0
- data/config/souls.rb +4 -0
- data/db/schema.rb +67 -0
- data/exe/souls +36 -34
- data/lib/souls.rb +24 -45
- data/lib/souls/generate/app/policies/user_policy.rb +31 -0
- 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 +18 -1134
- data/lib/souls/version.rb +1 -1
- data/souls.gemspec +1 -1
- metadata +25 -11
- data/config/initializers/souls.rb +0 -14
- data/lib/souls/generate.rb +0 -520
@@ -0,0 +1,20 @@
|
|
1
|
+
module Souls
|
2
|
+
module Generate
|
3
|
+
class << self
|
4
|
+
## Generate Model
|
5
|
+
def model class_name: "souls"
|
6
|
+
file_dir = "./app/models/"
|
7
|
+
FileUtils.mkdir_p file_dir unless Dir.exist? file_dir
|
8
|
+
file_path = "#{file_dir}#{class_name.singularize}.rb"
|
9
|
+
return "Model already exist! #{file_path}" if File.exist? file_path
|
10
|
+
File.open(file_path, "w") do |f|
|
11
|
+
f.write <<~EOS
|
12
|
+
class #{class_name.camelize} < ActiveRecord::Base
|
13
|
+
end
|
14
|
+
EOS
|
15
|
+
end
|
16
|
+
file_path
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,276 @@
|
|
1
|
+
module Souls
|
2
|
+
module Generate
|
3
|
+
class << self
|
4
|
+
## Generate 4 Mutations - ["create", "update", "delete", "destroy_delete"]
|
5
|
+
## 1.Mutation - Create
|
6
|
+
def create_mutation_head class_name: "user"
|
7
|
+
singularized_class_name = class_name.singularize.underscore
|
8
|
+
dir_name = "./app/graphql/mutations/#{singularized_class_name}"
|
9
|
+
FileUtils.mkdir_p dir_name unless Dir.exist? dir_name
|
10
|
+
file_path = "./app/graphql/mutations/#{singularized_class_name}/create_#{singularized_class_name}.rb"
|
11
|
+
File.open(file_path, "w") do |new_line|
|
12
|
+
new_line.write <<~EOS
|
13
|
+
module Mutations
|
14
|
+
module #{singularized_class_name.camelize}
|
15
|
+
class Create#{singularized_class_name.camelize} < BaseMutation
|
16
|
+
field :#{singularized_class_name}_edge, Types::#{singularized_class_name.camelize}NodeType, null: false
|
17
|
+
field :error, String, null: true
|
18
|
+
|
19
|
+
EOS
|
20
|
+
end
|
21
|
+
file_path
|
22
|
+
end
|
23
|
+
|
24
|
+
def create_mutation_params class_name: "souls"
|
25
|
+
file_path = "./app/graphql/mutations/#{class_name}/create_#{class_name}.rb"
|
26
|
+
path = "./db/schema.rb"
|
27
|
+
@on = false
|
28
|
+
@user_exist = false
|
29
|
+
@relation_params = []
|
30
|
+
File.open(file_path, "a") do |new_line|
|
31
|
+
File.open(path, "r") do |f|
|
32
|
+
f.each_line.with_index do |line, i|
|
33
|
+
if @on
|
34
|
+
if line.include?("end") || line.include?("t.index")
|
35
|
+
if @user_exist
|
36
|
+
new_line.write <<-EOS
|
37
|
+
|
38
|
+
def resolve **args
|
39
|
+
args[:user_id] = context[:user].id
|
40
|
+
EOS
|
41
|
+
else
|
42
|
+
new_line.write <<-EOS
|
43
|
+
|
44
|
+
def resolve **args
|
45
|
+
EOS
|
46
|
+
end
|
47
|
+
break
|
48
|
+
end
|
49
|
+
field = "[String]" if line.include?("array: true")
|
50
|
+
type, name = line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
|
51
|
+
field ||= type_check type
|
52
|
+
case name
|
53
|
+
when "user_id"
|
54
|
+
@user_exist = true
|
55
|
+
when /$*_id\z/
|
56
|
+
@relation_params << name
|
57
|
+
new_line.write " argument :#{name}, String, required: false\n"
|
58
|
+
when "created_at", "updated_at"
|
59
|
+
next
|
60
|
+
else
|
61
|
+
new_line.write " argument :#{name}, #{field}, required: false\n"
|
62
|
+
end
|
63
|
+
end
|
64
|
+
@on = true if table_check(line: line, class_name: class_name)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
@relation_params
|
69
|
+
end
|
70
|
+
|
71
|
+
def create_mutation_after_params class_name: "article", relation_params: []
|
72
|
+
return false if relation_params.empty?
|
73
|
+
file_path = "./app/graphql/mutations/#{class_name}/create_#{class_name}.rb"
|
74
|
+
relation_params.each do |params_name|
|
75
|
+
File.open(file_path, "a") do |new_line|
|
76
|
+
new_line.write " _, args[:#{params_name}] = SoulsApiSchema.from_global_id(args[:#{params_name}])\n"
|
77
|
+
end
|
78
|
+
end
|
79
|
+
true
|
80
|
+
end
|
81
|
+
|
82
|
+
def create_mutation_end class_name: "souls"
|
83
|
+
file_path = "./app/graphql/mutations/#{class_name}/create_#{class_name}.rb"
|
84
|
+
File.open(file_path, "a") do |new_line|
|
85
|
+
new_line.write <<~EOS
|
86
|
+
#{class_name} = ::#{class_name.camelize}.new args
|
87
|
+
if #{class_name}.save
|
88
|
+
{ #{class_name}_edge: { node: #{class_name} } }
|
89
|
+
else
|
90
|
+
{ error: #{class_name}.errors.full_messages }
|
91
|
+
end
|
92
|
+
rescue StandardError => error
|
93
|
+
GraphQL::ExecutionError.new error
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
EOS
|
99
|
+
end
|
100
|
+
file_path
|
101
|
+
end
|
102
|
+
|
103
|
+
## 2.Mutation - Update
|
104
|
+
def update_mutation_head class_name: "souls"
|
105
|
+
file_path = "./app/graphql/mutations/#{class_name}/update_#{class_name}.rb"
|
106
|
+
File.open(file_path, "w") do |new_line|
|
107
|
+
new_line.write <<~EOS
|
108
|
+
module Mutations
|
109
|
+
module #{class_name.camelize}
|
110
|
+
class Update#{class_name.camelize} < BaseMutation
|
111
|
+
field :#{class_name}_edge, Types::#{class_name.camelize}NodeType, null: false
|
112
|
+
|
113
|
+
argument :id, String, required: true
|
114
|
+
EOS
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
def update_mutation_params class_name: "souls"
|
119
|
+
file_path = "./app/graphql/mutations/#{class_name}/update_#{class_name}.rb"
|
120
|
+
path = "./db/schema.rb"
|
121
|
+
@on = false
|
122
|
+
@user_exist = false
|
123
|
+
@relation_params = []
|
124
|
+
File.open(file_path, "a") do |new_line|
|
125
|
+
File.open(path, "r") do |f|
|
126
|
+
f.each_line.with_index do |line, i|
|
127
|
+
if @on
|
128
|
+
if line.include?("end") || line.include?("t.index")
|
129
|
+
if @user_exist
|
130
|
+
new_line.write <<-EOS
|
131
|
+
|
132
|
+
def resolve **args
|
133
|
+
args[:user_id] = context[:user].id
|
134
|
+
_, args[:id] = SoulsApiSchema.from_global_id(args[:id])
|
135
|
+
EOS
|
136
|
+
else
|
137
|
+
new_line.write <<-EOS
|
138
|
+
|
139
|
+
def resolve **args
|
140
|
+
_, args[:id] = SoulsApiSchema.from_global_id(args[:id])
|
141
|
+
EOS
|
142
|
+
end
|
143
|
+
break
|
144
|
+
end
|
145
|
+
field = "[String]" if line.include?("array: true")
|
146
|
+
type, name = line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
|
147
|
+
field ||= type_check type
|
148
|
+
case name
|
149
|
+
when "user_id"
|
150
|
+
@user_exist = true
|
151
|
+
when /$*_id\z/
|
152
|
+
@relation_params << name
|
153
|
+
new_line.write " argument :#{name}, String, required: false\n"
|
154
|
+
when "created_at", "updated_at"
|
155
|
+
next
|
156
|
+
else
|
157
|
+
new_line.write " argument :#{name}, #{field}, required: false\n"
|
158
|
+
end
|
159
|
+
end
|
160
|
+
@on = true if table_check(line: line, class_name: class_name)
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
164
|
+
@relation_params
|
165
|
+
end
|
166
|
+
|
167
|
+
def update_mutation_after_params class_name: "article", relation_params: []
|
168
|
+
return false if relation_params.empty?
|
169
|
+
file_path = "./app/graphql/mutations/#{class_name}/update_#{class_name}.rb"
|
170
|
+
relation_params.each do |params_name|
|
171
|
+
File.open(file_path, "a") do |new_line|
|
172
|
+
new_line.write " _, args[:#{params_name}] = SoulsApiSchema.from_global_id(args[:#{params_name}])\n"
|
173
|
+
end
|
174
|
+
end
|
175
|
+
true
|
176
|
+
end
|
177
|
+
|
178
|
+
def update_mutation_end class_name: "souls"
|
179
|
+
file_path = "./app/graphql/mutations/#{class_name}/update_#{class_name}.rb"
|
180
|
+
File.open(file_path, "a") do |new_line|
|
181
|
+
new_line.write <<~EOS
|
182
|
+
#{class_name} = ::#{class_name.camelize}.find args[:id]
|
183
|
+
#{class_name}.update args
|
184
|
+
{ #{class_name}_edge: { node: ::#{class_name.camelize}.find(args[:id]) } }
|
185
|
+
rescue StandardError => error
|
186
|
+
GraphQL::ExecutionError.new error
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end
|
191
|
+
EOS
|
192
|
+
end
|
193
|
+
file_path
|
194
|
+
end
|
195
|
+
|
196
|
+
def update_mutation class_name: "souls"
|
197
|
+
update_mutation_head class_name: class_name
|
198
|
+
relation_params = update_mutation_params class_name: class_name
|
199
|
+
update_mutation_after_params class_name: class_name, relation_params: relation_params
|
200
|
+
update_mutation_end class_name: class_name
|
201
|
+
end
|
202
|
+
|
203
|
+
# 3. Mutation - Delete
|
204
|
+
def delete_mutation class_name: "souls"
|
205
|
+
file_path = "./app/graphql/mutations/#{class_name}/delete_#{class_name}.rb"
|
206
|
+
File.open(file_path, "w") do |f|
|
207
|
+
f.write <<~EOS
|
208
|
+
module Mutations
|
209
|
+
module #{class_name.camelize}
|
210
|
+
class Delete#{class_name.camelize} < BaseMutation
|
211
|
+
field :#{class_name}, Types::#{class_name.camelize}Type, null: false
|
212
|
+
argument :id, String, required: true
|
213
|
+
|
214
|
+
def resolve **args
|
215
|
+
_, data_id = SoulsApiSchema.from_global_id args[:id]
|
216
|
+
#{class_name} = ::#{class_name.camelize}.find data_id
|
217
|
+
#{class_name}.update(is_deleted: true)
|
218
|
+
{ #{class_name}: ::#{class_name.camelize}.find(data_id) }
|
219
|
+
rescue StandardError => error
|
220
|
+
GraphQL::ExecutionError.new error
|
221
|
+
end
|
222
|
+
end
|
223
|
+
end
|
224
|
+
end
|
225
|
+
EOS
|
226
|
+
end
|
227
|
+
file_path
|
228
|
+
end
|
229
|
+
|
230
|
+
# 4. Mutation - Destroy Delete
|
231
|
+
def destroy_delete_mutation class_name: "souls"
|
232
|
+
file_path = "./app/graphql/mutations/#{class_name}/destroy_delete_#{class_name}.rb"
|
233
|
+
File.open(file_path, "w") do |f|
|
234
|
+
f.write <<~EOS
|
235
|
+
module Mutations
|
236
|
+
module #{class_name.camelize}
|
237
|
+
class DestroyDelete#{class_name.camelize} < BaseMutation
|
238
|
+
field :#{class_name}, Types::#{class_name.camelize}Type, null: false
|
239
|
+
argument :id, String, required: true
|
240
|
+
|
241
|
+
def resolve **args
|
242
|
+
_, data_id = SoulsApiSchema.from_global_id args[:id]
|
243
|
+
#{class_name} = ::#{class_name.camelize}.find data_id
|
244
|
+
#{class_name}.destroy
|
245
|
+
{ #{class_name}: #{class_name} }
|
246
|
+
rescue StandardError => error
|
247
|
+
GraphQL::ExecutionError.new error
|
248
|
+
end
|
249
|
+
end
|
250
|
+
end
|
251
|
+
end
|
252
|
+
EOS
|
253
|
+
end
|
254
|
+
file_path
|
255
|
+
rescue StandardError => error
|
256
|
+
puts error
|
257
|
+
end
|
258
|
+
|
259
|
+
def mutation class_name: "souls"
|
260
|
+
singularized_class_name = class_name.singularize
|
261
|
+
|
262
|
+
create_mutation_head class_name: singularized_class_name
|
263
|
+
relation_params = create_mutation_params class_name: singularized_class_name
|
264
|
+
create_mutation_after_params class_name: singularized_class_name, relation_params: relation_params
|
265
|
+
[
|
266
|
+
create_mutation_end(class_name: singularized_class_name),
|
267
|
+
update_mutation(class_name: singularized_class_name),
|
268
|
+
delete_mutation(class_name: singularized_class_name),
|
269
|
+
destroy_delete_mutation(class_name: singularized_class_name)
|
270
|
+
]
|
271
|
+
rescue StandardError => error
|
272
|
+
puts error
|
273
|
+
end
|
274
|
+
end
|
275
|
+
end
|
276
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module Souls
|
2
|
+
module Generate
|
3
|
+
class << self
|
4
|
+
## Generate Policy
|
5
|
+
def policy class_name: "souls"
|
6
|
+
dir_name = "#{__dir__}/app/policies"
|
7
|
+
FileUtils.mkdir_p dir_name unless Dir.exist? dir_name
|
8
|
+
file_path = "#{dir_name}/#{class_name.singularize}_policy.rb"
|
9
|
+
File.open(file_path, "w") do |f|
|
10
|
+
f.write <<~EOS
|
11
|
+
class #{class_name.camelize}Policy < ApplicationPolicy
|
12
|
+
def show?
|
13
|
+
admin_permissions?
|
14
|
+
end
|
15
|
+
|
16
|
+
def index?
|
17
|
+
admin_permissions?
|
18
|
+
end
|
19
|
+
|
20
|
+
def create?
|
21
|
+
admin_permissions?
|
22
|
+
end
|
23
|
+
|
24
|
+
def update?
|
25
|
+
admin_permissions?
|
26
|
+
end
|
27
|
+
|
28
|
+
def delete?
|
29
|
+
admin_permissions?
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def staff_permissions?
|
35
|
+
@user.master? or @user.admin? or @user.staff?
|
36
|
+
end
|
37
|
+
|
38
|
+
def admin_permissions?
|
39
|
+
@user.master? or @user.admin?
|
40
|
+
end
|
41
|
+
end
|
42
|
+
EOS
|
43
|
+
end
|
44
|
+
file_path
|
45
|
+
rescue StandardError => error
|
46
|
+
puts "method error"
|
47
|
+
puts error.backtrace
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module Souls
|
2
|
+
module Generate
|
3
|
+
class << self
|
4
|
+
## Generate Query / Queries
|
5
|
+
def create_queries class_name: "souls"
|
6
|
+
file_path = "./app/graphql/queries/#{class_name.pluralize}.rb"
|
7
|
+
File.open(file_path, "w") do |f|
|
8
|
+
f.write <<~EOS
|
9
|
+
module Queries
|
10
|
+
class #{class_name.camelize.pluralize} < Queries::BaseQuery
|
11
|
+
type [Types::#{class_name.camelize}Type], null: false
|
12
|
+
|
13
|
+
def resolve
|
14
|
+
::#{class_name.camelize}.all
|
15
|
+
rescue StandardError => error
|
16
|
+
GraphQL::ExecutionError.new error
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
EOS
|
21
|
+
end
|
22
|
+
file_path
|
23
|
+
end
|
24
|
+
|
25
|
+
def create_query class_name: "souls"
|
26
|
+
file_path = "./app/graphql/queries/#{class_name}.rb"
|
27
|
+
File.open(file_path, "w") do |f|
|
28
|
+
f.write <<~EOS
|
29
|
+
module Queries
|
30
|
+
class #{class_name.camelize} < Queries::BaseQuery
|
31
|
+
type Types::#{class_name.camelize}Type, null: false
|
32
|
+
argument :id, String, required: true
|
33
|
+
|
34
|
+
def resolve **args
|
35
|
+
_, data_id = SoulsApiSchema.from_global_id args[:id]
|
36
|
+
::#{class_name.camelize}.find(data_id)
|
37
|
+
rescue StandardError => error
|
38
|
+
GraphQL::ExecutionError.new error
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
EOS
|
43
|
+
file_path
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def query class_name: "souls"
|
48
|
+
singularized_class_name = class_name.singularize
|
49
|
+
[
|
50
|
+
create_query(class_name: singularized_class_name),
|
51
|
+
create_queries(class_name: singularized_class_name)
|
52
|
+
]
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,153 @@
|
|
1
|
+
module Souls
|
2
|
+
module Generate
|
3
|
+
class << self
|
4
|
+
## Generate Resolver
|
5
|
+
def resolver_head class_name: "souls"
|
6
|
+
FileUtils.mkdir_p "./app/graphql/resolvers" unless Dir.exist? "./app/graphql/resolvers"
|
7
|
+
file_path = "./app/graphql/resolvers/#{class_name.singularize}_search.rb"
|
8
|
+
@relation_params = []
|
9
|
+
return ["Resolver already exist! #{file_path}"] if File.exist? file_path
|
10
|
+
File.open(file_path, "w") do |f|
|
11
|
+
f.write <<~EOS
|
12
|
+
module Resolvers
|
13
|
+
class #{class_name.camelize}Search < Base
|
14
|
+
include SearchObject.module(:graphql)
|
15
|
+
scope { ::#{class_name.camelize}.all }
|
16
|
+
type Types::#{class_name.camelize}Type.connection_type, null: false
|
17
|
+
description "Search #{class_name.camelize}"
|
18
|
+
|
19
|
+
class #{class_name.camelize}Filter < ::Types::BaseInputObject
|
20
|
+
argument :OR, [self], required: false
|
21
|
+
EOS
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def resolver_params class_name: "souls"
|
26
|
+
file_path = "./app/graphql/resolvers/#{class_name.singularize}_search.rb"
|
27
|
+
path = "./db/schema.rb"
|
28
|
+
@on = false
|
29
|
+
@user_exist = false
|
30
|
+
@relation_params = []
|
31
|
+
File.open(file_path, "a") do |new_line|
|
32
|
+
File.open(path, "r") do |f|
|
33
|
+
f.each_line.with_index do |line, i|
|
34
|
+
if @on
|
35
|
+
if line.include?("end") || line.include?("t.index")
|
36
|
+
break
|
37
|
+
end
|
38
|
+
field = "[String]" if line.include?("array: true")
|
39
|
+
type, name = get_type_and_name(line)
|
40
|
+
field ||= type_check type
|
41
|
+
case name
|
42
|
+
when "user_id"
|
43
|
+
@user_exist = true
|
44
|
+
when /$*_id\z/
|
45
|
+
@relation_params << name
|
46
|
+
new_line.write " argument :#{name}, String, required: false\n"
|
47
|
+
when "created_at", "updated_at"
|
48
|
+
next
|
49
|
+
else
|
50
|
+
new_line.write " argument :#{name}, #{field}, required: false\n"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
@on = true if table_check(line: line, class_name: class_name)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def resolver_after_params class_name: "souls"
|
60
|
+
file_path = "./app/graphql/resolvers/#{class_name.singularize}_search.rb"
|
61
|
+
File.open(file_path, "a") do |f|
|
62
|
+
f.write <<-EOS
|
63
|
+
argument :start_date, String, required: false
|
64
|
+
argument :end_date, String, required: false
|
65
|
+
end
|
66
|
+
|
67
|
+
option :filter, type: #{class_name.camelize}Filter, with: :apply_filter
|
68
|
+
option :first, type: types.Int, with: :apply_first
|
69
|
+
option :skip, type: types.Int, with: :apply_skip
|
70
|
+
|
71
|
+
def apply_filter(scope, value)
|
72
|
+
branches = normalize_filters(value).inject { |a, b| a.or(b) }
|
73
|
+
scope.merge branches
|
74
|
+
end
|
75
|
+
|
76
|
+
def normalize_filters(value, branches = [])
|
77
|
+
scope = ::#{class_name.camelize}.all
|
78
|
+
EOS
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def resolver_before_end class_name: "souls"
|
83
|
+
file_path = "./app/graphql/resolvers/#{class_name.singularize}_search.rb"
|
84
|
+
path = "./db/schema.rb"
|
85
|
+
@on = false
|
86
|
+
@user_exist = false
|
87
|
+
@relation_params = []
|
88
|
+
File.open(file_path, "a") do |new_line|
|
89
|
+
File.open(path, "r") do |f|
|
90
|
+
f.each_line.with_index do |line, i|
|
91
|
+
if @on
|
92
|
+
if line.include?("end") || line.include?("t.index")
|
93
|
+
break
|
94
|
+
end
|
95
|
+
type, name = get_type_and_name(line)
|
96
|
+
if line.include?("array: true")
|
97
|
+
new_line.write " scope = scope.where(\"#{name} @> ARRAY[?]::text[]\", value[:#{name}]) if value[:#{name}]\n"
|
98
|
+
next
|
99
|
+
end
|
100
|
+
case name
|
101
|
+
when "user_id"
|
102
|
+
@user_exist = true
|
103
|
+
when /$*_id\z/
|
104
|
+
@relation_params << name
|
105
|
+
new_line.write " scope = scope.where(#{name}: decode_global_key(value[:#{name}])) if value[:#{name}]\n"
|
106
|
+
when "created_at", "updated_at"
|
107
|
+
next
|
108
|
+
else
|
109
|
+
case type
|
110
|
+
when "boolean"
|
111
|
+
new_line.write " scope = scope.where(#{name}: value[:#{name}]) unless value[:#{name}].nil?\n"
|
112
|
+
else
|
113
|
+
new_line.write " scope = scope.where(#{name}: value[:#{name}]) if value[:#{name}]\n"
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
@on = true if table_check(line: line, class_name: class_name)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
def resolver_end class_name: "souls"
|
124
|
+
file_path = "./app/graphql/resolvers/#{class_name.singularize}_search.rb"
|
125
|
+
File.open(file_path, "a") do |f|
|
126
|
+
f.write <<~EOS
|
127
|
+
scope = scope.where("created_at >= ?", value[:start_date]) if value[:start_date]
|
128
|
+
scope = scope.where("created_at <= ?", value[:end_date]) if value[:end_date]
|
129
|
+
#{' '}
|
130
|
+
branches << scope
|
131
|
+
#{' '}
|
132
|
+
value[:OR].inject(branches) { |s, v| normalize_filters(v, s) } if value[:OR].present?
|
133
|
+
#{' '}
|
134
|
+
branches
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
EOS
|
139
|
+
end
|
140
|
+
file_path
|
141
|
+
end
|
142
|
+
|
143
|
+
def resolver class_name: "souls"
|
144
|
+
singularized_class_name = class_name.singularize.underscore
|
145
|
+
resolver_head class_name: singularized_class_name
|
146
|
+
resolver_params class_name: singularized_class_name
|
147
|
+
resolver_after_params class_name: singularized_class_name
|
148
|
+
resolver_before_end class_name: singularized_class_name
|
149
|
+
resolver_end class_name: singularized_class_name
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|