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