souls 0.10.9 → 0.11.4
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/.rubocop.yml +1 -1
- data/Gemfile.lock +1 -1
- data/exe/souls +1 -1
- data/lib/souls/init.rb +136 -14
- data/lib/souls/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 41f25d625a2113234605b9dae1fd2cbe7e5ae6116c99b675801d7e5b857e39f3
|
|
4
|
+
data.tar.gz: 4f07c3fae2465999b0c0adcb859680e9e45eb4bbfb49d33cf6f07443fb62d11e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4fab56a0dfb7c3f20f20651f5c87c53b92128ce56e30125c9bb56b0e1648bf867e88b4f92bd87fdfc30b9fcc7cb1beb4faed21e61df855a83adacf8a57ff1700
|
|
7
|
+
data.tar.gz: 603a9c0c54f42750aae84e7d649e5d334c01bbc30157d61ac1d302f017cd7862834ffffa75d4d025b52d19cbae7ac43a8cef7f4ff7ebafcbcf1f5a2bed5c95ec
|
data/.rubocop.yml
CHANGED
data/Gemfile.lock
CHANGED
data/exe/souls
CHANGED
data/lib/souls/init.rb
CHANGED
|
@@ -460,7 +460,7 @@ module Souls
|
|
|
460
460
|
]
|
|
461
461
|
end
|
|
462
462
|
|
|
463
|
-
def
|
|
463
|
+
def create_queries class_name: "souls"
|
|
464
464
|
file_path = "./app/graphql/queries/#{class_name.pluralize}.rb"
|
|
465
465
|
File.open(file_path, "w") do |f|
|
|
466
466
|
f.write <<~EOS
|
|
@@ -480,17 +480,18 @@ module Souls
|
|
|
480
480
|
file_path
|
|
481
481
|
end
|
|
482
482
|
|
|
483
|
-
def
|
|
483
|
+
def create_query class_name: "souls"
|
|
484
484
|
file_path = "./app/graphql/queries/#{class_name}.rb"
|
|
485
485
|
File.open(file_path, "w") do |f|
|
|
486
486
|
f.write <<~EOS
|
|
487
487
|
module Queries
|
|
488
488
|
class #{class_name.camelize} < Queries::BaseQuery
|
|
489
489
|
type Types::#{class_name.camelize}Type, null: false
|
|
490
|
-
argument :id,
|
|
490
|
+
argument :id, String, required: true
|
|
491
491
|
|
|
492
|
-
def resolve
|
|
493
|
-
|
|
492
|
+
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)
|
|
494
495
|
rescue StandardError => error
|
|
495
496
|
GraphQL::ExecutionError.new error
|
|
496
497
|
end
|
|
@@ -624,12 +625,12 @@ module Souls
|
|
|
624
625
|
end
|
|
625
626
|
|
|
626
627
|
def rspec_mutation_head class_name: "souls"
|
|
627
|
-
file_path = "./spec/mutations/#{class_name.
|
|
628
|
+
file_path = "./spec/mutations/#{class_name.singularize}_spec.rb"
|
|
628
629
|
File.open(file_path, "w") do |f|
|
|
629
630
|
f.write <<~EOS
|
|
630
|
-
RSpec.describe #{class_name.camelize} Mutation do
|
|
631
|
-
describe "#{class_name.camelize}
|
|
632
|
-
let!(:#{class_name.singularize.
|
|
631
|
+
RSpec.describe \"#{class_name.camelize} Mutation テスト\" do
|
|
632
|
+
describe "#{class_name.camelize} データを登録する" do
|
|
633
|
+
let!(:#{class_name.singularize.underscore}) { FactoryBot.create(:#{class_name.singularize.underscore}) }
|
|
633
634
|
|
|
634
635
|
let(:mutation) do
|
|
635
636
|
%(mutation {
|
|
@@ -647,12 +648,10 @@ module Souls
|
|
|
647
648
|
f.each_line.with_index do |line, i|
|
|
648
649
|
if @on
|
|
649
650
|
if line.include?("end") || line.include?("t.index")
|
|
650
|
-
new_line.write " }) {\n
|
|
651
|
+
new_line.write " }) {\n #{class_name.singularize.camelize} {\n id\n"
|
|
651
652
|
break
|
|
652
653
|
end
|
|
653
|
-
field = '["tag1", "tag2", "tag3"]' if line.include?("array: true")
|
|
654
654
|
type, name = line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
|
|
655
|
-
field ||= get_test_type type
|
|
656
655
|
case name
|
|
657
656
|
when "created_at", "updated_at"
|
|
658
657
|
next
|
|
@@ -761,6 +760,7 @@ end
|
|
|
761
760
|
end
|
|
762
761
|
end
|
|
763
762
|
end
|
|
763
|
+
[file_path]
|
|
764
764
|
end
|
|
765
765
|
|
|
766
766
|
def rspec_mutation class_name: "souls"
|
|
@@ -771,8 +771,115 @@ end
|
|
|
771
771
|
rspec_mutation_end class_name: singularized_class_name
|
|
772
772
|
end
|
|
773
773
|
|
|
774
|
+
def rspec_query_head class_name: "souls"
|
|
775
|
+
file_path = "./spec/queries/#{class_name.singularize}_spec.rb"
|
|
776
|
+
File.open(file_path, "w") do |f|
|
|
777
|
+
f.write <<~EOS
|
|
778
|
+
RSpec.describe \"#{class_name.camelize} Query テスト\" do
|
|
779
|
+
describe "#{class_name.camelize} データを取得する" do
|
|
780
|
+
let!(:#{class_name.singularize.underscore}) { FactoryBot.create(:#{class_name.singularize.underscore}) }
|
|
781
|
+
|
|
782
|
+
let(:query) do
|
|
783
|
+
%(query {
|
|
784
|
+
#{class_name.singularize.underscore}(id: \#{Base64.encode64("#{class_name.camelize}:\#{#{class_name.underscore}.id}")}) {
|
|
785
|
+
id
|
|
786
|
+
EOS
|
|
787
|
+
end
|
|
788
|
+
end
|
|
789
|
+
|
|
790
|
+
def rspec_query_params class_name: "souls"
|
|
791
|
+
file_path = "./spec/queries/#{class_name.pluralize}.rb"
|
|
792
|
+
path = "./db/schema.rb"
|
|
793
|
+
@on = false
|
|
794
|
+
File.open(file_path, "a") do |new_line|
|
|
795
|
+
File.open(path, "r") do |f|
|
|
796
|
+
f.each_line.with_index do |line, i|
|
|
797
|
+
if @on
|
|
798
|
+
if line.include?("end") || line.include?("t.index")
|
|
799
|
+
new_line.write <<-EOS
|
|
800
|
+
}
|
|
801
|
+
}
|
|
802
|
+
)
|
|
803
|
+
end
|
|
804
|
+
|
|
805
|
+
subject(:result) do
|
|
806
|
+
SoulsApiSchema.execute(query).as_json
|
|
807
|
+
end
|
|
808
|
+
|
|
809
|
+
it "return #{class_name.camelize} Data" do
|
|
810
|
+
a1 = result.dig("data", "#{class_name.singularize.underscore}")
|
|
811
|
+
expect(a1).to include(
|
|
812
|
+
"id" => be_a(String),
|
|
813
|
+
EOS
|
|
814
|
+
break
|
|
815
|
+
end
|
|
816
|
+
_, name = line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
|
|
817
|
+
case name
|
|
818
|
+
when "created_at", "updated_at"
|
|
819
|
+
next
|
|
820
|
+
else
|
|
821
|
+
new_line.write " #{name.singularize.camelize(:lower)}\n"
|
|
822
|
+
end
|
|
823
|
+
end
|
|
824
|
+
if table_check(line: line, class_name: class_name)
|
|
825
|
+
@on = true
|
|
826
|
+
end
|
|
827
|
+
end
|
|
828
|
+
end
|
|
829
|
+
end
|
|
830
|
+
end
|
|
831
|
+
|
|
832
|
+
def rspec_query_end class_name: "souls"
|
|
833
|
+
file_path = "./spec/queries/#{class_name.pluralize}.rb"
|
|
834
|
+
path = "./db/schema.rb"
|
|
835
|
+
@on = false
|
|
836
|
+
File.open(file_path, "a") do |new_line|
|
|
837
|
+
File.open(path, "r") do |f|
|
|
838
|
+
f.each_line.with_index do |line, i|
|
|
839
|
+
if @on
|
|
840
|
+
if line.include?("end") || line.include?("t.index")
|
|
841
|
+
new_line.write <<-EOS
|
|
842
|
+
)
|
|
843
|
+
end
|
|
844
|
+
end
|
|
845
|
+
end
|
|
846
|
+
EOS
|
|
847
|
+
break
|
|
848
|
+
end
|
|
849
|
+
type, name = line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
|
|
850
|
+
field ||= type_check type
|
|
851
|
+
array_true = line.include?("array: true")
|
|
852
|
+
case name
|
|
853
|
+
when "created_at", "updated_at"
|
|
854
|
+
next
|
|
855
|
+
else
|
|
856
|
+
case type
|
|
857
|
+
when "text"
|
|
858
|
+
if array_true
|
|
859
|
+
new_line.write " \"#{name.singularize.camelize(:lower)}\" => be_all(String),\n"
|
|
860
|
+
end
|
|
861
|
+
new_line.write " \"#{name.singularize.camelize(:lower)}\" => be_a(#{field}),\n"
|
|
862
|
+
when "string", "bigint", "integer", "float", "boolean"
|
|
863
|
+
new_line.write " \"#{name.singularize.camelize(:lower)}\" => be_a(#{field}),\n"
|
|
864
|
+
when "date", "datetime"
|
|
865
|
+
new_line.write " \"#{name.singularize.camelize(:lower)}\" => be_a(DateTime),\n"
|
|
866
|
+
end
|
|
867
|
+
end
|
|
868
|
+
end
|
|
869
|
+
if table_check(line: line, class_name: class_name)
|
|
870
|
+
@on = true
|
|
871
|
+
end
|
|
872
|
+
end
|
|
873
|
+
end
|
|
874
|
+
end
|
|
875
|
+
[file_path]
|
|
876
|
+
end
|
|
877
|
+
|
|
774
878
|
def rspec_query class_name: "souls"
|
|
775
|
-
|
|
879
|
+
singularized_class_name = class_name.singularize
|
|
880
|
+
rspec_query_head class_name: singularized_class_name
|
|
881
|
+
rspec_query_params class_name: singularized_class_name
|
|
882
|
+
rspec_query_end class_name: singularized_class_name
|
|
776
883
|
end
|
|
777
884
|
|
|
778
885
|
def get_end_point
|
|
@@ -809,6 +916,8 @@ end
|
|
|
809
916
|
type_paths = type class_name: singularized_class_name
|
|
810
917
|
rspec_factory_paths = rspec_factory class_name: singularized_class_name
|
|
811
918
|
rspec_model_paths = rspec_model class_name: singularized_class_name
|
|
919
|
+
rspec_mutation_paths = rspec_mutation class_name: singularized_class_name
|
|
920
|
+
rspec_query_paths = rspec_query class_name: singularized_class_name
|
|
812
921
|
query_path = query class_name: singularized_class_name
|
|
813
922
|
mutation_path = mutation class_name: singularized_class_name
|
|
814
923
|
[
|
|
@@ -816,6 +925,8 @@ end
|
|
|
816
925
|
type: type_paths,
|
|
817
926
|
rspec_factory: rspec_factory_paths,
|
|
818
927
|
rspec_model: rspec_model_paths,
|
|
928
|
+
rspec_mutation: rspec_mutation_paths,
|
|
929
|
+
rspec_query: rspec_query_paths,
|
|
819
930
|
query: query_path,
|
|
820
931
|
mutation: mutation_path,
|
|
821
932
|
add_query_type: [
|
|
@@ -832,7 +943,6 @@ end
|
|
|
832
943
|
|
|
833
944
|
def migrate_all
|
|
834
945
|
puts "◆◆◆ Let's Auto Generate CRUD API ◆◆◆\n"
|
|
835
|
-
`rake db:migrate`
|
|
836
946
|
paths = get_tables.map do |class_name|
|
|
837
947
|
migrate class_name: class_name.singularize
|
|
838
948
|
end
|
|
@@ -860,6 +970,18 @@ end
|
|
|
860
970
|
path[:rspec_model].each { |line| puts line }
|
|
861
971
|
end
|
|
862
972
|
end
|
|
973
|
+
puts "\n============== RspecMutation =================\n\n"
|
|
974
|
+
paths.each do |class_name|
|
|
975
|
+
class_name.each do |path|
|
|
976
|
+
path[:rspec_mutation].each { |line| puts line }
|
|
977
|
+
end
|
|
978
|
+
end
|
|
979
|
+
puts "\n============== RspecQuery =================\n\n"
|
|
980
|
+
paths.each do |class_name|
|
|
981
|
+
class_name.each do |path|
|
|
982
|
+
path[:rspec_query].each { |line| puts line }
|
|
983
|
+
end
|
|
984
|
+
end
|
|
863
985
|
puts "\n============== Query ======================\n\n"
|
|
864
986
|
paths.each do |class_name|
|
|
865
987
|
class_name.each do |path|
|
data/lib/souls/version.rb
CHANGED