souls 0.8.3 → 0.8.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: ba6949269bd50c172b4daeb162ce1667245fd7d9e64c4c667840cf84c74713ea
4
- data.tar.gz: 8c3b2f15b9144ed33e3685e204275f966f56178d4bb99312f5c23e906e74730e
3
+ metadata.gz: f5859735f56d7954ebc4b65d76b8961050dd13ce6b9e5572efc0feb08ddde21d
4
+ data.tar.gz: 95bc765b4a97393f94d53f5b08f34dc893482f5e266fb4a514429f2f40a39f3a
5
5
  SHA512:
6
- metadata.gz: 9a18ce07f509e90b00faf60356920d738fc3d415a9743c2ec37cce781f7ed712d6922cf03413d020d3ca63e7b7ecd47733d7c01e9abe866c861fee5ed4f15a5d
7
- data.tar.gz: de6602b9586212185510318a9f18346c3d313c972c449c3d4ac304f7d0dacd1de2787dfc51bfb66201c757b523094bb7a0d0d99eaf5e52cda09e7e22d93445cd
6
+ metadata.gz: 4fc5d3918a769fdfc7b67bf4466d65536b97a380e3504f736982889c0ae5a92cff0584e924bdd296049c91c260213954d5bfd22298570fab5ca26edda94eeab3
7
+ data.tar.gz: 14b3e574b8aed7a8563726edeca5c827bf0c37011d2a7d6c7f6de6a2456466a402c9172c1a5c21e684f0ef5a093d9db6ce8169a55d80ae3c5b3b40f5f96c38ad
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.1)
4
+ souls (0.8.7)
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!
@@ -1,13 +1,14 @@
1
1
  Souls.configure do |config|
2
- config.project_id = "el-quest"
3
- config.app = "el-quest"
4
- config.namespace = "souls"
5
- config.service_name = "blog-service"
6
- config.network = "elsoul"
7
- config.machine_type = "elsoul"
8
- config.zone = "elsoul"
9
- config.domain = "elsoul"
10
- config.google_application_credentials = "./config/credentials.json"
11
- config.strain = "service"
2
+ config.main_project_id = ""
3
+ config.project_id = ""
4
+ config.app = "souls"
5
+ config.namespace = ""
6
+ config.service_name = ""
7
+ config.network = ""
8
+ config.machine_type = ""
9
+ config.zone = ""
10
+ config.domain = ""
11
+ config.google_application_credentials = ""
12
+ config.strain = ""
12
13
  config.proto_package_name = "souls"
13
14
  end
data/exe/souls CHANGED
@@ -3,7 +3,7 @@ require "souls"
3
3
 
4
4
  begin
5
5
  begin
6
- require "./config/initializers/souls" unless ARGV[0] == "new"
6
+ require "./config/initializers/souls" unless ARGV[0] == "new" || ARGV[0] == "init"
7
7
  rescue
8
8
  Souls::Init.config_init
9
9
  end
@@ -46,10 +46,31 @@ 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 "migration"
61
+ Souls::Init.migration class_name: ARGV[2]
62
+ when "rspec_factory"
63
+ Souls::Init.rspec_factory class_name: ARGV[2]
64
+ when "rspec_model"
65
+ Souls::Init.rspec_model class_name: ARGV[2]
66
+ when "rspec_mutation"
67
+ Souls::Init.rspec_mutation class_name: ARGV[2]
68
+ when "rspec_query"
69
+ Souls::Init.rspec_query class_name: ARGV[2]
70
+ when "rspec_type"
71
+ Souls::Init.rspec_type class_name: ARGV[2]
72
+ else
73
+ end
53
74
  when "t", "test"
54
75
  case ARGV[1]
55
76
  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
@@ -41,15 +41,16 @@ module Souls
41
41
  confirm = STDIN.gets.chomp
42
42
  raise StandardError, "Retry" unless confirm == ""
43
43
  download_souls app_name: app_name, repository_name: "souls_#{STRAINS[strain.to_i - 1]}"
44
- config_init app_name: app_name, project: project if config_needed.include?(strain)
44
+ initial_config_init app_name: app_name, project: project if config_needed.include?(strain)
45
45
  rescue StandardError => error
46
46
  puts error
47
47
  retry
48
48
  end
49
49
  end
50
50
 
51
- def config_init app_name: "souls", project: {}
51
+ def initial_config_init app_name: "souls", project: {}
52
52
  puts "Generating souls conf..."
53
+ `touch "#{app_name}/config/initializers/souls.rb"`
53
54
  file_path = "#{app_name}/config/initializers/souls.rb"
54
55
  File.open(file_path, "w") do |f|
55
56
  f.write <<~EOS
@@ -71,6 +72,33 @@ module Souls
71
72
  end
72
73
  end
73
74
 
75
+ def config_init app_name: "souls", project: {}
76
+ `touch ./config/initializers/souls.rb`
77
+ file_path = "./config/initializers/souls.rb"
78
+ puts "Generating souls conf..."
79
+ sleep(rand(0.1..0.3))
80
+ puts "Generated!"
81
+ puts "Let's Edit SOULs Conf: `#{file_path}`"
82
+ File.open(file_path, "w") do |f|
83
+ f.write <<~EOS
84
+ Souls.configure do |config|
85
+ config.main_project_id = "#{project[:main_project_id]}"
86
+ config.project_id = "#{project[:project_id]}"
87
+ config.app = "#{app_name}"
88
+ config.namespace = "#{project[:namespace]}"
89
+ config.service_name = "#{project[:service_name]}"
90
+ config.network = "#{project[:network]}"
91
+ config.machine_type = "#{project[:machine_type]}"
92
+ config.zone = "#{project[:zone]}"
93
+ config.domain = "#{project[:domain]}"
94
+ config.google_application_credentials = "#{project[:google_application_credentials]}"
95
+ config.strain = "#{project[:strain]}"
96
+ config.proto_package_name = "souls"
97
+ end
98
+ EOS
99
+ end
100
+ end
101
+
74
102
  def get_version repository_name: "souls_service"
75
103
  data = JSON.parse `curl \
76
104
  -H "Accept: application/vnd.github.v3+json" \
@@ -215,6 +243,399 @@ module Souls
215
243
  `souls i delete_ingress`
216
244
  end
217
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
+ create_mutation_head class_name: class_name
431
+ create_mutation_params class_name: class_name
432
+ create_mutation_end class_name: class_name
433
+ update_mutation class_name: class_name
434
+ delete_mutation class_name: class_name
435
+ end
436
+
437
+ def create_query class_name: "souls"
438
+ file_path = "./app/graphql/queries/#{class_name.pluralize}.rb"
439
+ File.open(file_path, "w") do |f|
440
+ f.write <<~EOS
441
+ module Queries
442
+ class #{class_name.camelize.pluralize} < Queries::BaseQuery
443
+ type [Types::#{class_name.camelize}Type], null: false
444
+
445
+ def resolve
446
+ ::#{class_name.camelize}.all
447
+ rescue StandardError => error
448
+ GraphQL::ExecutionError.new error
449
+ end
450
+ end
451
+ end
452
+ EOS
453
+ end
454
+ puts "Query #{class_name}.rb Auto Generated from schema.rb!: `#{file_path}`"
455
+ end
456
+
457
+ def create_queries class_name: "souls"
458
+ file_path = "./app/graphql/queries/#{class_name}.rb"
459
+ File.open(file_path, "w") do |f|
460
+ f.write <<~EOS
461
+ module Queries
462
+ class #{class_name.camelize} < Queries::BaseQuery
463
+ type Types::#{class_name.camelize}Type, null: false
464
+ argument :id, Integer, required: true
465
+
466
+ def resolve id:
467
+ ::#{class_name.camelize}.find(id)
468
+ rescue StandardError => error
469
+ GraphQL::ExecutionError.new error
470
+ end
471
+ end
472
+ end
473
+ EOS
474
+ puts "Query #{class_name.pluralize}.rb Auto Generated from schema.rb!: `#{file_path}`"
475
+ end
476
+ end
477
+
478
+ def query class_name: "souls"
479
+ create_query class_name: class_name
480
+ create_queries class_name: class_name
481
+ end
482
+
483
+ def create_type_head class_name: "souls"
484
+ file_path = "./app/graphql/types/#{class_name}_type.rb"
485
+ File.open(file_path, "w") do |f|
486
+ f.write <<~EOS
487
+ module Types
488
+ class #{class_name.camelize}Type < GraphQL::Schema::Object
489
+ implements GraphQL::Types::Relay::Node
490
+
491
+ EOS
492
+ end
493
+ end
494
+
495
+ def create_type_params class_name: "souls"
496
+ file_path = "./app/graphql/types/#{class_name}_type.rb"
497
+ path = "./db/schema.rb"
498
+ @on = false
499
+ File.open(file_path, "a") do |new_line|
500
+ File.open(path, "r") do |f|
501
+ f.each_line.with_index do |line, i|
502
+ if @on
503
+ new_line.write "\n" && break if line.include?("end") || line.include?("t.index")
504
+ type, name = line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
505
+ field = type_check type
506
+ new_line.write " field :#{name}, #{field}, null: true\n"
507
+ end
508
+ if table_check(line: line, class_name: class_name)
509
+ @on = true
510
+ new_line.write " global_id_field :id\n"
511
+ end
512
+ end
513
+ end
514
+ end
515
+ end
516
+
517
+ def create_type_end class_name: "souls"
518
+ file_path = "./app/graphql/types/#{class_name}_type.rb"
519
+ File.open(file_path, "a") do |f|
520
+ f.write <<~EOS
521
+ end
522
+ end
523
+ EOS
524
+ end
525
+ puts "Type #{class_name}_type.rb Auto Generated from schema.rb!: `#{file_path}`"
526
+ end
527
+
528
+ def type class_name: "souls"
529
+ create_type_head class_name: class_name
530
+ create_type_params class_name: class_name
531
+ create_type_end class_name: class_name
532
+ end
533
+
534
+ def rspec_factory_head class_name: "souls"
535
+ file_path = "./spec/factories/#{class_name.pluralize}.rb"
536
+ File.open(file_path, "w") do |f|
537
+ f.write <<~EOS
538
+ FactoryBot.define do
539
+ factory :#{class_name} do
540
+ EOS
541
+ end
542
+ end
543
+
544
+ def rspec_factory_params class_name: "souls"
545
+ file_path = "./spec/factories/#{class_name.pluralize}.rb"
546
+ path = "./db/schema.rb"
547
+ @on = false
548
+ File.open(file_path, "a") do |new_line|
549
+ File.open(path, "r") do |f|
550
+ f.each_line.with_index do |line, i|
551
+ if @on
552
+ new_line.write "\n" && break if line.include?("end") || line.include?("t.index")
553
+ type, name = line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
554
+ field = get_test_type type
555
+ new_line.write " #{name} { #{field} }\n"
556
+ end
557
+ if table_check(line: line, class_name: class_name)
558
+ @on = true
559
+ end
560
+ end
561
+ end
562
+ end
563
+ end
564
+
565
+ def rspec_factory_end class_name: "souls"
566
+ file_path = "./spec/factories/#{class_name.pluralize}.rb"
567
+ File.open(file_path, "a") do |f|
568
+ f.write <<~EOS
569
+ end
570
+ end
571
+ EOS
572
+ end
573
+ puts "FactoryBot #{class_name.pluralize}.rb Auto Generated from schema.rb!: `#{file_path}`"
574
+ end
575
+
576
+ def rspec_factory class_name: "souls"
577
+ rspec_factory_head class_name: class_name
578
+ rspec_factory_params class_name: class_name
579
+ rspec_factory_end class_name: class_name
580
+ end
581
+
582
+ def rspec_model class_name: "souls"
583
+ file_path = "./spec/models/#{class_name}_spec.rb"
584
+ File.open(file_path, "w") do |f|
585
+ f.write <<~EOS
586
+ RSpec.describe #{class_name.camelize}, type: :model do
587
+ it "作成する" do
588
+ expect(FactoryBot.build(:#{class_name})).to be_valid
589
+ end
590
+
591
+ it "同じtitleがあると作成できない" do
592
+ FactoryBot.build(:#{class_name}, title: "hey")
593
+ expect(FactoryBot.build(:#{class_name}, title: "hey")).to be_valid
594
+ end
595
+ end
596
+ EOS
597
+ end
598
+ puts "Rspec #{class_name}_spec.rb Auto Generated from schema.rb!: `#{file_path}`"
599
+ end
600
+
601
+ def rspec_mutation class_name: "souls"
602
+ # if needed
603
+ end
604
+
605
+ def rspec_query class_name: "souls"
606
+ # if needed
607
+ end
608
+
609
+ def rspec_type class_name: "souls"
610
+ # if needed
611
+ end
612
+
613
+ def get_end_point
614
+ file_path = "./app/graphql/types/mutation_type.rb"
615
+ File.open(file_path, "r") do |f|
616
+ f.each_line.with_index do |line, i|
617
+ return i if line.include?("end")
618
+ end
619
+ end
620
+ end
621
+
622
+ def add_mutation_type class_name: "souls"
623
+ # let's do this later
624
+ end
625
+
626
+ def add_query_type class_name: "souls"
627
+ # let's do this later
628
+ end
629
+
630
+ def migration class_name: "souls"
631
+ # `rake db:migrate`
632
+ model class_name: class_name
633
+ mutation class_name: class_name
634
+ query class_name: class_name
635
+ type class_name: class_name
636
+ rspec_factory class_name: class_name
637
+ rspec_model class_name: class_name
638
+ end
218
639
  end
219
640
  end
220
641
  end