souls 0.13.4 → 0.13.5

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: 6f8b1300fc4644e24954fa9d46aa50ecc86731f9fb982ea3f198c9b57e017838
4
- data.tar.gz: c3144d0eb3dfd8521f9ea2f76da354809dd791a571052ec9b45fb586cebc5985
3
+ metadata.gz: 708f22e2d3efc407f65326eedb0ea4b8958e812b713b8e0a738b22ec9166660f
4
+ data.tar.gz: f5eaa355fd1123c0c8e99ee4e9a591169716766c5f32667dd8c0ed3baa5ce2a5
5
5
  SHA512:
6
- metadata.gz: b7c6e656cbb4aeec299eda315fda2f68ce08beb2010d160e20966eb1371e5ebc1deb2d143ecfc5b9c0210baf83ed10a807a5e04464ade080235dd13ccc857c7b
7
- data.tar.gz: 248b0e01f35edcf49bc4d887d3cf7468c9967012c011adf092d898d6538554deaecd46c14cbae4ca0364e6c7cacaf68a29836f2900b9bc5db9b63fcbd715abd5
6
+ metadata.gz: ebf255d21f902c2ad11d7f4869fc5d671e59065861f7865b4d0365f972a2336d8b92cfbd069ced29ab59f79cf3d824412a1fca119cb230e38f8bb9f467feb25d
7
+ data.tar.gz: c2aa3e77d9f73278a5e1f4a73ebb4377de3e6e2d1f8451075df63b8158e85d6422f65c7f28d53fbcc0bb081060446b385040279899151fb4bcc29c78ac257f03
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- souls (0.13.0)
4
+ souls (0.13.4)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -304,15 +304,32 @@ module Souls
304
304
  file_path = "./app/graphql/mutations/#{class_name}/create_#{class_name}.rb"
305
305
  path = "./db/schema.rb"
306
306
  @on = false
307
+ @user_exist = false
307
308
  File.open(file_path, "a") do |new_line|
308
309
  File.open(path, "r") do |f|
309
310
  f.each_line.with_index do |line, i|
310
311
  if @on
311
- break if line.include?("end") || line.include?("t.index")
312
+ if line.include?("end") || line.include?("t.index")
313
+ if @user_exist
314
+ new_line.write <<-EOS
315
+
316
+ def resolve **args
317
+ args[:user_id] = context[:user].id
318
+ EOS
319
+ else
320
+ new_line.write <<-EOS
321
+
322
+ def resolve **args
323
+ EOS
324
+ end
325
+ break
326
+ end
312
327
  field = "[String]" if line.include?("array: true")
313
328
  type, name = line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
314
329
  field ||= type_check type
315
330
  case name
331
+ when "user_id"
332
+ @user_exist = true
316
333
  when "created_at", "updated_at"
317
334
  next
318
335
  else
@@ -329,8 +346,6 @@ module Souls
329
346
  file_path = "./app/graphql/mutations/#{class_name}/create_#{class_name}.rb"
330
347
  File.open(file_path, "a") do |new_line|
331
348
  new_line.write <<~EOS
332
-
333
- def resolve **args
334
349
  #{class_name} = ::#{class_name.camelize}.new args
335
350
  if #{class_name}.save
336
351
  { #{class_name}: #{class_name} }
@@ -365,15 +380,32 @@ module Souls
365
380
  file_path = "./app/graphql/mutations/#{class_name}/update_#{class_name}.rb"
366
381
  path = "./db/schema.rb"
367
382
  @on = false
383
+ @user_exist = false
368
384
  File.open(file_path, "a") do |new_line|
369
385
  File.open(path, "r") do |f|
370
386
  f.each_line.with_index do |line, i|
371
387
  if @on
372
- break if line.include?("end") || line.include?("t.index")
388
+ if line.include?("end") || line.include?("t.index")
389
+ if @user_exist
390
+ new_line.write <<-EOS
391
+
392
+ def resolve **args
393
+ args[:user_id] = context[:user].id
394
+ EOS
395
+ else
396
+ new_line.write <<-EOS
397
+
398
+ def resolve **args
399
+ EOS
400
+ end
401
+ break
402
+ end
373
403
  field = "[String]" if line.include?("array: true")
374
404
  type, name = line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
375
405
  field ||= type_check type
376
406
  case name
407
+ when "user_id"
408
+ @user_exist = true
377
409
  when "created_at", "updated_at"
378
410
  next
379
411
  else
@@ -390,8 +422,6 @@ module Souls
390
422
  file_path = "./app/graphql/mutations/#{class_name}/update_#{class_name}.rb"
391
423
  File.open(file_path, "a") do |new_line|
392
424
  new_line.write <<~EOS
393
-
394
- def resolve **args
395
425
  #{class_name} = ::#{class_name.camelize}.find args[:id]
396
426
  #{class_name}.update args
397
427
  { #{class_name}: ::#{class_name.camelize}.find(args[:id]) }
@@ -420,10 +450,11 @@ module Souls
420
450
  module #{class_name.camelize}
421
451
  class Delete#{class_name.camelize} < BaseMutation
422
452
  field :#{class_name}, Types::#{class_name.camelize}Type, null: false
423
- argument :id, Integer, required: true
453
+ argument :id, String, required: true
424
454
 
425
- def resolve id:
426
- #{class_name} = ::#{class_name.camelize}.find id
455
+ def resolve **args
456
+ _, data_id = SoulsApiSchema.from_global_id args[:id]
457
+ #{class_name} = ::#{class_name.camelize}.find data_id
427
458
  #{class_name}.destroy
428
459
  { #{class_name}: #{class_name} }
429
460
  rescue StandardError => error
@@ -490,8 +521,8 @@ module Souls
490
521
  argument :id, String, required: true
491
522
 
492
523
  def resolve **args
493
- _, #{class_name.singularize.underscore}_id = SoulsApiSchema.from_global_id args[:id]
494
- ::#{class_name.camelize}.find(#{class_name.singularize.underscore}_id)
524
+ _, data_id = SoulsApiSchema.from_global_id args[:id]
525
+ ::#{class_name.camelize}.find(data_id)
495
526
  rescue StandardError => error
496
527
  GraphQL::ExecutionError.new error
497
528
  end
@@ -650,10 +681,11 @@ module Souls
650
681
  file_path = "./spec/mutations/#{class_name.singularize}_spec.rb"
651
682
  path = "./db/schema.rb"
652
683
  @on = false
684
+ @user_exist = false
653
685
  File.open(file_path, "a") do |new_line|
654
686
  File.open(path, "r") do |f|
655
687
  f.each_line.with_index do |line, i|
656
- if @on
688
+ if @on
657
689
  if line.include?("end") || line.include?("t.index")
658
690
  new_line.write " }) {\n #{class_name.singularize.camelize(:lower)} {\n id\n"
659
691
  break
@@ -663,6 +695,8 @@ module Souls
663
695
  case name
664
696
  when "created_at", "updated_at"
665
697
  next
698
+ when "user_id"
699
+ @user_exist = true
666
700
  else
667
701
  case type
668
702
  when "string", "text", "date", "datetime"
@@ -693,7 +727,28 @@ module Souls
693
727
  f.each_line.with_index do |line, i|
694
728
  if @on
695
729
  if line.include?("end") || line.include?("t.index")
696
- new_line.write <<-EOS
730
+ if @user_exist
731
+ new_line.write <<-EOS
732
+ }
733
+ }
734
+ }
735
+ )
736
+ end
737
+
738
+ subject(:result) do
739
+ context = {
740
+ user: user
741
+ }
742
+ SoulsApiSchema.execute(mutation, context: context).as_json
743
+ end
744
+
745
+ it "return #{class_name.camelize} Data" do
746
+ a1 = result.dig("data", "create#{class_name.singularize.camelize}", "#{class_name.singularize.camelize(:lower)}")
747
+ expect(a1).to include(
748
+ "id" => be_a(String),
749
+ EOS
750
+ else
751
+ new_line.write <<-EOS
697
752
  }
698
753
  }
699
754
  }
@@ -708,13 +763,14 @@ module Souls
708
763
  a1 = result.dig("data", "create#{class_name.singularize.camelize}", "#{class_name.singularize.camelize(:lower)}")
709
764
  expect(a1).to include(
710
765
  "id" => be_a(String),
711
- EOS
766
+ EOS
767
+ end
712
768
  break
713
769
  end
714
770
  _, name = line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
715
771
  array_true = line.include?("array: true")
716
772
  case name
717
- when "created_at", "updated_at"
773
+ when "user_id", "created_at", "updated_at"
718
774
  next
719
775
  else
720
776
  if array_true
@@ -741,11 +797,11 @@ module Souls
741
797
  f.each_line.with_index do |line, i|
742
798
  if @on
743
799
  if line.include?("end") || line.include?("t.index")
744
- new_line.write <<-EOS
745
- )
746
- end
747
- end
748
- end
800
+ new_line.write <<~EOS
801
+ )
802
+ end
803
+ end
804
+ end
749
805
  EOS
750
806
  break
751
807
  end
@@ -753,7 +809,7 @@ end
753
809
  field ||= type_check type
754
810
  array_true = line.include?("array: true")
755
811
  case name
756
- when "created_at", "updated_at"
812
+ when "user_id", "created_at", "updated_at"
757
813
  next
758
814
  else
759
815
  case type
@@ -832,7 +888,7 @@ end
832
888
  end
833
889
  _, name = line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
834
890
  case name
835
- when "created_at", "updated_at"
891
+ when "user_id", "created_at", "updated_at"
836
892
  next
837
893
  else
838
894
  new_line.write " #{name.singularize.camelize(:lower)}\n"
@@ -867,7 +923,7 @@ end
867
923
  field ||= type_check type
868
924
  array_true = line.include?("array: true")
869
925
  case name
870
- when "created_at", "updated_at"
926
+ when "user_id", "created_at", "updated_at"
871
927
  next
872
928
  else
873
929
  case type
@@ -1,3 +1,3 @@
1
1
  module Souls
2
- VERSION = "0.13.4"
2
+ VERSION = "0.13.5"
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.13.4
4
+ version: 0.13.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - POPPIN-FUMI