souls 0.14.3 → 0.14.8
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/Gemfile +1 -1
- data/Gemfile.lock +2 -2
- data/exe/souls +12 -2
- data/lib/souls.rb +1 -0
- data/lib/souls/generate.rb +98 -0
- data/lib/souls/init.rb +55 -14
- data/lib/souls/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 804fd65fe81c6419e3375ccd10cf74b25d6bdcb5e8d2aca7e3b89a3ad5312c42
|
4
|
+
data.tar.gz: 0b52eea2c5519ced9176e0c0004816cbd7b4e899e6b8c694ec8b2477455179b1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0eed1e0504165176a740e77e3d9d0b08154582b5b1aee47a11100d19edfa029002902870028bc669323d748645fbacadb627d92ee79933b3188f2cd813ade606
|
7
|
+
data.tar.gz: 6fcf0db4532e3a59b787e0c673522d2d2ca43e5bda3638799968e86b7664c95c21c2eb391aabbfff14cbb2ad8a4cd9ea89d885f2687824b1fd2a216147c09680
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
souls (0.14.
|
4
|
+
souls (0.14.7)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
@@ -19,7 +19,7 @@ GEM
|
|
19
19
|
concurrent-ruby (1.1.8)
|
20
20
|
diff-lcs (1.4.4)
|
21
21
|
ffi (1.14.2)
|
22
|
-
i18n (1.8.
|
22
|
+
i18n (1.8.8)
|
23
23
|
concurrent-ruby (~> 1.0)
|
24
24
|
language_server-protocol (3.15.0.1)
|
25
25
|
listen (3.4.1)
|
data/exe/souls
CHANGED
@@ -48,7 +48,11 @@ begin
|
|
48
48
|
when "test_dir"
|
49
49
|
Souls::Init.test_dir
|
50
50
|
when "test"
|
51
|
-
Souls::Init.
|
51
|
+
Souls::Init.node_type class_name: "user"
|
52
|
+
when "resolver"
|
53
|
+
Souls::Init.resolver class_name: "user"
|
54
|
+
when "job"
|
55
|
+
Souls::Init.job class_name: "user"
|
52
56
|
when "model"
|
53
57
|
Souls::Init.model class_name: ARGV[2]
|
54
58
|
when "mutation"
|
@@ -62,7 +66,7 @@ begin
|
|
62
66
|
when "migrate_all"
|
63
67
|
Souls::Init.migrate_all
|
64
68
|
when "migration"
|
65
|
-
`rake db:create_migration NAME=#{ARGV[
|
69
|
+
`rake db:create_migration NAME=#{ARGV[2]}`
|
66
70
|
when "rspec_factory"
|
67
71
|
Souls::Init.rspec_factory class_name: ARGV[2]
|
68
72
|
when "rspec_model"
|
@@ -76,6 +80,12 @@ begin
|
|
76
80
|
else
|
77
81
|
"SOULs!"
|
78
82
|
end
|
83
|
+
when "db:create"
|
84
|
+
`rake db:create && rake db:create RACK_ENV=test`
|
85
|
+
when "db:migrate"
|
86
|
+
`rake db:migrate && rake db:migrate RACK_ENV=test`
|
87
|
+
when "db:migrate:reset"
|
88
|
+
`rake db:migrate:reset && rake db:migrate:reset RACK_ENV=test`
|
79
89
|
when "t", "test"
|
80
90
|
`rubocop`
|
81
91
|
`bundle exec rspec`
|
data/lib/souls.rb
CHANGED
@@ -0,0 +1,98 @@
|
|
1
|
+
module Souls
|
2
|
+
module Init
|
3
|
+
class << self
|
4
|
+
def node_type class_name: "souls"
|
5
|
+
file_path = "./app/graphql/types/#{class_name.singularize}_node_type.rb"
|
6
|
+
File.open(file_path, "w") do |f|
|
7
|
+
f.write <<~EOS
|
8
|
+
module Types
|
9
|
+
class #{class_name.camelize}NodeType < GraphQL::Schema::Object
|
10
|
+
field :node, Types::#{class_name.camelize}, null: true
|
11
|
+
end
|
12
|
+
end
|
13
|
+
EOS
|
14
|
+
end
|
15
|
+
[file_path]
|
16
|
+
end
|
17
|
+
|
18
|
+
def resolver class_name: "souls"
|
19
|
+
FileUtils.mkdir_p "./app/graphql/resolvers" unless Dir.exist? "./app/graphql/resolvers"
|
20
|
+
file_path = "./app/graphql/resolvers/#{class_name.singularize}_search.rb"
|
21
|
+
File.open(file_path, "w") do |f|
|
22
|
+
f.write <<~EOS
|
23
|
+
module Resolvers
|
24
|
+
class #{class_name.camelize}Search < Base
|
25
|
+
include SearchObject.module(:graphql)
|
26
|
+
scope { ::#{class_name.camelize}.all }
|
27
|
+
type Types::#{class_name.camelize}Type.connection_type, null: false
|
28
|
+
description "Search #{class_name.camelize}"
|
29
|
+
|
30
|
+
class #{class_name.camelize}Filter < ::Types::BaseInputObject
|
31
|
+
argument :OR, [self], required: false
|
32
|
+
|
33
|
+
argument :start_date, String, required: false
|
34
|
+
argument :end_date, String, required: false
|
35
|
+
end
|
36
|
+
|
37
|
+
option :filter, type: #{class_name.camelize}Filter, with: :apply_filter
|
38
|
+
option :first, type: types.Int, with: :apply_first
|
39
|
+
option :skip, type: types.Int, with: :apply_skip
|
40
|
+
|
41
|
+
def apply_filter(scope, value)
|
42
|
+
branches = normalize_filters(value).inject { |a, b| a.or(b) }
|
43
|
+
scope.merge branches
|
44
|
+
end
|
45
|
+
|
46
|
+
def apply_first(scope, value)
|
47
|
+
scope.limit(value)
|
48
|
+
end
|
49
|
+
|
50
|
+
def apply_skip(scope, value)
|
51
|
+
scope.offset(value)
|
52
|
+
end
|
53
|
+
|
54
|
+
def decode_global_key id
|
55
|
+
_, data_id = SoulsApiSchema.from_global_id id
|
56
|
+
data_id
|
57
|
+
end
|
58
|
+
|
59
|
+
def normalize_filters(value, branches = [])
|
60
|
+
scope = ::Article.all
|
61
|
+
|
62
|
+
scope = scope.where("created_at >= ?", value[:start_date]) if value[:start_date]
|
63
|
+
scope = scope.where("created_at <= ?", value[:end_date]) if value[:end_date]
|
64
|
+
|
65
|
+
branches << scope
|
66
|
+
|
67
|
+
value[:OR].inject(branches) { |s, v| normalize_filters(v, s) } if value[:OR].present?
|
68
|
+
|
69
|
+
branches
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
EOS
|
74
|
+
end
|
75
|
+
[file_path]
|
76
|
+
end
|
77
|
+
|
78
|
+
def job class_name: "send_mail"
|
79
|
+
file_path = "./app/jobs/#{class_name.singularize}_job.rb"
|
80
|
+
File.open(file_path, "w") do |f|
|
81
|
+
f.write <<~EOS
|
82
|
+
class #{class_name.camelize}
|
83
|
+
include Sidekiq::Status::Worker
|
84
|
+
include Sidekiq::Worker
|
85
|
+
sidekiq_options queue: "default"
|
86
|
+
|
87
|
+
def perform **args
|
88
|
+
# write task code here
|
89
|
+
end
|
90
|
+
end
|
91
|
+
EOS
|
92
|
+
end
|
93
|
+
[file_path]
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
data/lib/souls/init.rb
CHANGED
@@ -244,6 +244,7 @@ module Souls
|
|
244
244
|
|
245
245
|
def model class_name: "souls"
|
246
246
|
file_path = "./app/models/#{class_name.singularize}.rb"
|
247
|
+
return p("Model already exist! #{file_path}") if File.exist? file_path
|
247
248
|
File.open(file_path, "w") do |f|
|
248
249
|
f.write <<~EOS
|
249
250
|
class #{class_name.camelize} < ActiveRecord::Base
|
@@ -257,6 +258,9 @@ module Souls
|
|
257
258
|
FileUtils.mkdir_p "./app/graphql/mutations"
|
258
259
|
FileUtils.mkdir_p "./app/graphql/queries"
|
259
260
|
FileUtils.mkdir_p "./app/graphql/types"
|
261
|
+
FileUtils.mkdir_p "./app/graphql/resolvers"
|
262
|
+
FileUtils.mkdir_p "./app/jobs"
|
263
|
+
FileUtils.mkdir_p "./app/models"
|
260
264
|
FileUtils.mkdir_p "./spec/factories"
|
261
265
|
FileUtils.mkdir_p "./spec/queries"
|
262
266
|
FileUtils.mkdir_p "./spec/mutations"
|
@@ -300,13 +304,15 @@ module Souls
|
|
300
304
|
end
|
301
305
|
|
302
306
|
def create_mutation_head class_name: "souls"
|
307
|
+
dir_name = "./app/graphql/mutations/#{class_name}"
|
308
|
+
FileUtils.mkdir_p dir_name unless Dir.exist? dir_name
|
303
309
|
file_path = "./app/graphql/mutations/#{class_name}/create_#{class_name}.rb"
|
304
310
|
File.open(file_path, "w") do |new_line|
|
305
311
|
new_line.write <<~EOS
|
306
312
|
module Mutations
|
307
313
|
module #{class_name.camelize}
|
308
314
|
class Create#{class_name.camelize} < BaseMutation
|
309
|
-
field :#{class_name}, Types::#{class_name.camelize}
|
315
|
+
field :#{class_name}_edge, Types::#{class_name.camelize}NodeType, null: false
|
310
316
|
field :error, String, null: true
|
311
317
|
|
312
318
|
EOS
|
@@ -377,7 +383,7 @@ module Souls
|
|
377
383
|
new_line.write <<~EOS
|
378
384
|
#{class_name} = ::#{class_name.camelize}.new args
|
379
385
|
if #{class_name}.save
|
380
|
-
{ #{class_name}: #{class_name} }
|
386
|
+
{ #{class_name}_edge: { node: #{class_name} } }
|
381
387
|
else
|
382
388
|
{ error: #{class_name}.errors.full_messages }
|
383
389
|
end
|
@@ -399,7 +405,7 @@ module Souls
|
|
399
405
|
module Mutations
|
400
406
|
module #{class_name.camelize}
|
401
407
|
class Update#{class_name.camelize} < BaseMutation
|
402
|
-
field :#{class_name}, Types::#{class_name.camelize}
|
408
|
+
field :#{class_name}_edge, Types::#{class_name.camelize}NodeType, null: false
|
403
409
|
|
404
410
|
argument :id, String, required: true
|
405
411
|
EOS
|
@@ -472,7 +478,7 @@ module Souls
|
|
472
478
|
new_line.write <<~EOS
|
473
479
|
#{class_name} = ::#{class_name.camelize}.find args[:id]
|
474
480
|
#{class_name}.update args
|
475
|
-
{ #{class_name}: ::#{class_name.camelize}.find(args[:id]) }
|
481
|
+
{ #{class_name}_edge: { node: ::#{class_name.camelize}.find(args[:id]) } }
|
476
482
|
rescue StandardError => error
|
477
483
|
GraphQL::ExecutionError.new error
|
478
484
|
end
|
@@ -501,6 +507,32 @@ module Souls
|
|
501
507
|
field :#{class_name}, Types::#{class_name.camelize}Type, null: false
|
502
508
|
argument :id, String, required: true
|
503
509
|
|
510
|
+
def resolve **args
|
511
|
+
_, data_id = SoulsApiSchema.from_global_id args[:id]
|
512
|
+
#{class_name} = ::#{class_name.camelize}.find data_id
|
513
|
+
#{class_name}.update(is_deleted: true)
|
514
|
+
{ #{class_name}: ::#{class_name.camelize}.find(data_id) }
|
515
|
+
rescue StandardError => error
|
516
|
+
GraphQL::ExecutionError.new error
|
517
|
+
end
|
518
|
+
end
|
519
|
+
end
|
520
|
+
end
|
521
|
+
EOS
|
522
|
+
end
|
523
|
+
file_path
|
524
|
+
end
|
525
|
+
|
526
|
+
def destroy_delete_mutation class_name: "souls"
|
527
|
+
file_path = "./app/graphql/mutations/#{class_name}/destroy_delete_#{class_name}.rb"
|
528
|
+
File.open(file_path, "w") do |f|
|
529
|
+
f.write <<~EOS
|
530
|
+
module Mutations
|
531
|
+
module #{class_name.camelize}
|
532
|
+
class DestroyDelete#{class_name.camelize} < BaseMutation
|
533
|
+
field :#{class_name}, Types::#{class_name.camelize}Type, null: false
|
534
|
+
argument :id, String, required: true
|
535
|
+
|
504
536
|
def resolve **args
|
505
537
|
_, data_id = SoulsApiSchema.from_global_id args[:id]
|
506
538
|
#{class_name} = ::#{class_name.camelize}.find data_id
|
@@ -526,18 +558,15 @@ module Souls
|
|
526
558
|
|
527
559
|
def mutation class_name: "souls"
|
528
560
|
singularized_class_name = class_name.singularize
|
529
|
-
|
530
|
-
create_confirm dir_path: "./app/graphql/mutations/#{singularized_class_name}"
|
531
|
-
else
|
532
|
-
Dir.mkdir "./app/graphql/mutations/#{singularized_class_name}"
|
533
|
-
end
|
561
|
+
|
534
562
|
create_mutation_head class_name: singularized_class_name
|
535
563
|
relation_params = create_mutation_params class_name: singularized_class_name
|
536
564
|
create_mutation_after_params class_name: singularized_class_name, relation_params: relation_params
|
537
565
|
[
|
538
566
|
create_mutation_end(class_name: singularized_class_name),
|
539
567
|
update_mutation(class_name: singularized_class_name),
|
540
|
-
delete_mutation(class_name: singularized_class_name)
|
568
|
+
delete_mutation(class_name: singularized_class_name),
|
569
|
+
destroy_delete_mutation(class_name: singularized_class_name)
|
541
570
|
]
|
542
571
|
end
|
543
572
|
|
@@ -790,7 +819,8 @@ module Souls
|
|
790
819
|
f.each_line.with_index do |line, i|
|
791
820
|
if @on
|
792
821
|
if line.include?("end") || line.include?("t.index")
|
793
|
-
new_line.write " }) {\n #{class_name.singularize.camelize(:lower)} {\n
|
822
|
+
new_line.write " }) {\n #{class_name.singularize.camelize(:lower)}Edge {\n node {\n"
|
823
|
+
new_line.write " id\n"
|
794
824
|
break
|
795
825
|
end
|
796
826
|
type, name = line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
|
@@ -834,6 +864,7 @@ module Souls
|
|
834
864
|
if line.include?("end") || line.include?("t.index")
|
835
865
|
if @user_exist
|
836
866
|
new_line.write <<-EOS
|
867
|
+
}
|
837
868
|
}
|
838
869
|
}
|
839
870
|
}
|
@@ -848,7 +879,7 @@ module Souls
|
|
848
879
|
end
|
849
880
|
|
850
881
|
it "return #{class_name.camelize} Data" do
|
851
|
-
a1 = result.dig("data", "create#{class_name.singularize.camelize}", "#{class_name.singularize.camelize(:lower)}")
|
882
|
+
a1 = result.dig("data", "create#{class_name.singularize.camelize}", "#{class_name.singularize.camelize(:lower)}Edge", "node")
|
852
883
|
expect(a1).to include(
|
853
884
|
"id" => be_a(String),
|
854
885
|
EOS
|
@@ -865,7 +896,7 @@ module Souls
|
|
865
896
|
end
|
866
897
|
|
867
898
|
it "return #{class_name.camelize} Data" do
|
868
|
-
a1 = result.dig("data", "create#{class_name.singularize.camelize}", "#{class_name.singularize.camelize(:lower)}")
|
899
|
+
a1 = result.dig("data", "create#{class_name.singularize.camelize}", "#{class_name.singularize.camelize(:lower)}Edge", "node")
|
869
900
|
expect(a1).to include(
|
870
901
|
"id" => be_a(String),
|
871
902
|
EOS
|
@@ -1139,6 +1170,7 @@ end
|
|
1139
1170
|
singularized_class_name = class_name.singularize
|
1140
1171
|
model_paths = model class_name: singularized_class_name
|
1141
1172
|
type_paths = type class_name: singularized_class_name
|
1173
|
+
node_type_paths = node_type class_name: singularized_class_name
|
1142
1174
|
rspec_factory_paths = rspec_factory class_name: singularized_class_name
|
1143
1175
|
rspec_model_paths = rspec_model class_name: singularized_class_name
|
1144
1176
|
rspec_mutation_paths = rspec_mutation class_name: singularized_class_name
|
@@ -1148,6 +1180,7 @@ end
|
|
1148
1180
|
[
|
1149
1181
|
model: model_paths,
|
1150
1182
|
type: type_paths,
|
1183
|
+
node_type: node_type_paths,
|
1151
1184
|
rspec_factory: rspec_factory_paths,
|
1152
1185
|
rspec_model: rspec_model_paths,
|
1153
1186
|
rspec_mutation: rspec_mutation_paths,
|
@@ -1161,7 +1194,8 @@ end
|
|
1161
1194
|
add_mutation_type: [
|
1162
1195
|
" field :create_#{singularized_class_name}, mutation: Mutations::#{singularized_class_name.camelize}::Create#{singularized_class_name.camelize}",
|
1163
1196
|
" field :update_#{singularized_class_name}, mutation: Mutations::#{singularized_class_name.camelize}::Update#{singularized_class_name.camelize}",
|
1164
|
-
" field :delete_#{singularized_class_name}, mutation: Mutations::#{singularized_class_name.camelize}::Delete#{singularized_class_name.camelize}"
|
1197
|
+
" field :delete_#{singularized_class_name}, mutation: Mutations::#{singularized_class_name.camelize}::Delete#{singularized_class_name.camelize}",
|
1198
|
+
" field :destroy_delete_#{singularized_class_name}, mutation: Mutations::#{singularized_class_name.camelize}::DestroyDelete#{singularized_class_name.camelize}"
|
1165
1199
|
]
|
1166
1200
|
]
|
1167
1201
|
end
|
@@ -1171,6 +1205,7 @@ end
|
|
1171
1205
|
result = migrate class_name: class_name
|
1172
1206
|
puts result[0][:model]
|
1173
1207
|
puts result[0][:type]
|
1208
|
+
puts result[0][:node_type]
|
1174
1209
|
puts result[0][:rspec_factory]
|
1175
1210
|
puts result[0][:rspec_model]
|
1176
1211
|
puts result[0][:rspec_mutation]
|
@@ -1220,6 +1255,12 @@ end
|
|
1220
1255
|
path[:type].each { |line| puts line }
|
1221
1256
|
end
|
1222
1257
|
end
|
1258
|
+
puts "\n============== NodeType =======================\n\n"
|
1259
|
+
paths.each do |class_name|
|
1260
|
+
class_name.each do |path|
|
1261
|
+
path[:node_type].each { |line| puts line }
|
1262
|
+
end
|
1263
|
+
end
|
1223
1264
|
puts "\n============== FactoryBot =================\n\n"
|
1224
1265
|
paths.each do |class_name|
|
1225
1266
|
class_name.each do |path|
|
data/lib/souls/version.rb
CHANGED
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.14.
|
4
|
+
version: 0.14.8
|
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-02-
|
13
|
+
date: 2021-02-12 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.
|
@@ -43,6 +43,7 @@ files:
|
|
43
43
|
- config/initializers/souls.rb
|
44
44
|
- exe/souls
|
45
45
|
- lib/souls.rb
|
46
|
+
- lib/souls/generate.rb
|
46
47
|
- lib/souls/init.rb
|
47
48
|
- lib/souls/version.rb
|
48
49
|
- rbs/init.rbs
|