souls 0.8.6 → 0.9.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 87b717736b09f7fb0d8c595800e4beb6ab622b8664b6fba6391ee94b45f6ed3d
4
- data.tar.gz: b112ea068f7dea6fc23f1f417b8e61e52b87fe35056f26bc5a5f950071efa147
3
+ metadata.gz: 8a81eb0037a3eecde1f3b08c81a7b5e9d002bb87ba9ac6f490ec19b44497672a
4
+ data.tar.gz: c967ac41e70dc02bcad1d6ea2ccda92872cbb6e3acf58d4d54cca0a7869ffdbf
5
5
  SHA512:
6
- metadata.gz: 4bfb79e0fc7f341a3e9b05be8a3649d377a49e8af4d749dbbf156e0e06ff3c6dec9b2dba29d09428aee716a132d924baa9d1f6f7859542a575fc5fd9713a305b
7
- data.tar.gz: 893e1f5cbe6d46a581f08681eb13b9e6b1caadc5ce3b921b2294db5e8518ce0e6658a637331edf43120747152c3e2af188e13913be0fdf83533b544dd347e3d5
6
+ metadata.gz: 3ab6e0d9ccbb80eeb4c5f009348cd18aa1d23c18959e7bbe9624809517c8dbcf664b3582235f7f68aae5a349cffcc80ce2c652368f7071829f59ff2db25c3aca
7
+ data.tar.gz: 9e102bba2db1959a4ad11ac7cac8cbda25b8f4a2f39bc38389bf7bfaf24c6c41cc08f5deb53de718d8cfda9ca710aed8735a59ddcad4ecadb0646b4b7768d1bc
data/.gitignore CHANGED
@@ -14,4 +14,4 @@
14
14
  .irb_history
15
15
  /spec/
16
16
  /app/
17
-
17
+ /db/
@@ -198,4 +198,9 @@ Style/GlobalStdStream:
198
198
  Layout/IndentationConsistency:
199
199
  Enabled: false
200
200
  Layout/IndentationWidth:
201
- Enabled: false
201
+ Enabled: false
202
+ Style/DateTime:
203
+ Enabled: false
204
+ Layout/HeredocIndentation:
205
+ Exclude:
206
+ - "lib/souls/init.rb"
data/Gemfile CHANGED
@@ -3,6 +3,7 @@ source "https://rubygems.org"
3
3
  # Specify your gem's dependencies in souls.gemspec
4
4
  gemspec
5
5
 
6
+ gem "activesupport", "6.1.0"
6
7
  gem "rake", "13.0.3"
7
8
  gem "rspec", "3.1.0"
8
9
  gem "steep", "0.39.0"
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- souls (0.8.5)
4
+ souls (0.8.9)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -63,6 +63,7 @@ PLATFORMS
63
63
  ruby
64
64
 
65
65
  DEPENDENCIES
66
+ activesupport (= 6.1.0)
66
67
  rake (= 13.0.3)
67
68
  rspec (= 3.1.0)
68
69
  souls!
data/exe/souls CHANGED
@@ -47,6 +47,8 @@ begin
47
47
  puts Souls::VERSION
48
48
  when "g", "generate"
49
49
  case ARGV[1]
50
+ when "test"
51
+ Souls::Init.delete_mutation class_name: "article"
50
52
  when "model"
51
53
  Souls::Init.model class_name: ARGV[2]
52
54
  when "mutation"
@@ -55,8 +57,12 @@ begin
55
57
  Souls::Init.query class_name: ARGV[2]
56
58
  when "type"
57
59
  Souls::Init.type class_name: ARGV[2]
58
- when "migration"
60
+ when "migrate"
59
61
  Souls::Init.migration class_name: ARGV[2]
62
+ when "migration"
63
+ `rake db:create_migration NAME=#{ARGV[3]}`
64
+ when "rspec_factory"
65
+ Souls::Init.rspec_factory class_name: ARGV[2]
60
66
  when "rspec_model"
61
67
  Souls::Init.rspec_model class_name: ARGV[2]
62
68
  when "rspec_mutation"
@@ -74,7 +80,7 @@ begin
74
80
  when "-s"
75
81
  `bundle exec steep check`
76
82
  else
77
- `bundle exec steep check`
83
+ `bundle exec rubocop`
78
84
  `bundle exec rspec`
79
85
  end
80
86
  when "deploy"
@@ -1,6 +1,7 @@
1
1
  require "souls/version"
2
2
  require "souls/init"
3
3
  require "json"
4
+ require "active_support/core_ext/string/inflections"
4
5
 
5
6
  module Souls
6
7
  class Error < StandardError; end
@@ -247,31 +247,86 @@ module Souls
247
247
  file_path = "./app/models/#{class_name}.rb"
248
248
  File.open(file_path, "w") do |f|
249
249
  f.write <<~EOS
250
- class #{class_name.capitalize} < ActiveRecord::Base
250
+ class #{class_name.camelize} < ActiveRecord::Base
251
251
  end
252
252
  EOS
253
253
  end
254
- puts "model #{class_name}.rb created!: `#{file_path}`"
254
+ puts "Model #{class_name}.rb Auto Generated from schema.rb!: `#{file_path}`"
255
255
  end
256
256
 
257
- def mutation class_name: "souls"
257
+ def type_check type
258
+ {
259
+ bigint: "Integer",
260
+ string: "String",
261
+ text: "String",
262
+ datetime: "GraphQL::Types::ISO8601DateTime",
263
+ boolean: "Boolean",
264
+ integer: "Integer"
265
+ }[type.to_sym]
266
+ end
267
+
268
+ def get_test_type type
269
+ {
270
+ bigint: 1,
271
+ string: '"MyString"',
272
+ text: '"MyString"',
273
+ datetime: "Time.now",
274
+ boolean: false,
275
+ integer: 1
276
+ }[type.to_sym]
277
+ end
278
+
279
+ 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
+ end
283
+ false
284
+ end
285
+
286
+ def create_mutation_head class_name: "souls"
258
287
  file_path = "./app/graphql/mutations/create_#{class_name}.rb"
259
- File.open(file_path, "w") do |f|
260
- f.write <<~EOS
288
+ File.open(file_path, "w") do |new_line|
289
+ new_line.write <<~EOS
261
290
  module Mutations
262
- class Create#{class_name.capitalize} < BaseMutation
263
- field :#{class_name}, Types::#{class_name.capitalize}Type, null: false
291
+ class Create#{class_name.camelize} < BaseMutation
292
+ field :#{class_name}, Types::#{class_name.camelize}Type, null: false
264
293
  field :error, String, null: true
265
294
 
266
- ## Change argument as you needed
267
- # argument :id, Integer, required: true
268
- # argument :title, String, required: true
269
- # argument :tag, [String], required: false
270
- # argument :is_public, Boolean, required: true
271
- # argument :public_date, GraphQL::Types::ISO8601DateTime, required: true
295
+ EOS
296
+ end
297
+ end
298
+
299
+ def create_mutation_params class_name: "souls"
300
+ file_path = "./app/graphql/mutations/create_#{class_name}.rb"
301
+ path = "./db/schema.rb"
302
+ @on = false
303
+ File.open(file_path, "a") do |new_line|
304
+ File.open(path, "r") do |f|
305
+ f.each_line.with_index do |line, i|
306
+ if @on
307
+ break if line.include?("end") || line.include?("t.index")
308
+ type, name = line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
309
+ field = type_check type
310
+ case name
311
+ when "created_at", "updated_at"
312
+ next
313
+ else
314
+ new_line.write " argument :#{name}, #{field}, required: false\n"
315
+ end
316
+ end
317
+ @on = true if table_check(line: line, class_name: class_name)
318
+ end
319
+ end
320
+ end
321
+ end
322
+
323
+ def create_mutation_end class_name: "souls"
324
+ file_path = "./app/graphql/mutations/create_#{class_name}.rb"
325
+ File.open(file_path, "a") do |new_line|
326
+ new_line.write <<~EOS
272
327
 
273
328
  def resolve **args
274
- #{class_name} = #{class_name.capitalize}.new args
329
+ #{class_name} = #{class_name.camelize}.new args
275
330
  if #{class_name}.save
276
331
  { #{class_name}: #{class_name} }
277
332
  else
@@ -284,19 +339,112 @@ module Souls
284
339
  end
285
340
  EOS
286
341
  end
287
- puts "mutation create_#{class_name}.rb created!: `#{file_path}`"
342
+ puts "Mutation create_#{class_name}.rb Auto Generated from schema.rb!: `#{file_path}`"
288
343
  end
289
344
 
290
- def query class_name: "souls"
291
- file_path = "./app/graphql/queries/#{class_name}s.rb"
345
+ def update_mutation_head class_name: "souls"
346
+ file_path = "./app/graphql/mutations/update_#{class_name}.rb"
347
+ File.open(file_path, "w") do |new_line|
348
+ new_line.write <<~EOS
349
+ module Mutations
350
+ class Update#{class_name.camelize} < BaseMutation
351
+ field :#{class_name}, Types::#{class_name.camelize}Type, null: false
352
+
353
+ EOS
354
+ end
355
+ end
356
+
357
+ def update_mutation_params class_name: "souls"
358
+ file_path = "./app/graphql/mutations/update_#{class_name}.rb"
359
+ path = "./db/schema.rb"
360
+ @on = false
361
+ File.open(file_path, "a") do |new_line|
362
+ File.open(path, "r") do |f|
363
+ f.each_line.with_index do |line, i|
364
+ if @on
365
+ break if line.include?("end") || line.include?("t.index")
366
+ type, name = line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
367
+ field = type_check type
368
+ case name
369
+ when "created_at", "updated_at"
370
+ next
371
+ else
372
+ new_line.write " argument :#{name}, #{field}, required: false\n"
373
+ end
374
+ end
375
+ @on = true if table_check(line: line, class_name: class_name)
376
+ end
377
+ end
378
+ end
379
+ end
380
+
381
+ def update_mutation_end class_name: "souls"
382
+ file_path = "./app/graphql/mutations/update_#{class_name}.rb"
383
+ File.open(file_path, "a") do |new_line|
384
+ new_line.write <<~EOS
385
+
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
392
+ end
393
+ end
394
+ end
395
+ EOS
396
+ end
397
+ puts "Mutation update_#{class_name}.rb Auto Generated from schema.rb!: `#{file_path}`"
398
+ end
399
+
400
+ def update_mutation class_name: "souls"
401
+ update_mutation_head class_name: class_name
402
+ update_mutation_params class_name: class_name
403
+ update_mutation_end class_name: class_name
404
+ end
405
+
406
+ def delete_mutation class_name: "souls"
407
+ file_path = "./app/graphql/mutations/delete_#{class_name}.rb"
408
+ File.open(file_path, "w") do |f|
409
+ f.write <<~EOS
410
+ 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
421
+ end
422
+ end
423
+ end
424
+ EOS
425
+ end
426
+ puts "Mutation create_#{class_name}.rb Auto Generated from schema.rb!: `#{file_path}`"
427
+ end
428
+
429
+ def mutation class_name: "souls"
430
+ singularized_class_name = class_name.singularize
431
+ create_mutation_head class_name: singularized_class_name
432
+ 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
436
+ end
437
+
438
+ def create_query class_name: "souls"
439
+ file_path = "./app/graphql/queries/#{class_name.pluralize}.rb"
292
440
  File.open(file_path, "w") do |f|
293
441
  f.write <<~EOS
294
442
  module Queries
295
- class #{class_name.capitalize}s < Queries::BaseQuery
296
- type [Types::#{class_name.capitalize}Type], null: false
443
+ class #{class_name.camelize.pluralize} < Queries::BaseQuery
444
+ type [Types::#{class_name.camelize}Type], null: false
297
445
 
298
446
  def resolve
299
- ::#{class_name.capitalize}.all
447
+ ::#{class_name.camelize}.all
300
448
  rescue StandardError => error
301
449
  GraphQL::ExecutionError.new error
302
450
  end
@@ -304,57 +452,142 @@ module Souls
304
452
  end
305
453
  EOS
306
454
  end
307
- puts "query #{class_name}s.rb created!: `#{file_path}`"
455
+ puts "Query #{class_name}.rb Auto Generated from schema.rb!: `#{file_path}`"
456
+ end
457
+
458
+ def create_queries class_name: "souls"
308
459
  file_path = "./app/graphql/queries/#{class_name}.rb"
309
460
  File.open(file_path, "w") do |f|
310
461
  f.write <<~EOS
311
462
  module Queries
312
- class #{class_name.capitalize} < Queries::BaseQuery
313
- type Types::#{class_name.capitalize}Type, null: false
463
+ class #{class_name.camelize} < Queries::BaseQuery
464
+ type Types::#{class_name.camelize}Type, null: false
314
465
  argument :id, Integer, required: true
315
466
 
316
467
  def resolve id:
317
- ::#{class_name.capitalize}.find(id)
468
+ ::#{class_name.camelize}.find(id)
318
469
  rescue StandardError => error
319
470
  GraphQL::ExecutionError.new error
320
471
  end
321
472
  end
322
473
  end
323
474
  EOS
324
- puts "query #{class_name}.rb created!: `#{file_path}`"
475
+ puts "Query #{class_name.pluralize}.rb Auto Generated from schema.rb!: `#{file_path}`"
325
476
  end
326
477
  end
327
478
 
328
- def type class_name: "souls"
479
+ def query class_name: "souls"
480
+ singularized_class_name = class_name.singularize
481
+ create_query class_name: singularized_class_name
482
+ create_queries class_name: singularized_class_name
483
+ end
484
+
485
+ def create_type_head class_name: "souls"
329
486
  file_path = "./app/graphql/types/#{class_name}_type.rb"
487
+ File.open(file_path, "w") do |f|
488
+ f.write <<~EOS
489
+ module Types
490
+ class #{class_name.camelize}Type < GraphQL::Schema::Object
491
+ implements GraphQL::Types::Relay::Node
492
+
493
+ EOS
494
+ end
495
+ end
496
+
497
+ def create_type_params class_name: "souls"
498
+ file_path = "./app/graphql/types/#{class_name}_type.rb"
499
+ path = "./db/schema.rb"
500
+ @on = false
501
+ File.open(file_path, "a") do |new_line|
502
+ File.open(path, "r") do |f|
503
+ f.each_line.with_index do |line, i|
504
+ if @on
505
+ new_line.write "\n" && break if line.include?("end") || line.include?("t.index")
506
+ type, name = line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
507
+ field = type_check type
508
+ new_line.write " field :#{name}, #{field}, null: true\n"
509
+ end
510
+ if table_check(line: line, class_name: class_name)
511
+ @on = true
512
+ new_line.write " global_id_field :id\n"
513
+ end
514
+ end
515
+ end
516
+ end
517
+ end
518
+
519
+ def create_type_end class_name: "souls"
520
+ file_path = "./app/graphql/types/#{class_name}_type.rb"
521
+ File.open(file_path, "a") do |f|
522
+ f.write <<~EOS
523
+ end
524
+ end
525
+ EOS
526
+ end
527
+ puts "Type #{class_name}_type.rb Auto Generated from schema.rb!: `#{file_path}`"
528
+ end
529
+
530
+ def type class_name: "souls"
531
+ singularized_class_name = class_name.singularize
532
+ create_type_head class_name: singularized_class_name
533
+ create_type_params class_name: singularized_class_name
534
+ create_type_end class_name: singularized_class_name
535
+ end
536
+
537
+ def rspec_factory_head class_name: "souls"
538
+ file_path = "./spec/factories/#{class_name.pluralize}.rb"
330
539
  File.open(file_path, "w") do |f|
331
540
  f.write <<~EOS
332
- module Types
333
- class #{class_name.capitalize}Type < GraphQL::Schema::Object
334
- implements GraphQL::Types::Relay::Node
335
-
336
- ## Change field as you needed
337
- # global_id_field :id
338
- # field :user, Types::UserType, null: false
339
- # field :title, String, null: false
340
- # field :tag, [String], null: true
341
- # field :public_date, GraphQL::Types::ISO8601DateTime, null: false
342
- # field :is_public, Boolean, null: false
343
- # field :article_category, Types::ArticleCategoryType, null: false
344
- # field :created_at, GraphQL::Types::ISO8601DateTime, null: true
345
- # field :updated_at, GraphQL::Types::ISO8601DateTime, null: true
541
+ FactoryBot.define do
542
+ factory :#{class_name} do
543
+ EOS
544
+ end
545
+ end
546
+
547
+ def rspec_factory_params class_name: "souls"
548
+ file_path = "./spec/factories/#{class_name.pluralize}.rb"
549
+ path = "./db/schema.rb"
550
+ @on = false
551
+ File.open(file_path, "a") do |new_line|
552
+ File.open(path, "r") do |f|
553
+ f.each_line.with_index do |line, i|
554
+ if @on
555
+ new_line.write "\n" && break if line.include?("end") || line.include?("t.index")
556
+ type, name = line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
557
+ field = get_test_type type
558
+ new_line.write " #{name} { #{field} }\n"
559
+ end
560
+ if table_check(line: line, class_name: class_name)
561
+ @on = true
562
+ end
563
+ end
564
+ end
565
+ end
566
+ end
567
+
568
+ def rspec_factory_end class_name: "souls"
569
+ file_path = "./spec/factories/#{class_name.pluralize}.rb"
570
+ File.open(file_path, "a") do |f|
571
+ f.write <<~EOS
346
572
  end
347
573
  end
348
574
  EOS
349
575
  end
350
- puts "type #{class_name}.rb created!: `#{file_path}`"
576
+ puts "FactoryBot #{class_name.pluralize}.rb Auto Generated from schema.rb!: `#{file_path}`"
577
+ end
578
+
579
+ def rspec_factory class_name: "souls"
580
+ singularized_class_name = class_name.singularize
581
+ rspec_factory_head class_name: singularized_class_name
582
+ rspec_factory_params class_name: singularized_class_name
583
+ rspec_factory_end class_name: singularized_class_name
351
584
  end
352
585
 
353
586
  def rspec_model class_name: "souls"
354
587
  file_path = "./spec/models/#{class_name}_spec.rb"
355
588
  File.open(file_path, "w") do |f|
356
589
  f.write <<~EOS
357
- RSpec.describe #{class_name.capitalize}, type: :model do
590
+ RSpec.describe #{class_name.camelize}, type: :model do
358
591
  it "作成する" do
359
592
  expect(FactoryBot.build(:#{class_name})).to be_valid
360
593
  end
@@ -366,26 +599,47 @@ module Souls
366
599
  end
367
600
  EOS
368
601
  end
369
- puts "rspec_model #{class_name}_spec.rb created!: `#{file_path}`"
602
+ puts "Rspec #{class_name}_spec.rb Auto Generated from schema.rb!: `#{file_path}`"
370
603
  end
371
604
 
372
605
  def rspec_mutation class_name: "souls"
606
+ # if needed
373
607
  end
374
608
 
375
609
  def rspec_query class_name: "souls"
610
+ # if needed
376
611
  end
377
612
 
378
613
  def rspec_type class_name: "souls"
614
+ # if needed
615
+ end
616
+
617
+ def get_end_point
618
+ file_path = "./app/graphql/types/mutation_type.rb"
619
+ File.open(file_path, "r") do |f|
620
+ f.each_line.with_index do |line, i|
621
+ return i if line.include?("end")
622
+ end
623
+ end
624
+ end
625
+
626
+ def add_mutation_type class_name: "souls"
627
+ # let's do this later
628
+ end
629
+
630
+ def add_query_type class_name: "souls"
631
+ # let's do this later
379
632
  end
380
633
 
381
634
  def migration class_name: "souls"
635
+ `rake db:migrate`
382
636
  model class_name: class_name
383
637
  mutation class_name: class_name
384
638
  query class_name: class_name
385
639
  type class_name: class_name
640
+ rspec_factory class_name: class_name
386
641
  rspec_model class_name: class_name
387
642
  end
388
-
389
643
  end
390
644
  end
391
645
  end
@@ -1,3 +1,3 @@
1
1
  module Souls
2
- VERSION = "0.8.6"
2
+ VERSION = "0.9.1"
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.8.6
4
+ version: 0.9.1
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-20 00:00:00.000000000 Z
13
+ date: 2021-01-21 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.