souls 0.9.2 → 0.9.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 75064881212497375ac7f55321f3fdc9c795b51b0d7b3cd17964efa744acf8a9
4
- data.tar.gz: 14fd24e84cd0bd2062bc3644eb543e542dbe89d60c51c18e657e2f32d02866c9
3
+ metadata.gz: 6a8efc84721906b20b73fad75d05827e7c2f5a1a0807f73004ef29bd3e0ef9c7
4
+ data.tar.gz: d2b21b116edab2cf8b769ebf59c503f1caf3fa455a6a65dede7576014152e249
5
5
  SHA512:
6
- metadata.gz: 141abafb886a0edd0b4b98a76f13547974244c9847fa028553617c730098bcec839a653dbc84e1e78a025cda4cd5e8f09cc9d3dafdce4bbdff4a6af02897dfe5
7
- data.tar.gz: edd609ace5b59bd45a92245dc481ab14289cf5d4a234883af8533bef6176ce4ce156b056af7aaedcfe853796ac30665755ef313c223c45eeb1c02e5eacba7f72
6
+ metadata.gz: f7b4c568802ba5da4d843183077e1fc317ab8314bef75d8fa0c6aec00d57204ad27942fd732d0e6f91e2496996dc87ff77a3332b2b0083762d54a28823a2bb3b
7
+ data.tar.gz: 7b99e59bfe3d8a1aeb76d468be9d66d622b81ca03bc682ac83683061accb152e33483fa2541336ca0aa1aa1ec6a55c8da1b98e4f73693809cda1ad72473d5d9d
@@ -133,7 +133,7 @@ Metrics/AbcSize:
133
133
  Enabled: false
134
134
 
135
135
  Metrics/CyclomaticComplexity:
136
- Max: 10
136
+ Max: 30
137
137
 
138
138
  Metrics/PerceivedComplexity:
139
139
  Enabled: false
@@ -203,4 +203,6 @@ Style/DateTime:
203
203
  Enabled: false
204
204
  Layout/HeredocIndentation:
205
205
  Exclude:
206
- - "lib/souls/init.rb"
206
+ - "lib/souls/init.rb"
207
+ Style/RaiseArgs:
208
+ Enabled: false
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- souls (0.9.1)
4
+ souls (0.9.6)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/exe/souls CHANGED
@@ -48,7 +48,7 @@ begin
48
48
  when "g", "generate"
49
49
  case ARGV[1]
50
50
  when "test"
51
- Souls::Init.delete_mutation class_name: "article"
51
+ Souls::Init.get_tables
52
52
  when "model"
53
53
  Souls::Init.model class_name: ARGV[2]
54
54
  when "mutation"
@@ -58,7 +58,9 @@ begin
58
58
  when "type"
59
59
  Souls::Init.type class_name: ARGV[2]
60
60
  when "migrate"
61
- Souls::Init.migration class_name: ARGV[2]
61
+ Souls::Init.migrate class_name: ARGV[2]
62
+ when "migrate_all"
63
+ Souls::Init.migrate_all
62
64
  when "migration"
63
65
  `rake db:create_migration NAME=#{ARGV[3]}`
64
66
  when "rspec_factory"
@@ -74,22 +76,16 @@ begin
74
76
  else
75
77
  end
76
78
  when "t", "test"
77
- case ARGV[1]
78
- when "-r"
79
- `bundle exec rspec`
80
- when "-s"
81
- `bundle exec steep check`
82
- else
83
- `rubocop`
84
- `bundle exec rspec`
85
- end
79
+ puts `rubocop`
80
+ puts `bundle exec rspec`
86
81
  when "deploy"
87
82
  project_id = Souls.configuration.project_id
88
83
  `gcloud builds submit --config=cloudbuild.yml --project #{project_id}`
89
84
  else
90
- puts "Welcome to Souls!Yeah!"
85
+ puts "Welcome to SOULs!"
91
86
  end
92
87
  rescue StandardError => error
93
88
  puts error
94
- puts "Thank you!Souls!"
89
+ puts "Thank you!!"
90
+ puts "SOULs"
95
91
  end
@@ -2,6 +2,7 @@ require "souls/version"
2
2
  require "souls/init"
3
3
  require "json"
4
4
  require "active_support/core_ext/string/inflections"
5
+ require "fileutils"
5
6
 
6
7
  module Souls
7
8
  class Error < StandardError; end
@@ -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 "=============================="
@@ -251,13 +251,14 @@ module Souls
251
251
  end
252
252
  EOS
253
253
  end
254
- puts "Model #{class_name}.rb Auto Generated from schema.rb!: `#{file_path}`"
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",
263
264
  boolean: "Boolean",
@@ -268,6 +269,7 @@ module Souls
268
269
  def get_test_type type
269
270
  {
270
271
  bigint: 1,
272
+ float: 4.2,
271
273
  string: '"MyString"',
272
274
  text: '"MyString"',
273
275
  datetime: "Time.now",
@@ -277,27 +279,28 @@ module Souls
277
279
  end
278
280
 
279
281
  def table_check line: "", class_name: ""
280
- if line.include?("create_table")
281
- return true if line.split(" ")[1].gsub("\"", "").gsub(",", "") == "#{class_name.pluralize}"
282
+ if line.include?("create_table") && (line.split(" ")[1].gsub("\"", "").gsub(",", "") == class_name.pluralize.to_s)
283
+ return true
282
284
  end
283
285
  false
284
286
  end
285
287
 
286
288
  def create_mutation_head class_name: "souls"
287
- file_path = "./app/graphql/mutations/create_#{class_name}.rb"
289
+ file_path = "./app/graphql/mutations/#{class_name}/create_#{class_name}.rb"
288
290
  File.open(file_path, "w") do |new_line|
289
291
  new_line.write <<~EOS
290
292
  module Mutations
291
- class Create#{class_name.camelize} < BaseMutation
292
- field :#{class_name}, Types::#{class_name.camelize}Type, null: false
293
- field :error, String, null: true
293
+ module #{class_name.camelize}
294
+ class Create#{class_name.camelize} < BaseMutation
295
+ field :#{class_name}, Types::#{class_name.camelize}Type, null: false
296
+ field :error, String, null: true
294
297
 
295
298
  EOS
296
299
  end
297
300
  end
298
301
 
299
302
  def create_mutation_params class_name: "souls"
300
- file_path = "./app/graphql/mutations/create_#{class_name}.rb"
303
+ file_path = "./app/graphql/mutations/#{class_name}/create_#{class_name}.rb"
301
304
  path = "./db/schema.rb"
302
305
  @on = false
303
306
  File.open(file_path, "a") do |new_line|
@@ -305,13 +308,14 @@ module Souls
305
308
  f.each_line.with_index do |line, i|
306
309
  if @on
307
310
  break if line.include?("end") || line.include?("t.index")
311
+ field = "[String]" if line.include?("array: true")
308
312
  type, name = line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
309
- field = type_check type
313
+ field ||= type_check type
310
314
  case name
311
315
  when "created_at", "updated_at"
312
316
  next
313
317
  else
314
- new_line.write " argument :#{name}, #{field}, required: false\n"
318
+ new_line.write " argument :#{name}, #{field}, required: false\n"
315
319
  end
316
320
  end
317
321
  @on = true if table_check(line: line, class_name: class_name)
@@ -321,41 +325,43 @@ module Souls
321
325
  end
322
326
 
323
327
  def create_mutation_end class_name: "souls"
324
- file_path = "./app/graphql/mutations/create_#{class_name}.rb"
328
+ file_path = "./app/graphql/mutations/#{class_name}/create_#{class_name}.rb"
325
329
  File.open(file_path, "a") do |new_line|
326
330
  new_line.write <<~EOS
327
331
 
328
- def resolve **args
329
- #{class_name} = #{class_name.camelize}.new args
330
- if #{class_name}.save
331
- { #{class_name}: #{class_name} }
332
- else
333
- { error: #{class_name}.errors.full_messages }
332
+ def resolve **args
333
+ #{class_name} = #{class_name.camelize}.new args
334
+ if #{class_name}.save
335
+ { #{class_name}: #{class_name} }
336
+ else
337
+ { error: #{class_name}.errors.full_messages }
338
+ end
339
+ rescue StandardError => error
340
+ GraphQL::ExecutionError.new error
334
341
  end
335
- rescue StandardError => error
336
- GraphQL::ExecutionError.new error
337
342
  end
338
343
  end
339
344
  end
340
345
  EOS
341
346
  end
342
- puts "Mutation create_#{class_name}.rb Auto Generated from schema.rb!: `#{file_path}`"
347
+ file_path
343
348
  end
344
349
 
345
350
  def update_mutation_head class_name: "souls"
346
- file_path = "./app/graphql/mutations/update_#{class_name}.rb"
351
+ file_path = "./app/graphql/mutations/#{class_name}/update_#{class_name}.rb"
347
352
  File.open(file_path, "w") do |new_line|
348
353
  new_line.write <<~EOS
349
354
  module Mutations
350
- class Update#{class_name.camelize} < BaseMutation
351
- field :#{class_name}, Types::#{class_name.camelize}Type, null: false
355
+ module #{class_name.camelize}
356
+ class Update#{class_name.camelize} < BaseMutation
357
+ field :#{class_name}, Types::#{class_name.camelize}Type, null: false
352
358
 
353
359
  EOS
354
360
  end
355
361
  end
356
362
 
357
363
  def update_mutation_params class_name: "souls"
358
- file_path = "./app/graphql/mutations/update_#{class_name}.rb"
364
+ file_path = "./app/graphql/mutations/#{class_name}/update_#{class_name}.rb"
359
365
  path = "./db/schema.rb"
360
366
  @on = false
361
367
  File.open(file_path, "a") do |new_line|
@@ -363,13 +369,14 @@ module Souls
363
369
  f.each_line.with_index do |line, i|
364
370
  if @on
365
371
  break if line.include?("end") || line.include?("t.index")
372
+ field = "[String]" if line.include?("array: true")
366
373
  type, name = line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
367
- field = type_check type
374
+ field ||= type_check type
368
375
  case name
369
376
  when "created_at", "updated_at"
370
377
  next
371
378
  else
372
- new_line.write " argument :#{name}, #{field}, required: false\n"
379
+ new_line.write " argument :#{name}, #{field}, required: false\n"
373
380
  end
374
381
  end
375
382
  @on = true if table_check(line: line, class_name: class_name)
@@ -379,22 +386,23 @@ module Souls
379
386
  end
380
387
 
381
388
  def update_mutation_end class_name: "souls"
382
- file_path = "./app/graphql/mutations/update_#{class_name}.rb"
389
+ file_path = "./app/graphql/mutations/#{class_name}/update_#{class_name}.rb"
383
390
  File.open(file_path, "a") do |new_line|
384
391
  new_line.write <<~EOS
385
392
 
386
- def resolve **args
387
- #{class_name} = #{class_name.camelize}.find args[:id]
388
- #{class_name}.update args
389
- { #{class_name}: #{class_name.camelize}.find(args[:id]) }
390
- rescue StandardError => error
391
- GraphQL::ExecutionError.new error
393
+ def resolve **args
394
+ #{class_name} = #{class_name.camelize}.find args[:id]
395
+ #{class_name}.update args
396
+ { #{class_name}: #{class_name.camelize}.find(args[:id]) }
397
+ rescue StandardError => error
398
+ GraphQL::ExecutionError.new error
399
+ end
392
400
  end
393
401
  end
394
402
  end
395
403
  EOS
396
404
  end
397
- puts "Mutation update_#{class_name}.rb Auto Generated from schema.rb!: `#{file_path}`"
405
+ file_path
398
406
  end
399
407
 
400
408
  def update_mutation class_name: "souls"
@@ -404,35 +412,51 @@ module Souls
404
412
  end
405
413
 
406
414
  def delete_mutation class_name: "souls"
407
- file_path = "./app/graphql/mutations/delete_#{class_name}.rb"
415
+ file_path = "./app/graphql/mutations/#{class_name}/delete_#{class_name}.rb"
408
416
  File.open(file_path, "w") do |f|
409
417
  f.write <<~EOS
410
418
  module Mutations
411
- class Delete#{class_name.camelize} < BaseMutation
412
- field :#{class_name}, Types::#{class_name.camelize}Type, null: false
413
- argument :id, Integer, required: true
414
-
415
- def resolve id:
416
- #{class_name} = #{class_name.camelize}.find id
417
- #{class_name}.destroy
418
- { #{class_name}: #{class_name} }
419
- rescue StandardError => error
420
- GraphQL::ExecutionError.new error
419
+ module #{class_name.camelize}
420
+ class Delete#{class_name.camelize} < BaseMutation
421
+ field :#{class_name}, Types::#{class_name.camelize}Type, null: false
422
+ argument :id, Integer, required: true
423
+
424
+ def resolve id:
425
+ #{class_name} = #{class_name.camelize}.find id
426
+ #{class_name}.destroy
427
+ { #{class_name}: #{class_name} }
428
+ rescue StandardError => error
429
+ GraphQL::ExecutionError.new error
430
+ end
421
431
  end
422
432
  end
423
433
  end
424
434
  EOS
425
435
  end
426
- puts "Mutation create_#{class_name}.rb Auto Generated from schema.rb!: `#{file_path}`"
436
+ file_path
437
+ end
438
+
439
+ def create_confirm
440
+ puts "Directory already exists, Overwrite?? (Y/N)"
441
+ input = STDIN.gets.chomp
442
+ return true if input == "Y"
443
+ raise StandardError.new "Directory Already Exist!"
427
444
  end
428
445
 
429
446
  def mutation class_name: "souls"
430
447
  singularized_class_name = class_name.singularize
448
+ if Dir.exist? "./app/graphql/mutations/#{singularized_class_name}"
449
+ # create_confirm
450
+ FileUtils.rm_r("./app/graphql/mutations/#{singularized_class_name}")
451
+ end
452
+ Dir.mkdir "./app/graphql/mutations/#{singularized_class_name}"
431
453
  create_mutation_head class_name: singularized_class_name
432
454
  create_mutation_params class_name: singularized_class_name
433
- create_mutation_end class_name: singularized_class_name
434
- update_mutation class_name: singularized_class_name
435
- delete_mutation class_name: singularized_class_name
455
+ [
456
+ create_mutation_end(class_name: singularized_class_name),
457
+ update_mutation(class_name: singularized_class_name),
458
+ delete_mutation(class_name: singularized_class_name)
459
+ ]
436
460
  end
437
461
 
438
462
  def create_query class_name: "souls"
@@ -452,7 +476,7 @@ module Souls
452
476
  end
453
477
  EOS
454
478
  end
455
- puts "Query #{class_name}.rb Auto Generated from schema.rb!: `#{file_path}`"
479
+ file_path
456
480
  end
457
481
 
458
482
  def create_queries class_name: "souls"
@@ -472,14 +496,13 @@ module Souls
472
496
  end
473
497
  end
474
498
  EOS
475
- puts "Query #{class_name.pluralize}.rb Auto Generated from schema.rb!: `#{file_path}`"
499
+ file_path
476
500
  end
477
501
  end
478
502
 
479
503
  def query class_name: "souls"
480
504
  singularized_class_name = class_name.singularize
481
- create_query class_name: singularized_class_name
482
- create_queries class_name: singularized_class_name
505
+ [create_query(class_name: singularized_class_name), create_queries(class_name: singularized_class_name)]
483
506
  end
484
507
 
485
508
  def create_type_head class_name: "souls"
@@ -524,7 +547,7 @@ module Souls
524
547
  end
525
548
  EOS
526
549
  end
527
- puts "Type #{class_name}_type.rb Auto Generated from schema.rb!: `#{file_path}`"
550
+ [file_path]
528
551
  end
529
552
 
530
553
  def type class_name: "souls"
@@ -573,7 +596,7 @@ module Souls
573
596
  end
574
597
  EOS
575
598
  end
576
- puts "FactoryBot #{class_name.pluralize}.rb Auto Generated from schema.rb!: `#{file_path}`"
599
+ [file_path]
577
600
  end
578
601
 
579
602
  def rspec_factory class_name: "souls"
@@ -589,17 +612,12 @@ module Souls
589
612
  f.write <<~EOS
590
613
  RSpec.describe #{class_name.camelize}, type: :model do
591
614
  it "作成する" do
592
- expect(FactoryBot.build(:#{class_name})).to be_valid
593
- end
594
-
595
- it "同じtitleがあると作成できない" do
596
- FactoryBot.build(:#{class_name}, title: "hey")
597
- expect(FactoryBot.build(:#{class_name}, title: "hey")).to be_valid
615
+ expect(FactoryBot.build(:#{class_name.singularize})).to be_valid
598
616
  end
599
617
  end
600
618
  EOS
601
619
  end
602
- puts "Rspec #{class_name}_spec.rb Auto Generated from schema.rb!: `#{file_path}`"
620
+ [file_path]
603
621
  end
604
622
 
605
623
  def rspec_mutation class_name: "souls"
@@ -623,6 +641,17 @@ module Souls
623
641
  end
624
642
  end
625
643
 
644
+ def get_tables
645
+ path = "./db/schema.rb"
646
+ tables = []
647
+ File.open(path, "r") do |f|
648
+ f.each_line.with_index do |line, i|
649
+ tables << line.split("\"")[1] if line.include?("create_table")
650
+ end
651
+ end
652
+ tables
653
+ end
654
+
626
655
  def add_mutation_type class_name: "souls"
627
656
  # let's do this later
628
657
  end
@@ -631,15 +660,98 @@ module Souls
631
660
  # let's do this later
632
661
  end
633
662
 
634
- def migration class_name: "souls"
635
- `rake db:migrate`
636
- model class_name: class_name
637
- mutation class_name: class_name
638
- query class_name: class_name
639
- type class_name: class_name
640
- rspec_factory class_name: class_name
641
- rspec_model class_name: class_name
663
+ def migrate class_name: "souls"
664
+ # `rake db:migrate`
665
+ singularized_class_name = class_name.singularize
666
+ model_paths = model class_name: singularized_class_name
667
+ type_paths = type class_name: singularized_class_name
668
+ rspec_factory_paths = rspec_factory class_name: singularized_class_name
669
+ rspec_model_paths = rspec_model class_name: singularized_class_name
670
+ query_path = query class_name: singularized_class_name
671
+ mutation_path = mutation class_name: singularized_class_name
672
+ [
673
+ model: model_paths,
674
+ type: type_paths,
675
+ rspec_factory: rspec_factory_paths,
676
+ rspec_model: rspec_model_paths,
677
+ query: query_path,
678
+ mutation: mutation_path,
679
+ add_query_type: [
680
+ "field :#{singularized_class_name}, resolver: Queries::#{singularized_class_name.camelize}",
681
+ "field :#{singularized_class_name.pluralize}, Types::#{singularized_class_name.camelize}Type.connection_type, null: true"
682
+ ],
683
+ add_mutation_type: [
684
+ "field :create_#{singularized_class_name}, mutation: Mutations::#{singularized_class_name.camelize}::Create#{singularized_class_name.camelize}",
685
+ "field :update_#{singularized_class_name}, mutation: Mutations::#{singularized_class_name.camelize}::Update#{singularized_class_name.camelize}",
686
+ "field :delete_#{singularized_class_name}, mutation: Mutations::#{singularized_class_name.camelize}::Delete#{singularized_class_name.camelize}"
687
+ ]
688
+ ]
689
+ end
690
+
691
+ def migrate_all
692
+ puts "◆◆◆ Let's Auto Generate CRUD API ◆◆◆\n"
693
+ paths = get_tables.map do |class_name|
694
+ migrate class_name: class_name
695
+ end
696
+ puts "\n============== Model ======================\n\n"
697
+ paths.each do |class_name|
698
+ class_name.each do |path|
699
+ path[:model].each { |line| puts line }
700
+ end
701
+ end
702
+ puts "\n============== Type =======================\n\n"
703
+ paths.each do |class_name|
704
+ class_name.each do |path|
705
+ path[:type].each { |line| puts line }
706
+ end
707
+ end
708
+ puts "\n============== FactoryBot =================\n\n"
709
+ paths.each do |class_name|
710
+ class_name.each do |path|
711
+ path[:rspec_factory].each { |line| puts line }
712
+ end
713
+ end
714
+ puts "\n============== RspecModel =================\n\n"
715
+ paths.each do |class_name|
716
+ class_name.each do |path|
717
+ path[:rspec_model].each { |line| puts line }
718
+ end
719
+ end
720
+ puts "\n============== Query ======================\n\n"
721
+ paths.each do |class_name|
722
+ class_name.each do |path|
723
+ path[:query].each { |line| puts line }
724
+ end
725
+ end
726
+ puts "\n============== Mutation ===================\n\n"
727
+ paths.each do |class_name|
728
+ class_name.each do |path|
729
+ path[:mutation].each { |line| puts line }
730
+ end
731
+ end
732
+ puts "\nAll files created from ./db/schema.rb"
733
+ puts "\n\n"
734
+ puts "\n##########################################################\n"
735
+ puts "# #\n"
736
+ puts "# Add These Lines at ./app/graphql/types/query_type.rb #\n"
737
+ puts "# #\n"
738
+ puts "##########################################################\n\n\n"
739
+ paths.each do |class_name|
740
+ class_name.each do |path|
741
+ path[:add_query_type].each { |line| puts line }
742
+ end
743
+ end
744
+ puts "\n#############################################################\n"
745
+ puts "# #\n"
746
+ puts "# Add These Lines at ./app/graphql/types/mutation_type.rb #\n"
747
+ puts "# #\n"
748
+ puts "#############################################################\n\n\n"
749
+ paths.each do |class_name|
750
+ class_name.each do |path|
751
+ path[:add_mutation_type].each { |line| puts line }
752
+ end
753
+ end
642
754
  end
643
755
  end
644
756
  end
645
- end
757
+ end
@@ -1,3 +1,3 @@
1
1
  module Souls
2
- VERSION = "0.9.2"
2
+ VERSION = "0.9.8"
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.9.2
4
+ version: 0.9.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-01-21 00:00:00.000000000 Z
13
+ date: 2021-01-22 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.