souls 0.16.5 → 0.16.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ecbbcfd268702626603691c3b4e206e3787c2b3a52db1c130d7d36cbb039b513
4
- data.tar.gz: 761fd5f0a11eb5101f41c2cec69d0e3b8ffb6647e09c4bae308ae54ab8c5103e
3
+ metadata.gz: a327229d00231e3a106e8dd748d083b4fe4a5bc776960144b2eeeed15c0a5a4b
4
+ data.tar.gz: 6fc169ee068d88ac46f2673bd48d89c2e1afb4bfbf75a753a357fe2615166454
5
5
  SHA512:
6
- metadata.gz: 4ba3b4de41c6e00bfe330f0a84654a4cf033219a8a3b1a7ce81406a2ec0107a30b4df8b218e70dc02f454dad0a9526ccc9a10d3f1bf0ef32527b3c4b41c4d4ee
7
- data.tar.gz: 5af9857415389ae10597b7111063bc4166d8ab337a8ef4e4bb2a25f3f932dca88d6bebfbd3bf4e94861790f11c8a2642efc66e6d04d8388d78f4bfc5c6f37e78
6
+ metadata.gz: 05e475df2a78f94bfa8a3f55441ca563d30b17e7ef6c5c4b5bc39f95a4633864ea785f6b07d798667f6022980ab1bfa0d05f160f0c3a35d5b94444a8b2a46d44
7
+ data.tar.gz: 20b59cdf504c52fb19154f2fb9a89951f0220c0ba1a9fa27c02ccec2b32a2abf5946c253634427a699bcc3a5633f5e1016e21cd4971c3e214a8121c897a2f29e
data/.rubocop.yml CHANGED
@@ -79,6 +79,9 @@ Style/HashSyntax:
79
79
  - "**/*.rake"
80
80
  - "Rakefile"
81
81
 
82
+ Layout/HeredocIndentation:
83
+ Enabled: false
84
+
82
85
  Style/IfUnlessModifier:
83
86
  Enabled: false
84
87
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- souls (0.16.5)
4
+ souls (0.16.6)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -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 resolver class_name: "souls"
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
- argument :is_deleted, Boolean, required: false
35
- argument :start_date, String, required: false
36
- argument :end_date, String, required: false
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
- option :filter, type: #{class_name.camelize}Filter, with: :apply_filter
40
- option :first, type: types.Int, with: :apply_first
41
- option :skip, type: types.Int, with: :apply_skip
42
-
43
- def apply_filter(scope, value)
44
- branches = normalize_filters(value).inject { |a, b| a.or(b) }
45
- scope.merge branches
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
- def apply_first(scope, value)
49
- scope.limit(value)
50
- end
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
- def apply_skip(scope, value)
53
- scope.offset(value)
54
- end
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
- def decode_global_key id
57
- _, data_id = SoulsApiSchema.from_global_id id
58
- data_id
59
- end
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
- def normalize_filters(value, branches = [])
62
- scope = ::#{class_name.camelize}.all
94
+ def apply_first(scope, value)
95
+ scope.limit(value)
96
+ end
63
97
 
64
- scope = scope.where(is_deleted: value[:is_deleted]) if value[:is_deleted]
65
- scope = scope.where("created_at >= ?", value[:start_date]) if value[:start_date]
66
- scope = scope.where("created_at <= ?", value[:end_date]) if value[:end_date]
98
+ def apply_skip(scope, value)
99
+ scope.offset(value)
100
+ end
67
101
 
68
- branches << scope
102
+ def decode_global_key id
103
+ _, data_id = SoulsApiSchema.from_global_id id
104
+ data_id
105
+ end
69
106
 
70
- value[:OR].inject(branches) { |s, v| normalize_filters(v, s) } if value[:OR].present?
107
+ def normalize_filters(value, branches = [])
108
+ scope = ::#{class_name.camelize}.all
109
+ EOS
110
+ end
111
+ end
71
112
 
72
- branches
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
@@ -1,3 +1,3 @@
1
1
  module Souls
2
- VERSION = "0.16.5"
2
+ VERSION = "0.16.6"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: souls
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.16.5
4
+ version: 0.16.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - POPPIN-FUMI