souls 0.16.5 → 0.16.6
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/.rubocop.yml +3 -0
- data/Gemfile.lock +1 -1
- data/lib/souls/generate.rb +128 -30
- data/lib/souls/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a327229d00231e3a106e8dd748d083b4fe4a5bc776960144b2eeeed15c0a5a4b
|
4
|
+
data.tar.gz: 6fc169ee068d88ac46f2673bd48d89c2e1afb4bfbf75a753a357fe2615166454
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 05e475df2a78f94bfa8a3f55441ca563d30b17e7ef6c5c4b5bc39f95a4633864ea785f6b07d798667f6022980ab1bfa0d05f160f0c3a35d5b94444a8b2a46d44
|
7
|
+
data.tar.gz: 20b59cdf504c52fb19154f2fb9a89951f0220c0ba1a9fa27c02ccec2b32a2abf5946c253634427a699bcc3a5633f5e1016e21cd4971c3e214a8121c897a2f29e
|
data/.rubocop.yml
CHANGED
data/Gemfile.lock
CHANGED
data/lib/souls/generate.rb
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
module Souls
|
2
2
|
module Init
|
3
3
|
class << self
|
4
|
+
def get_type_and_name line
|
5
|
+
line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
|
6
|
+
end
|
7
|
+
|
4
8
|
def node_type class_name: "souls"
|
5
9
|
file_path = "./app/graphql/types/#{class_name.singularize}_node_type.rb"
|
6
10
|
File.open(file_path, "w") do |f|
|
@@ -15,9 +19,10 @@ module Souls
|
|
15
19
|
[file_path]
|
16
20
|
end
|
17
21
|
|
18
|
-
def
|
22
|
+
def resolver_head class_name: "souls"
|
19
23
|
FileUtils.mkdir_p "./app/graphql/resolvers" unless Dir.exist? "./app/graphql/resolvers"
|
20
24
|
file_path = "./app/graphql/resolvers/#{class_name.singularize}_search.rb"
|
25
|
+
@relation_params = []
|
21
26
|
return ["Resolver already exist! #{file_path}"] if File.exist? file_path
|
22
27
|
File.open(file_path, "w") do |f|
|
23
28
|
f.write <<~EOS
|
@@ -30,54 +35,147 @@ module Souls
|
|
30
35
|
|
31
36
|
class #{class_name.camelize}Filter < ::Types::BaseInputObject
|
32
37
|
argument :OR, [self], required: false
|
38
|
+
EOS
|
39
|
+
end
|
40
|
+
end
|
33
41
|
|
34
|
-
|
35
|
-
|
36
|
-
|
42
|
+
def resolver_params class_name: "souls"
|
43
|
+
file_path = "./app/graphql/resolvers/#{class_name.singularize}_search.rb"
|
44
|
+
path = "./db/schema.rb"
|
45
|
+
@on = false
|
46
|
+
@user_exist = false
|
47
|
+
@relation_params = []
|
48
|
+
File.open(file_path, "a") do |new_line|
|
49
|
+
File.open(path, "r") do |f|
|
50
|
+
f.each_line.with_index do |line, i|
|
51
|
+
if @on
|
52
|
+
if line.include?("end") || line.include?("t.index")
|
53
|
+
break
|
37
54
|
end
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
55
|
+
field = "[String]" if line.include?("array: true")
|
56
|
+
type, name = get_type_and_name(line)
|
57
|
+
field ||= type_check type
|
58
|
+
case name
|
59
|
+
when "user_id"
|
60
|
+
@user_exist = true
|
61
|
+
when /$*_id\z/
|
62
|
+
@relation_params << name
|
63
|
+
new_line.write " argument :#{name}, String, required: false\n"
|
64
|
+
when "created_at", "updated_at"
|
65
|
+
next
|
66
|
+
else
|
67
|
+
new_line.write " argument :#{name}, #{field}, required: false\n"
|
46
68
|
end
|
69
|
+
end
|
70
|
+
@on = true if table_check(line: line, class_name: class_name)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
47
75
|
|
48
|
-
|
49
|
-
|
50
|
-
|
76
|
+
def resolver_after_params class_name: "souls"
|
77
|
+
file_path = "./app/graphql/resolvers/#{class_name.singularize}_search.rb"
|
78
|
+
File.open(file_path, "a") do |f|
|
79
|
+
f.write <<-EOS
|
80
|
+
argument :is_deleted, Boolean, required: false
|
81
|
+
argument :start_date, String, required: false
|
82
|
+
argument :end_date, String, required: false
|
83
|
+
end
|
51
84
|
|
52
|
-
|
53
|
-
|
54
|
-
|
85
|
+
option :filter, type: #{class_name.camelize}Filter, with: :apply_filter
|
86
|
+
option :first, type: types.Int, with: :apply_first
|
87
|
+
option :skip, type: types.Int, with: :apply_skip
|
55
88
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
89
|
+
def apply_filter(scope, value)
|
90
|
+
branches = normalize_filters(value).inject { |a, b| a.or(b) }
|
91
|
+
scope.merge branches
|
92
|
+
end
|
60
93
|
|
61
|
-
|
62
|
-
|
94
|
+
def apply_first(scope, value)
|
95
|
+
scope.limit(value)
|
96
|
+
end
|
63
97
|
|
64
|
-
|
65
|
-
|
66
|
-
|
98
|
+
def apply_skip(scope, value)
|
99
|
+
scope.offset(value)
|
100
|
+
end
|
67
101
|
|
68
|
-
|
102
|
+
def decode_global_key id
|
103
|
+
_, data_id = SoulsApiSchema.from_global_id id
|
104
|
+
data_id
|
105
|
+
end
|
69
106
|
|
70
|
-
|
107
|
+
def normalize_filters(value, branches = [])
|
108
|
+
scope = ::#{class_name.camelize}.all
|
109
|
+
EOS
|
110
|
+
end
|
111
|
+
end
|
71
112
|
|
72
|
-
|
113
|
+
def resolver_before_end class_name: "souls"
|
114
|
+
file_path = "./app/graphql/resolvers/#{class_name.singularize}_search.rb"
|
115
|
+
path = "./db/schema.rb"
|
116
|
+
@on = false
|
117
|
+
@user_exist = false
|
118
|
+
@relation_params = []
|
119
|
+
File.open(file_path, "a") do |new_line|
|
120
|
+
File.open(path, "r") do |f|
|
121
|
+
f.each_line.with_index do |line, i|
|
122
|
+
if @on
|
123
|
+
if line.include?("end") || line.include?("t.index")
|
124
|
+
break
|
125
|
+
end
|
126
|
+
_, name = get_type_and_name(line)
|
127
|
+
if line.include?("array: true")
|
128
|
+
new_line.write " scope = scope.where(\"#{name} @> ARRAY[?]::text[]\", value[:#{name}]) if value[:#{name}]\n"
|
129
|
+
next
|
130
|
+
end
|
131
|
+
case name
|
132
|
+
when "user_id"
|
133
|
+
@user_exist = true
|
134
|
+
when /$*_id\z/
|
135
|
+
@relation_params << name
|
136
|
+
new_line.write " scope = scope.where(#{name}: decode_global_key(value[:#{name}])) if value[:#{name}]\n"
|
137
|
+
when "created_at", "updated_at"
|
138
|
+
next
|
139
|
+
else
|
140
|
+
new_line.write " scope = scope.where(#{name}: value[:#{name}]) if value[:#{name}]\n"
|
73
141
|
end
|
74
142
|
end
|
143
|
+
@on = true if table_check(line: line, class_name: class_name)
|
75
144
|
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
def resolver_end class_name: "souls"
|
150
|
+
file_path = "./app/graphql/resolvers/#{class_name.singularize}_search.rb"
|
151
|
+
File.open(file_path, "a") do |f|
|
152
|
+
f.write <<-EOS
|
153
|
+
scope = scope.where(is_deleted: value[:is_deleted]) if value[:is_deleted]
|
154
|
+
scope = scope.where("created_at >= ?", value[:start_date]) if value[:start_date]
|
155
|
+
scope = scope.where("created_at <= ?", value[:end_date]) if value[:end_date]
|
156
|
+
|
157
|
+
branches << scope
|
158
|
+
|
159
|
+
value[:OR].inject(branches) { |s, v| normalize_filters(v, s) } if value[:OR].present?
|
160
|
+
|
161
|
+
branches
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
76
165
|
EOS
|
77
166
|
end
|
78
167
|
[file_path]
|
79
168
|
end
|
80
169
|
|
170
|
+
def resolver class_name: "souls"
|
171
|
+
singularized_class_name = class_name.singularize.underscore
|
172
|
+
resolver_head class_name: singularized_class_name
|
173
|
+
resolver_params class_name: singularized_class_name
|
174
|
+
resolver_after_params class_name: singularized_class_name
|
175
|
+
resolver_before_end class_name: singularized_class_name
|
176
|
+
resolver_end class_name: singularized_class_name
|
177
|
+
end
|
178
|
+
|
81
179
|
def job class_name: "send_mail"
|
82
180
|
file_path = "./app/jobs/#{class_name.singularize}_job.rb"
|
83
181
|
return ["Job already exist! #{file_path}"] if File.exist? file_path
|
data/lib/souls/version.rb
CHANGED