souls 0.9.4 → 0.10.1
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 +2 -4
- data/lib/souls/init.rb +143 -60
- 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: e75a809266d43f9c1f712c89d8d20f8156bf7c535de57a61e708920e75bfd044
|
|
4
|
+
data.tar.gz: cd0fc519cd00283704edb8cb8892fe4eecf4329553435d8a7b8c36fe2588ae3c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ee85b4b713494dc0ad4ffe7407e4f713184416cb164d4ff7d90e68862c5058924ebbfedb7fc1d51a3b9fd7f68e0ec7b9fd4ac6f86473aeff0b43b2d036ad12fe
|
|
7
|
+
data.tar.gz: 8792bf31bf2803ad97f7f58f7c3ce71b2ba49b28b433e5fdfbd37a001b3d5c37844c995b200cc81cbb80aed15e16af82f78ddece504388830241a241ded90116
|
data/.rubocop.yml
CHANGED
data/Gemfile.lock
CHANGED
data/exe/souls
CHANGED
|
@@ -58,11 +58,9 @@ begin
|
|
|
58
58
|
when "type"
|
|
59
59
|
Souls::Init.type class_name: ARGV[2]
|
|
60
60
|
when "migrate"
|
|
61
|
-
Souls::Init.
|
|
61
|
+
Souls::Init.migrate class_name: ARGV[2]
|
|
62
62
|
when "migrate_all"
|
|
63
|
-
Souls::Init.
|
|
64
|
-
Souls::Init.migration class_name: class_name
|
|
65
|
-
end
|
|
63
|
+
Souls::Init.migrate_all
|
|
66
64
|
when "migration"
|
|
67
65
|
`rake db:create_migration NAME=#{ARGV[3]}`
|
|
68
66
|
when "rspec_factory"
|
data/lib/souls/init.rb
CHANGED
|
@@ -115,11 +115,11 @@ module Souls
|
|
|
115
115
|
system "cp -r #{repository_name}-#{folder}/ #{app_name}/"
|
|
116
116
|
system "rm -rf #{version}.tar.gz && rm -rf #{repository_name}-#{folder}"
|
|
117
117
|
txt = <<~TEXT
|
|
118
|
-
_____ ____ __ ____
|
|
118
|
+
_____ ____ __ ____#{' '}
|
|
119
119
|
/ ___// __ \\/ / / / / _____
|
|
120
120
|
\\__ \\/ / / / / / / / / ___/
|
|
121
|
-
___/ / /_/ / /_/ / /___(__ )
|
|
122
|
-
/____/\\____/\\____/_____/____
|
|
121
|
+
___/ / /_/ / /_/ / /___(__ )#{' '}
|
|
122
|
+
/____/\\____/\\____/_____/____/#{' '}
|
|
123
123
|
TEXT
|
|
124
124
|
puts txt
|
|
125
125
|
puts "=============================="
|
|
@@ -244,22 +244,24 @@ module Souls
|
|
|
244
244
|
end
|
|
245
245
|
|
|
246
246
|
def model class_name: "souls"
|
|
247
|
-
file_path = "./app/models/#{class_name}.rb"
|
|
247
|
+
file_path = "./app/models/#{class_name.singularize}.rb"
|
|
248
248
|
File.open(file_path, "w") do |f|
|
|
249
249
|
f.write <<~EOS
|
|
250
250
|
class #{class_name.camelize} < ActiveRecord::Base
|
|
251
251
|
end
|
|
252
252
|
EOS
|
|
253
253
|
end
|
|
254
|
-
|
|
254
|
+
[file_path]
|
|
255
255
|
end
|
|
256
256
|
|
|
257
257
|
def type_check type
|
|
258
258
|
{
|
|
259
259
|
bigint: "Integer",
|
|
260
260
|
string: "String",
|
|
261
|
+
float: "Float",
|
|
261
262
|
text: "String",
|
|
262
263
|
datetime: "GraphQL::Types::ISO8601DateTime",
|
|
264
|
+
date: "GraphQL::Types::ISO8601DateTime",
|
|
263
265
|
boolean: "Boolean",
|
|
264
266
|
integer: "Integer"
|
|
265
267
|
}[type.to_sym]
|
|
@@ -268,17 +270,19 @@ module Souls
|
|
|
268
270
|
def get_test_type type
|
|
269
271
|
{
|
|
270
272
|
bigint: 1,
|
|
273
|
+
float: 4.2,
|
|
271
274
|
string: '"MyString"',
|
|
272
275
|
text: '"MyString"',
|
|
273
276
|
datetime: "Time.now",
|
|
277
|
+
date: "Time.now",
|
|
274
278
|
boolean: false,
|
|
275
279
|
integer: 1
|
|
276
280
|
}[type.to_sym]
|
|
277
281
|
end
|
|
278
282
|
|
|
279
283
|
def table_check line: "", class_name: ""
|
|
280
|
-
if line.include?("create_table")
|
|
281
|
-
return true
|
|
284
|
+
if line.include?("create_table") && (line.split(" ")[1].gsub("\"", "").gsub(",", "") == class_name.pluralize.to_s)
|
|
285
|
+
return true
|
|
282
286
|
end
|
|
283
287
|
false
|
|
284
288
|
end
|
|
@@ -306,8 +310,9 @@ module Souls
|
|
|
306
310
|
f.each_line.with_index do |line, i|
|
|
307
311
|
if @on
|
|
308
312
|
break if line.include?("end") || line.include?("t.index")
|
|
313
|
+
field = "[String]" if line.include?("array: true")
|
|
309
314
|
type, name = line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
|
|
310
|
-
field
|
|
315
|
+
field ||= type_check type
|
|
311
316
|
case name
|
|
312
317
|
when "created_at", "updated_at"
|
|
313
318
|
next
|
|
@@ -327,7 +332,7 @@ module Souls
|
|
|
327
332
|
new_line.write <<~EOS
|
|
328
333
|
|
|
329
334
|
def resolve **args
|
|
330
|
-
#{class_name} =
|
|
335
|
+
#{class_name} = ::#{class_name.camelize}.new args
|
|
331
336
|
if #{class_name}.save
|
|
332
337
|
{ #{class_name}: #{class_name} }
|
|
333
338
|
else
|
|
@@ -341,7 +346,7 @@ module Souls
|
|
|
341
346
|
end
|
|
342
347
|
EOS
|
|
343
348
|
end
|
|
344
|
-
|
|
349
|
+
file_path
|
|
345
350
|
end
|
|
346
351
|
|
|
347
352
|
def update_mutation_head class_name: "souls"
|
|
@@ -366,8 +371,9 @@ module Souls
|
|
|
366
371
|
f.each_line.with_index do |line, i|
|
|
367
372
|
if @on
|
|
368
373
|
break if line.include?("end") || line.include?("t.index")
|
|
374
|
+
field = "[String]" if line.include?("array: true")
|
|
369
375
|
type, name = line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
|
|
370
|
-
field
|
|
376
|
+
field ||= type_check type
|
|
371
377
|
case name
|
|
372
378
|
when "created_at", "updated_at"
|
|
373
379
|
next
|
|
@@ -387,9 +393,9 @@ module Souls
|
|
|
387
393
|
new_line.write <<~EOS
|
|
388
394
|
|
|
389
395
|
def resolve **args
|
|
390
|
-
#{class_name} =
|
|
396
|
+
#{class_name} = ::#{class_name.camelize}.find args[:id]
|
|
391
397
|
#{class_name}.update args
|
|
392
|
-
{ #{class_name}:
|
|
398
|
+
{ #{class_name}: ::#{class_name.camelize}.find(args[:id]) }
|
|
393
399
|
rescue StandardError => error
|
|
394
400
|
GraphQL::ExecutionError.new error
|
|
395
401
|
end
|
|
@@ -398,7 +404,7 @@ module Souls
|
|
|
398
404
|
end
|
|
399
405
|
EOS
|
|
400
406
|
end
|
|
401
|
-
|
|
407
|
+
file_path
|
|
402
408
|
end
|
|
403
409
|
|
|
404
410
|
def update_mutation class_name: "souls"
|
|
@@ -418,7 +424,7 @@ module Souls
|
|
|
418
424
|
argument :id, Integer, required: true
|
|
419
425
|
|
|
420
426
|
def resolve id:
|
|
421
|
-
#{class_name} =
|
|
427
|
+
#{class_name} = ::#{class_name.camelize}.find id
|
|
422
428
|
#{class_name}.destroy
|
|
423
429
|
{ #{class_name}: #{class_name} }
|
|
424
430
|
rescue StandardError => error
|
|
@@ -429,35 +435,30 @@ module Souls
|
|
|
429
435
|
end
|
|
430
436
|
EOS
|
|
431
437
|
end
|
|
432
|
-
|
|
438
|
+
file_path
|
|
433
439
|
end
|
|
434
440
|
|
|
435
|
-
def create_confirm
|
|
436
|
-
puts "Directory already exists, Overwrite?? (Y/N)"
|
|
441
|
+
def create_confirm dir_path: ""
|
|
442
|
+
puts "Directory already exists, Overwrite?? (Y/N)\n#{dir_path}"
|
|
437
443
|
input = STDIN.gets.chomp
|
|
438
444
|
return true if input == "Y"
|
|
439
|
-
raise StandardError.new "Directory Already Exist
|
|
445
|
+
raise StandardError.new "Directory Already Exist!\n#{dir_path}"
|
|
440
446
|
end
|
|
441
447
|
|
|
442
448
|
def mutation class_name: "souls"
|
|
443
449
|
singularized_class_name = class_name.singularize
|
|
444
450
|
if Dir.exist? "./app/graphql/mutations/#{singularized_class_name}"
|
|
445
|
-
create_confirm
|
|
451
|
+
create_confirm dir_path: "./app/graphql/mutations/#{singularized_class_name}"
|
|
446
452
|
FileUtils.rm_r("./app/graphql/mutations/#{singularized_class_name}")
|
|
447
453
|
end
|
|
448
454
|
Dir.mkdir "./app/graphql/mutations/#{singularized_class_name}"
|
|
449
455
|
create_mutation_head class_name: singularized_class_name
|
|
450
456
|
create_mutation_params class_name: singularized_class_name
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
puts "\n\n"
|
|
457
|
-
puts "field :create_#{singularized_class_name}, mutation: Mutations::#{singularized_class_name.camelize}::Create#{singularized_class_name.camelize}"
|
|
458
|
-
puts "field :update_#{singularized_class_name}, mutation: Mutations::#{singularized_class_name.camelize}::Update#{singularized_class_name.camelize}"
|
|
459
|
-
puts "field :delete_#{singularized_class_name}, mutation: Mutations::#{singularized_class_name.camelize}::Delete#{singularized_class_name.camelize}"
|
|
460
|
-
puts "\n\n#############################################################################################################"
|
|
457
|
+
[
|
|
458
|
+
create_mutation_end(class_name: singularized_class_name),
|
|
459
|
+
update_mutation(class_name: singularized_class_name),
|
|
460
|
+
delete_mutation(class_name: singularized_class_name)
|
|
461
|
+
]
|
|
461
462
|
end
|
|
462
463
|
|
|
463
464
|
def create_query class_name: "souls"
|
|
@@ -477,7 +478,7 @@ module Souls
|
|
|
477
478
|
end
|
|
478
479
|
EOS
|
|
479
480
|
end
|
|
480
|
-
|
|
481
|
+
file_path
|
|
481
482
|
end
|
|
482
483
|
|
|
483
484
|
def create_queries class_name: "souls"
|
|
@@ -497,20 +498,13 @@ module Souls
|
|
|
497
498
|
end
|
|
498
499
|
end
|
|
499
500
|
EOS
|
|
500
|
-
|
|
501
|
+
file_path
|
|
501
502
|
end
|
|
502
503
|
end
|
|
503
504
|
|
|
504
505
|
def query class_name: "souls"
|
|
505
506
|
singularized_class_name = class_name.singularize
|
|
506
|
-
create_query class_name: singularized_class_name
|
|
507
|
-
create_queries class_name: singularized_class_name
|
|
508
|
-
puts "\n#############################################################################################################"
|
|
509
|
-
puts "\nAdd these lines at `./app/graphql/types/query_type.rb`"
|
|
510
|
-
puts "\n\n"
|
|
511
|
-
puts "field :#{singularized_class_name}, resolber: Queries::#{singularized_class_name.camelize}"
|
|
512
|
-
puts "field :#{singularized_class_name.pluralize}, Types::#{singularized_class_name.camelize}Type.connection_type, null: true"
|
|
513
|
-
puts "\n\n#############################################################################################################"
|
|
507
|
+
[create_query(class_name: singularized_class_name), create_queries(class_name: singularized_class_name)]
|
|
514
508
|
end
|
|
515
509
|
|
|
516
510
|
def create_type_head class_name: "souls"
|
|
@@ -534,8 +528,9 @@ module Souls
|
|
|
534
528
|
f.each_line.with_index do |line, i|
|
|
535
529
|
if @on
|
|
536
530
|
new_line.write "\n" && break if line.include?("end") || line.include?("t.index")
|
|
531
|
+
field = "[String]" if line.include?("array: true")
|
|
537
532
|
type, name = line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
|
|
538
|
-
field
|
|
533
|
+
field ||= type_check type
|
|
539
534
|
new_line.write " field :#{name}, #{field}, null: true\n"
|
|
540
535
|
end
|
|
541
536
|
if table_check(line: line, class_name: class_name)
|
|
@@ -555,7 +550,7 @@ module Souls
|
|
|
555
550
|
end
|
|
556
551
|
EOS
|
|
557
552
|
end
|
|
558
|
-
|
|
553
|
+
[file_path]
|
|
559
554
|
end
|
|
560
555
|
|
|
561
556
|
def type class_name: "souls"
|
|
@@ -584,8 +579,9 @@ module Souls
|
|
|
584
579
|
f.each_line.with_index do |line, i|
|
|
585
580
|
if @on
|
|
586
581
|
new_line.write "\n" && break if line.include?("end") || line.include?("t.index")
|
|
582
|
+
field = '["tag1", "tag2", "tag3"]' if line.include?("array: true")
|
|
587
583
|
type, name = line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
|
|
588
|
-
field
|
|
584
|
+
field ||= get_test_type type
|
|
589
585
|
new_line.write " #{name} { #{field} }\n"
|
|
590
586
|
end
|
|
591
587
|
if table_check(line: line, class_name: class_name)
|
|
@@ -604,7 +600,7 @@ module Souls
|
|
|
604
600
|
end
|
|
605
601
|
EOS
|
|
606
602
|
end
|
|
607
|
-
|
|
603
|
+
[file_path]
|
|
608
604
|
end
|
|
609
605
|
|
|
610
606
|
def rspec_factory class_name: "souls"
|
|
@@ -620,17 +616,12 @@ module Souls
|
|
|
620
616
|
f.write <<~EOS
|
|
621
617
|
RSpec.describe #{class_name.camelize}, type: :model do
|
|
622
618
|
it "作成する" do
|
|
623
|
-
expect(FactoryBot.build(:#{class_name})).to be_valid
|
|
624
|
-
end
|
|
625
|
-
|
|
626
|
-
it "同じtitleがあると作成できない" do
|
|
627
|
-
FactoryBot.build(:#{class_name}, title: "hey")
|
|
628
|
-
expect(FactoryBot.build(:#{class_name}, title: "hey")).to be_valid
|
|
619
|
+
expect(FactoryBot.build(:#{class_name.singularize})).to be_valid
|
|
629
620
|
end
|
|
630
621
|
end
|
|
631
622
|
EOS
|
|
632
623
|
end
|
|
633
|
-
|
|
624
|
+
[file_path]
|
|
634
625
|
end
|
|
635
626
|
|
|
636
627
|
def rspec_mutation class_name: "souls"
|
|
@@ -673,15 +664,107 @@ module Souls
|
|
|
673
664
|
# let's do this later
|
|
674
665
|
end
|
|
675
666
|
|
|
676
|
-
def
|
|
677
|
-
|
|
678
|
-
model class_name:
|
|
679
|
-
type class_name:
|
|
680
|
-
rspec_factory class_name:
|
|
681
|
-
rspec_model class_name:
|
|
682
|
-
query class_name:
|
|
683
|
-
mutation class_name:
|
|
667
|
+
def migrate class_name: "souls"
|
|
668
|
+
singularized_class_name = class_name.singularize
|
|
669
|
+
model_paths = model class_name: singularized_class_name
|
|
670
|
+
type_paths = type class_name: singularized_class_name
|
|
671
|
+
rspec_factory_paths = rspec_factory class_name: singularized_class_name
|
|
672
|
+
rspec_model_paths = rspec_model class_name: singularized_class_name
|
|
673
|
+
query_path = query class_name: singularized_class_name
|
|
674
|
+
mutation_path = mutation class_name: singularized_class_name
|
|
675
|
+
[
|
|
676
|
+
model: model_paths,
|
|
677
|
+
type: type_paths,
|
|
678
|
+
rspec_factory: rspec_factory_paths,
|
|
679
|
+
rspec_model: rspec_model_paths,
|
|
680
|
+
query: query_path,
|
|
681
|
+
mutation: mutation_path,
|
|
682
|
+
add_query_type: [
|
|
683
|
+
"field :#{singularized_class_name}, resolver: Queries::#{singularized_class_name.camelize}",
|
|
684
|
+
"field :#{singularized_class_name.pluralize}, Types::#{singularized_class_name.camelize}Type.connection_type, null: true"
|
|
685
|
+
],
|
|
686
|
+
add_mutation_type: [
|
|
687
|
+
"field :create_#{singularized_class_name}, mutation: Mutations::#{singularized_class_name.camelize}::Create#{singularized_class_name.camelize}",
|
|
688
|
+
"field :update_#{singularized_class_name}, mutation: Mutations::#{singularized_class_name.camelize}::Update#{singularized_class_name.camelize}",
|
|
689
|
+
"field :delete_#{singularized_class_name}, mutation: Mutations::#{singularized_class_name.camelize}::Delete#{singularized_class_name.camelize}"
|
|
690
|
+
]
|
|
691
|
+
]
|
|
692
|
+
end
|
|
693
|
+
|
|
694
|
+
def migrate_all
|
|
695
|
+
puts "◆◆◆ Let's Auto Generate CRUD API ◆◆◆\n"
|
|
696
|
+
`rake db:migrate`
|
|
697
|
+
paths = get_tables.map do |class_name|
|
|
698
|
+
migrate class_name: class_name.singularize
|
|
699
|
+
end
|
|
700
|
+
puts "\n============== Model ======================\n\n"
|
|
701
|
+
paths.each do |class_name|
|
|
702
|
+
class_name.each do |path|
|
|
703
|
+
path[:model].each { |line| puts line }
|
|
704
|
+
end
|
|
705
|
+
end
|
|
706
|
+
puts "\n============== Type =======================\n\n"
|
|
707
|
+
paths.each do |class_name|
|
|
708
|
+
class_name.each do |path|
|
|
709
|
+
path[:type].each { |line| puts line }
|
|
710
|
+
end
|
|
711
|
+
end
|
|
712
|
+
puts "\n============== FactoryBot =================\n\n"
|
|
713
|
+
paths.each do |class_name|
|
|
714
|
+
class_name.each do |path|
|
|
715
|
+
path[:rspec_factory].each { |line| puts line }
|
|
716
|
+
end
|
|
717
|
+
end
|
|
718
|
+
puts "\n============== RspecModel =================\n\n"
|
|
719
|
+
paths.each do |class_name|
|
|
720
|
+
class_name.each do |path|
|
|
721
|
+
path[:rspec_model].each { |line| puts line }
|
|
722
|
+
end
|
|
723
|
+
end
|
|
724
|
+
puts "\n============== Query ======================\n\n"
|
|
725
|
+
paths.each do |class_name|
|
|
726
|
+
class_name.each do |path|
|
|
727
|
+
path[:query].each { |line| puts line }
|
|
728
|
+
end
|
|
729
|
+
end
|
|
730
|
+
puts "\n============== Mutation ===================\n\n"
|
|
731
|
+
paths.each do |class_name|
|
|
732
|
+
class_name.each do |path|
|
|
733
|
+
path[:mutation].each { |line| puts line }
|
|
734
|
+
end
|
|
735
|
+
end
|
|
736
|
+
puts "\nAll files created from ./db/schema.rb"
|
|
737
|
+
puts "\n\n"
|
|
738
|
+
puts "\n##########################################################\n"
|
|
739
|
+
puts "# #\n"
|
|
740
|
+
puts "# Add These Lines at ./app/graphql/types/query_type.rb #\n"
|
|
741
|
+
puts "# #\n"
|
|
742
|
+
puts "##########################################################\n\n\n"
|
|
743
|
+
paths.each do |class_name|
|
|
744
|
+
class_name.each do |path|
|
|
745
|
+
path[:add_query_type].each { |line| puts line }
|
|
746
|
+
end
|
|
747
|
+
end
|
|
748
|
+
puts "\n\n##Connection Type\n\n"
|
|
749
|
+
get_tables.each do |class_name|
|
|
750
|
+
puts <<~EOS
|
|
751
|
+
def #{class_name.pluralize}
|
|
752
|
+
#{class_name.camelize}.all.order(id: :desc)
|
|
753
|
+
end
|
|
754
|
+
\n
|
|
755
|
+
EOS
|
|
756
|
+
end
|
|
757
|
+
puts "\n#############################################################\n"
|
|
758
|
+
puts "# #\n"
|
|
759
|
+
puts "# Add These Lines at ./app/graphql/types/mutation_type.rb #\n"
|
|
760
|
+
puts "# #\n"
|
|
761
|
+
puts "#############################################################\n\n\n"
|
|
762
|
+
paths.each do |class_name|
|
|
763
|
+
class_name.each do |path|
|
|
764
|
+
path[:add_mutation_type].each { |line| puts line }
|
|
765
|
+
end
|
|
766
|
+
end
|
|
684
767
|
end
|
|
685
768
|
end
|
|
686
769
|
end
|
|
687
|
-
end
|
|
770
|
+
end
|
data/lib/souls/version.rb
CHANGED