souls 0.8.5 → 0.9.0

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: a57b96797a0a477562740a5cf08fbd5c4183f2fe493a70cb69566f5f1cda980b
4
- data.tar.gz: 8a029707d19eda050c020c36600dda592d3f0a0451d05f51667343a5d6a8ad2f
3
+ metadata.gz: 54a4dccb9631723491affa9d73948039c25f6c0a0c50f4603a564fa20471e7b7
4
+ data.tar.gz: 8566b5d084abd62b73de54b875f74a7e87e7667a2f47d06637964dbc610cb6d2
5
5
  SHA512:
6
- metadata.gz: f46f143cc597d71e62948f95226c7bbee91541063d8d6ea03f8fc77e46bdbeeff35373e709ba663b9c5b745e4a2524413ba0c11b4254738792f7265794d7c110
7
- data.tar.gz: 0c608d8eda05af23a06ae4767e2b19d38e4c98f72a0136bded4e86c48ddc0c08731e5d07d99e3355f30135337fe70f1b9f457dd010216cb618f06d693af06d13
6
+ metadata.gz: 198f92ed3a8d414db7ee84e4e4dbeaa5cac76afc6226a4ab22c00042d4d98a0301fe055b701327a8bb09207058e71bac4508932e3e69f44455e5f9d5f6d8656c
7
+ data.tar.gz: 2411b6a5b7a2a44fb90353a08d2b80a2df9c3862d5a03e86d9780fe9c840f8f722a140e5d30c61637f95bb82cd2df967baabab1e2649fe49b1a24b47d58885e5
data/.gitignore CHANGED
@@ -11,4 +11,7 @@
11
11
  .rspec_status
12
12
  /config/keyfile.json
13
13
  .env
14
- .irb_history
14
+ .irb_history
15
+ /spec/
16
+ /app/
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.4)
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
@@ -46,10 +46,33 @@ begin
46
46
  when "-v", "--version"
47
47
  puts Souls::VERSION
48
48
  when "g", "generate"
49
- `touch .rubocop.yml`
50
- `touch .env`
51
- `touch .gitignore`
52
- `touch .irbrc`
49
+ case ARGV[1]
50
+ when "test"
51
+ Souls::Init.delete_mutation class_name: "article"
52
+ when "model"
53
+ Souls::Init.model class_name: ARGV[2]
54
+ when "mutation"
55
+ Souls::Init.mutation class_name: ARGV[2]
56
+ when "query"
57
+ Souls::Init.query class_name: ARGV[2]
58
+ when "type"
59
+ Souls::Init.type class_name: ARGV[2]
60
+ when "migrate"
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]
66
+ when "rspec_model"
67
+ Souls::Init.rspec_model class_name: ARGV[2]
68
+ when "rspec_mutation"
69
+ Souls::Init.rspec_mutation class_name: ARGV[2]
70
+ when "rspec_query"
71
+ Souls::Init.rspec_query class_name: ARGV[2]
72
+ when "rspec_type"
73
+ Souls::Init.rspec_type class_name: ARGV[2]
74
+ else
75
+ end
53
76
  when "t", "test"
54
77
  case ARGV[1]
55
78
  when "-r"
@@ -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
@@ -243,6 +243,403 @@ module Souls
243
243
  `souls i delete_ingress`
244
244
  end
245
245
 
246
+ def model class_name: "souls"
247
+ file_path = "./app/models/#{class_name}.rb"
248
+ File.open(file_path, "w") do |f|
249
+ f.write <<~EOS
250
+ class #{class_name.camelize} < ActiveRecord::Base
251
+ end
252
+ EOS
253
+ end
254
+ puts "Model #{class_name}.rb Auto Generated from schema.rb!: `#{file_path}`"
255
+ end
256
+
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"
287
+ file_path = "./app/graphql/mutations/create_#{class_name}.rb"
288
+ File.open(file_path, "w") do |new_line|
289
+ new_line.write <<~EOS
290
+ 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
294
+
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
327
+
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 }
334
+ end
335
+ rescue StandardError => error
336
+ GraphQL::ExecutionError.new error
337
+ end
338
+ end
339
+ end
340
+ EOS
341
+ end
342
+ puts "Mutation create_#{class_name}.rb Auto Generated from schema.rb!: `#{file_path}`"
343
+ end
344
+
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"
440
+ File.open(file_path, "w") do |f|
441
+ f.write <<~EOS
442
+ module Queries
443
+ class #{class_name.camelize.pluralize} < Queries::BaseQuery
444
+ type [Types::#{class_name.camelize}Type], null: false
445
+
446
+ def resolve
447
+ ::#{class_name.camelize}.all
448
+ rescue StandardError => error
449
+ GraphQL::ExecutionError.new error
450
+ end
451
+ end
452
+ end
453
+ EOS
454
+ end
455
+ puts "Query #{class_name}.rb Auto Generated from schema.rb!: `#{file_path}`"
456
+ end
457
+
458
+ def create_queries class_name: "souls"
459
+ file_path = "./app/graphql/queries/#{class_name}.rb"
460
+ File.open(file_path, "w") do |f|
461
+ f.write <<~EOS
462
+ module Queries
463
+ class #{class_name.camelize} < Queries::BaseQuery
464
+ type Types::#{class_name.camelize}Type, null: false
465
+ argument :id, Integer, required: true
466
+
467
+ def resolve id:
468
+ ::#{class_name.camelize}.find(id)
469
+ rescue StandardError => error
470
+ GraphQL::ExecutionError.new error
471
+ end
472
+ end
473
+ end
474
+ EOS
475
+ puts "Query #{class_name.pluralize}.rb Auto Generated from schema.rb!: `#{file_path}`"
476
+ end
477
+ end
478
+
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"
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"
539
+ File.open(file_path, "w") do |f|
540
+ f.write <<~EOS
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
572
+ end
573
+ end
574
+ EOS
575
+ end
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
584
+ end
585
+
586
+ def rspec_model class_name: "souls"
587
+ file_path = "./spec/models/#{class_name}_spec.rb"
588
+ File.open(file_path, "w") do |f|
589
+ f.write <<~EOS
590
+ RSpec.describe #{class_name.camelize}, type: :model do
591
+ 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
598
+ end
599
+ end
600
+ EOS
601
+ end
602
+ puts "Rspec #{class_name}_spec.rb Auto Generated from schema.rb!: `#{file_path}`"
603
+ end
604
+
605
+ def rspec_mutation class_name: "souls"
606
+ # if needed
607
+ end
608
+
609
+ def rspec_query class_name: "souls"
610
+ # if needed
611
+ end
612
+
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
632
+ end
633
+
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
642
+ end
246
643
  end
247
644
  end
248
645
  end
@@ -1,3 +1,3 @@
1
1
  module Souls
2
- VERSION = "0.8.5"
2
+ VERSION = "0.9.0"
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.5
4
+ version: 0.9.0
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-19 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.