souls 0.16.4 → 0.16.9

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0a95c2f58d01aa07cecc588a0c9beba4bbce457bd48c45975dc3b5a071a0ee80
4
- data.tar.gz: 48959daa9836b8175871e8320acefae6c382e4ec266ca301fd27974175abc4ec
3
+ metadata.gz: e03fb6575c0bc3b27aefb06271fa7c0bb6918f6e02b149e27122bed7cb36bb82
4
+ data.tar.gz: 5f834aa5e01aa7eb295e22a25bd46e24449e842f912c6b4072cd20c3055cba42
5
5
  SHA512:
6
- metadata.gz: e8d533843c23355c65d6b2b32f433c04259a34aa83aa04d152f0a2e8d5b216474f676cec996a156b8d370c36739e80a41ead964884b2d4f3b06644ac914531fc
7
- data.tar.gz: eef3ca623bc05f8b0577073f928f0a649957dc92ffb263b87c6eb3ce53b9f92cd03d46e97e9903e9370726419843587ffae30039d84210fcc72e9d1d76713f60
6
+ metadata.gz: 889facdd951bec4e5697c3d8454ca0de04d5ab16d0d178a75f8e79e0a8d3bb01d26bb8dda9ff9d85dec07c0cbbd4b2c9365a8d2e4fbd0bbb1ed808e129b49377
7
+ data.tar.gz: 4823330b6923de3548872f399de7eb4632e11190e8e431583f483dbcd964a80beb2ff5d70a610667572e14d35b9315f835b29ea4bf42028296ab9ef8da097f1d
data/.rubocop.yml CHANGED
@@ -79,6 +79,7 @@ Style/HashSyntax:
79
79
  - "**/*.rake"
80
80
  - "Rakefile"
81
81
 
82
+
82
83
  Style/IfUnlessModifier:
83
84
  Enabled: false
84
85
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- souls (0.16.4)
4
+ souls (0.16.7)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/exe/souls CHANGED
@@ -33,7 +33,12 @@ begin
33
33
  when "media", "admin"
34
34
  system "yarn dev"
35
35
  else
36
- system "bundle exec irb"
36
+ case ARGV[1]
37
+ when "RACK_ENV=production"
38
+ system "bundle exec irb RACK_ENV=production"
39
+ else
40
+ system "bundle exec irb"
41
+ end
37
42
  end
38
43
  when "i", "infra"
39
44
  Souls.send ARGV[1]
@@ -43,6 +48,21 @@ begin
43
48
  Souls::Init.config_init
44
49
  when "-v", "--version"
45
50
  puts Souls::VERSION
51
+ when "add"
52
+ case ARGV[1]
53
+ when "mutation"
54
+ Souls::Init.add_mutation class_name: "user", file_name: "hoi"
55
+ when "type"
56
+ Souls::Init.add_type class_name: "user", file_name: "hoi"
57
+ when "connection"
58
+ Souls::Init.add_connection class_name: "user", file_name: "hoi"
59
+ when "edge"
60
+ Souls::Init.add_edge class_name: "user", file_name: "hoi"
61
+ when "rspec_mutation"
62
+ Souls::Init.add_rspec_mutation class_name: "user", file_name: "hoi"
63
+ else
64
+ puts "HOI!"
65
+ end
46
66
  when "g", "generate"
47
67
  case ARGV[1]
48
68
  when "test_dir"
@@ -87,7 +107,12 @@ begin
87
107
  when "db:create"
88
108
  system "rake db:create && rake db:create RACK_ENV=test"
89
109
  when "db:migrate"
90
- system "rake db:migrate && rake db:migrate RACK_ENV=test"
110
+ case ARGV[1]
111
+ when "RACK_ENV=production"
112
+ system "rake db:migrate RACK_ENV=production"
113
+ else
114
+ system "rake db:migrate && rake db:migrate RACK_ENV=test"
115
+ end
91
116
  when "db:seed"
92
117
  system "rake db:seed"
93
118
  when "db:migrate:reset"
@@ -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,63 +35,143 @@ 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
54
+ end
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"
37
68
  end
69
+ end
70
+ @on = true if table_check(line: line, class_name: class_name)
71
+ end
72
+ end
73
+ end
74
+ end
38
75
 
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
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 :start_date, String, required: false
81
+ argument :end_date, String, required: false
82
+ end
42
83
 
43
- def apply_filter(scope, value)
44
- branches = normalize_filters(value).inject { |a, b| a.or(b) }
45
- scope.merge branches
46
- end
84
+ option :filter, type: #{class_name.camelize}Filter, with: :apply_filter
85
+ option :first, type: types.Int, with: :apply_first
86
+ option :skip, type: types.Int, with: :apply_skip
47
87
 
48
- def apply_first(scope, value)
49
- scope.limit(value)
50
- end
88
+ def apply_filter(scope, value)
89
+ branches = normalize_filters(value).inject { |a, b| a.or(b) }
90
+ scope.merge branches
91
+ end
51
92
 
52
- def apply_skip(scope, value)
53
- scope.offset(value)
54
- end
93
+ def normalize_filters(value, branches = [])
94
+ scope = ::#{class_name.camelize}.all
95
+ EOS
96
+ end
97
+ end
55
98
 
56
- def decode_global_key id
57
- _, data_id = SoulsApiSchema.from_global_id id
58
- data_id
99
+ def resolver_before_end class_name: "souls"
100
+ file_path = "./app/graphql/resolvers/#{class_name.singularize}_search.rb"
101
+ path = "./db/schema.rb"
102
+ @on = false
103
+ @user_exist = false
104
+ @relation_params = []
105
+ File.open(file_path, "a") do |new_line|
106
+ File.open(path, "r") do |f|
107
+ f.each_line.with_index do |line, i|
108
+ if @on
109
+ if line.include?("end") || line.include?("t.index")
110
+ break
59
111
  end
112
+ type, name = get_type_and_name(line)
113
+ if line.include?("array: true")
114
+ new_line.write " scope = scope.where(\"#{name} @> ARRAY[?]::text[]\", value[:#{name}]) if value[:#{name}]\n"
115
+ next
116
+ end
117
+ case name
118
+ when "user_id"
119
+ @user_exist = true
120
+ when /$*_id\z/
121
+ @relation_params << name
122
+ new_line.write " scope = scope.where(#{name}: decode_global_key(value[:#{name}])) if value[:#{name}]\n"
123
+ when "created_at", "updated_at"
124
+ next
125
+ else
126
+ case type
127
+ when "boolean"
128
+ new_line.write " scope = scope.where(#{name}: value[:#{name}]) unless value[:#{name}].nil?\n"
129
+ else
130
+ new_line.write " scope = scope.where(#{name}: value[:#{name}]) if value[:#{name}]\n"
131
+ end
132
+ end
133
+ end
134
+ @on = true if table_check(line: line, class_name: class_name)
135
+ end
136
+ end
137
+ end
138
+ end
60
139
 
61
- def normalize_filters(value, branches = [])
62
- scope = ::#{class_name.camelize}.all
63
-
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]
140
+ def resolver_end class_name: "souls"
141
+ file_path = "./app/graphql/resolvers/#{class_name.singularize}_search.rb"
142
+ File.open(file_path, "a") do |f|
143
+ f.write <<-EOS
144
+ scope = scope.where("created_at >= ?", value[:start_date]) if value[:start_date]
145
+ scope = scope.where("created_at <= ?", value[:end_date]) if value[:end_date]
67
146
 
68
- branches << scope
147
+ branches << scope
69
148
 
70
- value[:OR].inject(branches) { |s, v| normalize_filters(v, s) } if value[:OR].present?
149
+ value[:OR].inject(branches) { |s, v| normalize_filters(v, s) } if value[:OR].present?
71
150
 
72
- branches
73
- end
74
- end
75
- end
151
+ branches
152
+ end
153
+ end
154
+ end
76
155
  EOS
77
156
  end
78
157
  [file_path]
79
158
  end
80
159
 
160
+ def resolver class_name: "souls"
161
+ singularized_class_name = class_name.singularize.underscore
162
+ resolver_head class_name: singularized_class_name
163
+ resolver_params class_name: singularized_class_name
164
+ resolver_after_params class_name: singularized_class_name
165
+ resolver_before_end class_name: singularized_class_name
166
+ resolver_end class_name: singularized_class_name
167
+ end
168
+
81
169
  def job class_name: "send_mail"
82
170
  file_path = "./app/jobs/#{class_name.singularize}_job.rb"
83
171
  return ["Job already exist! #{file_path}"] if File.exist? file_path
84
172
  File.open(file_path, "w") do |f|
85
173
  f.write <<~EOS
86
174
  class #{class_name.camelize}
87
- include Sidekiq::Status::Worker
88
- include Sidekiq::Worker
89
- sidekiq_options queue: "default"
90
175
 
91
176
  def perform **args
92
177
  # write task code here
@@ -300,6 +385,36 @@ end
300
385
  rescue StandardError => error
301
386
  puts error
302
387
  end
388
+
389
+ def add_mutation class_name: "souls", file_name: "hoi"
390
+ singularized_class_name = class_name.singularize.underscore
391
+ file_path = "./app/graphql/mutations/#{singularized_class_name}/#{file_name}.rb"
392
+ file_path
393
+ end
394
+
395
+ def add_type class_name: "souls", file_name: "hoi"
396
+ singularized_class_name = class_name.singularize.underscore
397
+ file_path = "./app/graphql/types/#{file_name}.rb"
398
+ file_path
399
+ end
400
+
401
+ def add_edge class_name: "souls", file_name: "hoi"
402
+ singularized_class_name = class_name.singularize.underscore
403
+ file_path = "./app/graphql/types/#{file_name}.rb"
404
+ file_path
405
+ end
406
+
407
+ def add_connection class_name: "souls", file_name: "hoi"
408
+ singularized_class_name = class_name.singularize.underscore
409
+ file_path = "./app/graphql/types/#{file_name}.rb"
410
+ file_path
411
+ end
412
+
413
+ def add_rspec_mutation class_name: "souls", file_name: "hoi"
414
+ singularized_class_name = class_name.singularize.underscore
415
+ file_path = "./app/graphql/types/#{file_name}.rb"
416
+ file_path
417
+ end
303
418
  end
304
419
  end
305
420
  end
data/lib/souls/init.rb CHANGED
@@ -780,10 +780,6 @@ module Souls
780
780
  EOS
781
781
  else
782
782
  new_line.write <<-EOS
783
-
784
- def get_global_key class_name, id
785
- Base64.encode64(\"\#{class_name}:\#{id}\")
786
- end
787
783
  let(:#{class_name}) { FactoryBot.attributes_for(:#{class_name}, #{@relation_params.join(", ")}) }
788
784
 
789
785
  let(:mutation) do
data/lib/souls/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Souls
2
- VERSION = "0.16.4"
2
+ VERSION = "0.16.9"
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.4
4
+ version: 0.16.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - POPPIN-FUMI
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: exe
12
12
  cert_chain: []
13
- date: 2021-03-01 00:00:00.000000000 Z
13
+ date: 2021-03-13 00:00:00.000000000 Z
14
14
  dependencies: []
15
15
  description: SOULS is a Web Application Framework for Microservices on Multi Cloud
16
16
  Platform such as Google Cloud Platform, Amazon Web Services, and Alibaba Cloud.
@@ -70,7 +70,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
70
70
  - !ruby/object:Gem::Version
71
71
  version: '0'
72
72
  requirements: []
73
- rubygems_version: 3.2.3
73
+ rubygems_version: 3.2.4
74
74
  signing_key:
75
75
  specification_version: 4
76
76
  summary: SOULS is a GraphQL Based Web Application Framework for Microservices on Multi