souls 0.8.6 → 0.8.7

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: 46e7d4670ab49a147d4f62b0dbf14872051c8c30bf3bdc01f49cf30d48f91205
4
+ data.tar.gz: bb3be9fcb27284432fd0052c71769f131af513a1a606e201f21dc9601b97c043
5
5
  SHA512:
6
- metadata.gz: 4bfb79e0fc7f341a3e9b05be8a3649d377a49e8af4d749dbbf156e0e06ff3c6dec9b2dba29d09428aee716a132d924baa9d1f6f7859542a575fc5fd9713a305b
7
- data.tar.gz: 893e1f5cbe6d46a581f08681eb13b9e6b1caadc5ce3b921b2294db5e8518ce0e6658a637331edf43120747152c3e2af188e13913be0fdf83533b544dd347e3d5
6
+ metadata.gz: 4f906bfa46081147867fc125f8dc8dd3806cbf39fce4605f9454481d0299ecefa77e0faad71941f9d7ab3dd6d48225bde24d6998e79458ce8773274d2b42fd95
7
+ data.tar.gz: b84307ee1d465c28e6296a091a470b5fe3a8b8e8dd24d38ac773cb2de3b4bdb9c01f7b40c92b62e540441a3c2b7ee6f1ec775fb777c8b1b0ff444085a26c71f1
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"
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- souls (0.8.5)
4
+ souls (0.8.6)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
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"
@@ -57,6 +59,8 @@ begin
57
59
  Souls::Init.type class_name: ARGV[2]
58
60
  when "migration"
59
61
  Souls::Init.migration class_name: ARGV[2]
62
+ when "rspec_factory"
63
+ Souls::Init.rspec_factory class_name: ARGV[2]
60
64
  when "rspec_model"
61
65
  Souls::Init.rspec_model class_name: ARGV[2]
62
66
  when "rspec_mutation"
@@ -254,21 +254,71 @@ module Souls
254
254
  puts "model #{class_name}.rb created!: `#{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}s"
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
291
  class Create#{class_name.capitalize} < BaseMutation
263
292
  field :#{class_name}, Types::#{class_name.capitalize}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
+ new_line.write " argument :#{name}, #{field}, required: false\n"
311
+ end
312
+ @on = true if table_check(line: line, class_name: class_name)
313
+ end
314
+ end
315
+ end
316
+ end
317
+
318
+ def create_mutation_end class_name: "souls"
319
+ file_path = "./app/graphql/mutations/create_#{class_name}.rb"
320
+ File.open(file_path, "a") do |new_line|
321
+ new_line.write <<~EOS
272
322
 
273
323
  def resolve **args
274
324
  #{class_name} = #{class_name.capitalize}.new args
@@ -284,7 +334,94 @@ module Souls
284
334
  end
285
335
  EOS
286
336
  end
287
- puts "mutation create_#{class_name}.rb created!: `#{file_path}`"
337
+ puts "Mutation create_#{class_name}.rb Auto Generated from schema.rb!: `#{file_path}`"
338
+ end
339
+
340
+ def update_mutation_head class_name: "souls"
341
+ file_path = "./app/graphql/mutations/update_#{class_name}.rb"
342
+ File.open(file_path, "w") do |new_line|
343
+ new_line.write <<~EOS
344
+ module Mutations
345
+ class Update#{class_name.capitalize} < BaseMutation
346
+ field :#{class_name}, Types::#{class_name.capitalize}Type, null: false
347
+
348
+ EOS
349
+ end
350
+ end
351
+
352
+ def update_mutation_params class_name: "souls"
353
+ file_path = "./app/graphql/mutations/update_#{class_name}.rb"
354
+ path = "./db/schema.rb"
355
+ @on = false
356
+ File.open(file_path, "a") do |new_line|
357
+ File.open(path, "r") do |f|
358
+ f.each_line.with_index do |line, i|
359
+ if @on
360
+ break if line.include?("end") || line.include?("t.index")
361
+ type, name = line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
362
+ field = type_check type
363
+ new_line.write " argument :#{name}, #{field}, required: false\n"
364
+ end
365
+ @on = true if table_check(line: line, class_name: class_name)
366
+ end
367
+ end
368
+ end
369
+ end
370
+
371
+ def update_mutation_end class_name: "souls"
372
+ file_path = "./app/graphql/mutations/update_#{class_name}.rb"
373
+ File.open(file_path, "a") do |new_line|
374
+ new_line.write <<~EOS
375
+
376
+ def resolve **args
377
+ #{class_name} = #{class_name.capitalize}.find args[:id]
378
+ #{class_name}.update args
379
+ { #{class_name}: #{class_name.capitalize}.find(args[:id]) }
380
+ rescue StandardError => error
381
+ GraphQL::ExecutionError.new error
382
+ end
383
+ end
384
+ end
385
+ EOS
386
+ end
387
+ puts "Mutation update_#{class_name}.rb Auto Generated from schema.rb!: `#{file_path}`"
388
+ end
389
+
390
+ def update_mutation class_name: "souls"
391
+ update_mutation_head class_name: class_name
392
+ update_mutation_params class_name: class_name
393
+ update_mutation_end class_name: class_name
394
+ end
395
+
396
+ def delete_mutation class_name: "souls"
397
+ file_path = "./app/graphql/mutations/delete_#{class_name}.rb"
398
+ File.open(file_path, "w") do |f|
399
+ f.write <<~EOS
400
+ module Mutations
401
+ class Delete#{class_name.capitalize} < BaseMutation
402
+ field :#{class_name}, Types::#{class_name.capitalize}Type, null: false
403
+ argument :id, Integer, required: true
404
+
405
+ def resolve id:
406
+ #{class_name} = #{class_name.capitalize}.find id
407
+ #{class_name}.destroy
408
+ { #{class_name}: #{class_name} }
409
+ rescue StandardError => error
410
+ GraphQL::ExecutionError.new error
411
+ end
412
+ end
413
+ end
414
+ EOS
415
+ end
416
+ puts "Mutation create_#{class_name}.rb Auto Generated from schema.rb!: `#{file_path}`"
417
+ end
418
+
419
+ def mutation class_name: "souls"
420
+ create_mutation_head class_name: class_name
421
+ create_mutation_params class_name: class_name
422
+ create_mutation_end class_name: class_name
423
+ update_mutation class_name: class_name
424
+ delete_mutation class_name: class_name
288
425
  end
289
426
 
290
427
  def query class_name: "souls"
@@ -325,29 +462,103 @@ module Souls
325
462
  end
326
463
  end
327
464
 
328
- def type class_name: "souls"
465
+ def create_type_head class_name: "souls"
466
+ file_path = "./app/graphql/types/#{class_name}_type.rb"
467
+ File.open(file_path, "w") do |f|
468
+ f.write <<~EOS
469
+ module Types
470
+ class #{class_name.capitalize}Type < GraphQL::Schema::Object
471
+ implements GraphQL::Types::Relay::Node
472
+
473
+ EOS
474
+ end
475
+ end
476
+
477
+ def create_type_params class_name: "souls"
329
478
  file_path = "./app/graphql/types/#{class_name}_type.rb"
479
+ path = "./db/schema.rb"
480
+ @on = false
481
+ File.open(file_path, "a") do |new_line|
482
+ File.open(path, "r") do |f|
483
+ f.each_line.with_index do |line, i|
484
+ if @on
485
+ new_line.write "\n" && break if line.include?("end") || line.include?("t.index")
486
+ type, name = line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
487
+ field = type_check type
488
+ new_line.write " field :#{name}, #{field}, null: true\n"
489
+ end
490
+ if table_check(line: line, class_name: class_name)
491
+ @on = true
492
+ new_line.write " global_id_field :id\n"
493
+ end
494
+ end
495
+ end
496
+ end
497
+ end
498
+
499
+ def create_type_end class_name: "souls"
500
+ file_path = "./app/graphql/types/#{class_name}_type.rb"
501
+ File.open(file_path, "a") do |f|
502
+ f.write <<~EOS
503
+ end
504
+ end
505
+ EOS
506
+ end
507
+ puts "Type #{class_name}_type.rb Auto Generated from schema.rb!: `#{file_path}`"
508
+ end
509
+
510
+ def type class_name: "souls"
511
+ create_type_head class_name: class_name
512
+ create_type_params class_name: class_name
513
+ create_type_end class_name: class_name
514
+ end
515
+
516
+ def rspec_factory_head class_name: "souls"
517
+ file_path = "./spec/factories/#{class_name}s.rb"
330
518
  File.open(file_path, "w") do |f|
331
519
  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
520
+ FactoryBot.define do
521
+ factory :#{class_name} do
522
+ EOS
523
+ end
524
+ end
525
+
526
+ def rspec_factory_params class_name: "souls"
527
+ file_path = "./spec/factories/#{class_name}s.rb"
528
+ path = "./db/schema.rb"
529
+ @on = false
530
+ File.open(file_path, "a") do |new_line|
531
+ File.open(path, "r") do |f|
532
+ f.each_line.with_index do |line, i|
533
+ if @on
534
+ new_line.write "\n" && break if line.include?("end") || line.include?("t.index")
535
+ type, name = line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
536
+ field = get_test_type type
537
+ new_line.write " #{name} { #{field} }\n"
538
+ end
539
+ if table_check(line: line, class_name: class_name)
540
+ @on = true
541
+ end
542
+ end
543
+ end
544
+ end
545
+ end
546
+
547
+ def rspec_factory_end class_name: "souls"
548
+ file_path = "./spec/factories/#{class_name}s.rb"
549
+ File.open(file_path, "a") do |f|
550
+ f.write <<~EOS
346
551
  end
347
552
  end
348
553
  EOS
349
554
  end
350
- puts "type #{class_name}.rb created!: `#{file_path}`"
555
+ puts "FactoryBot #{class_name}s.rb Auto Generated from schema.rb!: `#{file_path}`"
556
+ end
557
+
558
+ def rspec_factory class_name: "souls"
559
+ rspec_factory_head class_name: class_name
560
+ rspec_factory_params class_name: class_name
561
+ rspec_factory_end class_name: class_name
351
562
  end
352
563
 
353
564
  def rspec_model class_name: "souls"
@@ -370,22 +581,43 @@ module Souls
370
581
  end
371
582
 
372
583
  def rspec_mutation class_name: "souls"
584
+ # if needed
373
585
  end
374
586
 
375
587
  def rspec_query class_name: "souls"
588
+ # if needed
376
589
  end
377
590
 
378
591
  def rspec_type class_name: "souls"
592
+ # if needed
593
+ end
594
+
595
+ def get_end_point
596
+ file_path = "./app/graphql/types/mutation_type.rb"
597
+ File.open(file_path, "r") do |f|
598
+ f.each_line.with_index do |line, i|
599
+ return i if line.include?("end")
600
+ end
601
+ end
602
+ end
603
+
604
+ def add_mutation_type class_name: "souls"
605
+ # let's do this later
606
+ end
607
+
608
+ def add_query_type class_name: "souls"
609
+ # let's do this later
379
610
  end
380
611
 
381
612
  def migration class_name: "souls"
613
+ `rake db:migrate`
382
614
  model class_name: class_name
383
615
  mutation class_name: class_name
384
616
  query class_name: class_name
385
617
  type class_name: class_name
618
+ rspec_factory class_name: class_name
386
619
  rspec_model class_name: class_name
387
620
  end
388
-
389
621
  end
390
622
  end
391
623
  end
@@ -1,3 +1,3 @@
1
1
  module Souls
2
- VERSION = "0.8.6"
2
+ VERSION = "0.8.7"
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.8.7
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.