souls 0.14.7 → 0.15.2

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: 82a93c134d59e41d907e30a4784bc6d0713d20ec016e606b49f957aa699e1e82
4
- data.tar.gz: 663dd3215bf74f74fa17e6178a4afface0c4a173334519c4e27af210261716f2
3
+ metadata.gz: c7b44206555239cc385474416cbba36b9dddad92466891ee4c8854370c4ae817
4
+ data.tar.gz: 8f11b53691ecdc25c592470296230d4bfc1b65454d5bc1d5bb4467de32848f6a
5
5
  SHA512:
6
- metadata.gz: 182ee54e370af1f746a45613aeb1c78604701a2ac075e7de9e58e211ed8028a0a75dcc4ab0fddce1f870a17392c14a7fc0e1aede1bdc6d8c37bdf4e107457d23
7
- data.tar.gz: d91eab772bd9ec65a0844df7fb363171a2a02c76d9300c60087c37fcc75a26d188e067ae36526d9401c09793aacbe16c46bb6968dc126884ef0ad7ea5649b93a
6
+ metadata.gz: 393cc8a649f39858552f9ebcb72fbcd2c8c9973b9946def63ac73fafed150b0d55af307b5e4a14aec80771ae61019d49e9c5be73c585e2cfaa19256b7664911e
7
+ data.tar.gz: 71a1f70b1ef6ceb7853768685e7d05fe3193a838db649e6ae19486d022498a0ff2932a98876c5c52a3ad23495c31cf4afdd9be4182dce755b543faa85b9dbfa4
data/Gemfile CHANGED
@@ -6,5 +6,5 @@ gemspec
6
6
  gem "activesupport", "6.1.0"
7
7
  gem "rake", "13.0.3"
8
8
  gem "rspec", "3.1.0"
9
+ gem "rubocop", "1.7.0"
9
10
  gem "steep", "0.39.0"
10
- gem "rubocop", "1.7.0"
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- souls (0.14.6)
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.7)
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
@@ -47,8 +47,12 @@ begin
47
47
  case ARGV[1]
48
48
  when "test_dir"
49
49
  Souls::Init.test_dir
50
- when "test"
51
- Souls::Init.single_migrate class_name: "user"
50
+ when "node_type"
51
+ Souls::Init.node_type class_name: ARGV[2]
52
+ when "resolver"
53
+ Souls::Init.resolver class_name: ARGV[2]
54
+ when "job"
55
+ Souls::Init.job class_name: ARGV[2]
52
56
  when "model"
53
57
  Souls::Init.model class_name: ARGV[2]
54
58
  when "mutation"
@@ -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
@@ -1,5 +1,6 @@
1
1
  require "souls/version"
2
2
  require "souls/init"
3
+ require "souls/generate"
3
4
  require "json"
4
5
  require "active_support/core_ext/string/inflections"
5
6
  require "fileutils"
@@ -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}Type, 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,7 +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
+ return ["Model already exist! #{file_path}"] if File.exist? file_path
248
248
  File.open(file_path, "w") do |f|
249
249
  f.write <<~EOS
250
250
  class #{class_name.camelize} < ActiveRecord::Base
@@ -258,6 +258,8 @@ module Souls
258
258
  FileUtils.mkdir_p "./app/graphql/mutations"
259
259
  FileUtils.mkdir_p "./app/graphql/queries"
260
260
  FileUtils.mkdir_p "./app/graphql/types"
261
+ FileUtils.mkdir_p "./app/graphql/resolvers"
262
+ FileUtils.mkdir_p "./app/jobs"
261
263
  FileUtils.mkdir_p "./app/models"
262
264
  FileUtils.mkdir_p "./spec/factories"
263
265
  FileUtils.mkdir_p "./spec/queries"
@@ -310,7 +312,7 @@ module Souls
310
312
  module Mutations
311
313
  module #{class_name.camelize}
312
314
  class Create#{class_name.camelize} < BaseMutation
313
- field :#{class_name}, Types::#{class_name.camelize}Type, null: false
315
+ field :#{class_name}_edge, Types::#{class_name.camelize}NodeType, null: false
314
316
  field :error, String, null: true
315
317
 
316
318
  EOS
@@ -381,7 +383,7 @@ module Souls
381
383
  new_line.write <<~EOS
382
384
  #{class_name} = ::#{class_name.camelize}.new args
383
385
  if #{class_name}.save
384
- { #{class_name}: #{class_name} }
386
+ { #{class_name}_edge: { node: #{class_name} } }
385
387
  else
386
388
  { error: #{class_name}.errors.full_messages }
387
389
  end
@@ -403,7 +405,7 @@ module Souls
403
405
  module Mutations
404
406
  module #{class_name.camelize}
405
407
  class Update#{class_name.camelize} < BaseMutation
406
- field :#{class_name}, Types::#{class_name.camelize}Type, null: false
408
+ field :#{class_name}_edge, Types::#{class_name.camelize}NodeType, null: false
407
409
 
408
410
  argument :id, String, required: true
409
411
  EOS
@@ -476,7 +478,7 @@ module Souls
476
478
  new_line.write <<~EOS
477
479
  #{class_name} = ::#{class_name.camelize}.find args[:id]
478
480
  #{class_name}.update args
479
- { #{class_name}: ::#{class_name.camelize}.find(args[:id]) }
481
+ { #{class_name}_edge: { node: ::#{class_name.camelize}.find(args[:id]) } }
480
482
  rescue StandardError => error
481
483
  GraphQL::ExecutionError.new error
482
484
  end
@@ -505,6 +507,32 @@ module Souls
505
507
  field :#{class_name}, Types::#{class_name.camelize}Type, null: false
506
508
  argument :id, String, required: true
507
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
+
508
536
  def resolve **args
509
537
  _, data_id = SoulsApiSchema.from_global_id args[:id]
510
538
  #{class_name} = ::#{class_name.camelize}.find data_id
@@ -537,7 +565,8 @@ module Souls
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
 
@@ -695,6 +724,7 @@ module Souls
695
724
  end
696
725
 
697
726
  def rspec_factory class_name: "souls"
727
+ return ["Aleady Exist!"] unless File.exist? "./spec/factories/#{class_name.singularize}"
698
728
  singularized_class_name = class_name.singularize
699
729
  rspec_factory_head class_name: singularized_class_name
700
730
  rspec_factory_params class_name: singularized_class_name
@@ -703,6 +733,7 @@ module Souls
703
733
 
704
734
  def rspec_model class_name: "souls"
705
735
  file_path = "./spec/models/#{class_name}_spec.rb"
736
+ return ["Aleady Exist!"] unless File.exist? file_path
706
737
  File.open(file_path, "w") do |f|
707
738
  f.write <<~EOS
708
739
  RSpec.describe "#{class_name.camelize} Model テスト", type: :model do
@@ -790,7 +821,8 @@ module Souls
790
821
  f.each_line.with_index do |line, i|
791
822
  if @on
792
823
  if line.include?("end") || line.include?("t.index")
793
- new_line.write " }) {\n #{class_name.singularize.camelize(:lower)} {\n id\n"
824
+ new_line.write " }) {\n #{class_name.singularize.camelize(:lower)}Edge {\n node {\n"
825
+ new_line.write " id\n"
794
826
  break
795
827
  end
796
828
  type, name = line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
@@ -834,6 +866,7 @@ module Souls
834
866
  if line.include?("end") || line.include?("t.index")
835
867
  if @user_exist
836
868
  new_line.write <<-EOS
869
+ }
837
870
  }
838
871
  }
839
872
  }
@@ -848,12 +881,13 @@ module Souls
848
881
  end
849
882
 
850
883
  it "return #{class_name.camelize} Data" do
851
- a1 = result.dig("data", "create#{class_name.singularize.camelize}", "#{class_name.singularize.camelize(:lower)}")
884
+ a1 = result.dig("data", "create#{class_name.singularize.camelize}", "#{class_name.singularize.camelize(:lower)}Edge", "node")
852
885
  expect(a1).to include(
853
886
  "id" => be_a(String),
854
887
  EOS
855
888
  else
856
889
  new_line.write <<-EOS
890
+ }
857
891
  }
858
892
  }
859
893
  }
@@ -865,7 +899,7 @@ module Souls
865
899
  end
866
900
 
867
901
  it "return #{class_name.camelize} Data" do
868
- a1 = result.dig("data", "create#{class_name.singularize.camelize}", "#{class_name.singularize.camelize(:lower)}")
902
+ a1 = result.dig("data", "create#{class_name.singularize.camelize}", "#{class_name.singularize.camelize(:lower)}Edge", "node")
869
903
  expect(a1).to include(
870
904
  "id" => be_a(String),
871
905
  EOS
@@ -1139,6 +1173,7 @@ end
1139
1173
  singularized_class_name = class_name.singularize
1140
1174
  model_paths = model class_name: singularized_class_name
1141
1175
  type_paths = type class_name: singularized_class_name
1176
+ node_type_paths = node_type class_name: singularized_class_name
1142
1177
  rspec_factory_paths = rspec_factory class_name: singularized_class_name
1143
1178
  rspec_model_paths = rspec_model class_name: singularized_class_name
1144
1179
  rspec_mutation_paths = rspec_mutation class_name: singularized_class_name
@@ -1148,6 +1183,7 @@ end
1148
1183
  [
1149
1184
  model: model_paths,
1150
1185
  type: type_paths,
1186
+ node_type: node_type_paths,
1151
1187
  rspec_factory: rspec_factory_paths,
1152
1188
  rspec_model: rspec_model_paths,
1153
1189
  rspec_mutation: rspec_mutation_paths,
@@ -1161,7 +1197,8 @@ end
1161
1197
  add_mutation_type: [
1162
1198
  " field :create_#{singularized_class_name}, mutation: Mutations::#{singularized_class_name.camelize}::Create#{singularized_class_name.camelize}",
1163
1199
  " 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}"
1200
+ " field :delete_#{singularized_class_name}, mutation: Mutations::#{singularized_class_name.camelize}::Delete#{singularized_class_name.camelize}",
1201
+ " field :destroy_delete_#{singularized_class_name}, mutation: Mutations::#{singularized_class_name.camelize}::DestroyDelete#{singularized_class_name.camelize}"
1165
1202
  ]
1166
1203
  ]
1167
1204
  end
@@ -1171,6 +1208,7 @@ end
1171
1208
  result = migrate class_name: class_name
1172
1209
  puts result[0][:model]
1173
1210
  puts result[0][:type]
1211
+ puts result[0][:node_type]
1174
1212
  puts result[0][:rspec_factory]
1175
1213
  puts result[0][:rspec_model]
1176
1214
  puts result[0][:rspec_mutation]
@@ -1220,6 +1258,12 @@ end
1220
1258
  path[:type].each { |line| puts line }
1221
1259
  end
1222
1260
  end
1261
+ puts "\n============== NodeType =======================\n\n"
1262
+ paths.each do |class_name|
1263
+ class_name.each do |path|
1264
+ path[:node_type].each { |line| puts line }
1265
+ end
1266
+ end
1223
1267
  puts "\n============== FactoryBot =================\n\n"
1224
1268
  paths.each do |class_name|
1225
1269
  class_name.each do |path|
data/lib/souls/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Souls
2
- VERSION = "0.14.7"
2
+ VERSION = "0.15.2"
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.14.7
4
+ version: 0.15.2
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-04 00:00:00.000000000 Z
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