souls 0.8.2 → 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: cc9a28012025af5ddad7c91cd7fc8738d41f91e2348ce3fc32ee7d97610d4177
4
- data.tar.gz: f8dfd8d2cc6573d29e9069b5d51271ef0af3c45d8d337984a0b292852f87073c
3
+ metadata.gz: 46e7d4670ab49a147d4f62b0dbf14872051c8c30bf3bdc01f49cf30d48f91205
4
+ data.tar.gz: bb3be9fcb27284432fd0052c71769f131af513a1a606e201f21dc9601b97c043
5
5
  SHA512:
6
- metadata.gz: d674883bcc4208a98960b3cc6a363e830515f3d120a810fe39e6a220587c13a2687a98ebea76dc27bbb0d26578ec24f8cba6822617f4b48cdd621f7657c03843
7
- data.tar.gz: 914d33cf7642f4563985e49d2bec7c44ca203fee95f5bf3cf62c313a5ab0c6b05a33c4c2212c5a72f4a6c68d3bf21c3586c9eef553c7fd44ec9d0d4a1e6128f3
6
+ metadata.gz: 4f906bfa46081147867fc125f8dc8dd3806cbf39fce4605f9454481d0299ecefa77e0faad71941f9d7ab3dd6d48225bde24d6998e79458ce8773274d2b42fd95
7
+ data.tar.gz: b84307ee1d465c28e6296a091a470b5fe3a8b8e8dd24d38ac773cb2de3b4bdb9c01f7b40c92b62e540441a3c2b7ee6f1ec775fb777c8b1b0ff444085a26c71f1
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"
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- souls (0.8.1)
4
+ souls (0.8.6)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -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"
@@ -125,7 +125,7 @@ module Souls
125
125
  def export_network_group
126
126
  app = Souls.configuration.app
127
127
  system "NEG_NAME=$(gcloud compute network-endpoint-groups list | grep #{app} | awk '{print $1}')"
128
- `echo $NEG_NAME > ./infra/config/neg_name`
128
+ `echo $NEG_NAME > ./config/neg_name`
129
129
  end
130
130
 
131
131
  def delete_network_group_list neg_name:
@@ -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,381 @@ 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.capitalize} < ActiveRecord::Base
251
+ end
252
+ EOS
253
+ end
254
+ puts "model #{class_name}.rb created!: `#{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}s"
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.capitalize} < BaseMutation
292
+ field :#{class_name}, Types::#{class_name.capitalize}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
+ 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
322
+
323
+ def resolve **args
324
+ #{class_name} = #{class_name.capitalize}.new args
325
+ if #{class_name}.save
326
+ { #{class_name}: #{class_name} }
327
+ else
328
+ { error: #{class_name}.errors.full_messages }
329
+ end
330
+ rescue StandardError => error
331
+ GraphQL::ExecutionError.new error
332
+ end
333
+ end
334
+ end
335
+ EOS
336
+ end
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
425
+ end
426
+
427
+ def query class_name: "souls"
428
+ file_path = "./app/graphql/queries/#{class_name}s.rb"
429
+ File.open(file_path, "w") do |f|
430
+ f.write <<~EOS
431
+ module Queries
432
+ class #{class_name.capitalize}s < Queries::BaseQuery
433
+ type [Types::#{class_name.capitalize}Type], null: false
434
+
435
+ def resolve
436
+ ::#{class_name.capitalize}.all
437
+ rescue StandardError => error
438
+ GraphQL::ExecutionError.new error
439
+ end
440
+ end
441
+ end
442
+ EOS
443
+ end
444
+ puts "query #{class_name}s.rb created!: `#{file_path}`"
445
+ file_path = "./app/graphql/queries/#{class_name}.rb"
446
+ File.open(file_path, "w") do |f|
447
+ f.write <<~EOS
448
+ module Queries
449
+ class #{class_name.capitalize} < Queries::BaseQuery
450
+ type Types::#{class_name.capitalize}Type, null: false
451
+ argument :id, Integer, required: true
452
+
453
+ def resolve id:
454
+ ::#{class_name.capitalize}.find(id)
455
+ rescue StandardError => error
456
+ GraphQL::ExecutionError.new error
457
+ end
458
+ end
459
+ end
460
+ EOS
461
+ puts "query #{class_name}.rb created!: `#{file_path}`"
462
+ end
463
+ end
464
+
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"
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"
518
+ File.open(file_path, "w") do |f|
519
+ f.write <<~EOS
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
551
+ end
552
+ end
553
+ EOS
554
+ end
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
562
+ end
563
+
564
+ def rspec_model class_name: "souls"
565
+ file_path = "./spec/models/#{class_name}_spec.rb"
566
+ File.open(file_path, "w") do |f|
567
+ f.write <<~EOS
568
+ RSpec.describe #{class_name.capitalize}, type: :model do
569
+ it "作成する" do
570
+ expect(FactoryBot.build(:#{class_name})).to be_valid
571
+ end
572
+
573
+ it "同じtitleがあると作成できない" do
574
+ FactoryBot.build(:#{class_name}, title: "hey")
575
+ expect(FactoryBot.build(:#{class_name}, title: "hey")).to be_valid
576
+ end
577
+ end
578
+ EOS
579
+ end
580
+ puts "rspec_model #{class_name}_spec.rb created!: `#{file_path}`"
581
+ end
582
+
583
+ def rspec_mutation class_name: "souls"
584
+ # if needed
585
+ end
586
+
587
+ def rspec_query class_name: "souls"
588
+ # if needed
589
+ end
590
+
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
610
+ end
611
+
612
+ def migration class_name: "souls"
613
+ `rake db:migrate`
614
+ model class_name: class_name
615
+ mutation class_name: class_name
616
+ query class_name: class_name
617
+ type class_name: class_name
618
+ rspec_factory class_name: class_name
619
+ rspec_model class_name: class_name
620
+ end
218
621
  end
219
622
  end
220
623
  end