souls 0.9.6 → 0.10.2
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 +4 -4
- data/Gemfile.lock +1 -1
- data/exe/souls +2 -2
- data/lib/souls/init.rb +36 -28
- data/lib/souls/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: dfc16affde84b15f23a6c4d1c97ed25862e5f5b1bfab48570fb8b2882930038e
|
|
4
|
+
data.tar.gz: '094139bfe2171b44beb293ac9467d7cb56965b28b3a90d32620dfb74e1adf88a'
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f13ab04eacb55fc25652526912cb8253296072ccd0bedb3f5a71ca67ddf3f66d389d52104d3386989ad293499ae8df768aba0f9ca2c4e2123d86dc94455797a7
|
|
7
|
+
data.tar.gz: e9a15bac295d47b3125948dc9c3cc39a0bc608bbec109575216e342df4759d08e395ef3d72ed286b0bb7a54585fa66efbb9adf7d7fb9b3a5bf3d57c21556fb29
|
data/Gemfile.lock
CHANGED
data/exe/souls
CHANGED
|
@@ -76,8 +76,8 @@ begin
|
|
|
76
76
|
else
|
|
77
77
|
end
|
|
78
78
|
when "t", "test"
|
|
79
|
-
|
|
80
|
-
|
|
79
|
+
`rubocop`
|
|
80
|
+
`bundle exec rspec`
|
|
81
81
|
when "deploy"
|
|
82
82
|
project_id = Souls.configuration.project_id
|
|
83
83
|
`gcloud builds submit --config=cloudbuild.yml --project #{project_id}`
|
data/lib/souls/init.rb
CHANGED
|
@@ -244,7 +244,7 @@ module Souls
|
|
|
244
244
|
end
|
|
245
245
|
|
|
246
246
|
def model class_name: "souls"
|
|
247
|
-
file_path = "./app/models/#{class_name}.rb"
|
|
247
|
+
file_path = "./app/models/#{class_name.singularize}.rb"
|
|
248
248
|
File.open(file_path, "w") do |f|
|
|
249
249
|
f.write <<~EOS
|
|
250
250
|
class #{class_name.camelize} < ActiveRecord::Base
|
|
@@ -261,6 +261,7 @@ module Souls
|
|
|
261
261
|
float: "Float",
|
|
262
262
|
text: "String",
|
|
263
263
|
datetime: "GraphQL::Types::ISO8601DateTime",
|
|
264
|
+
date: "GraphQL::Types::ISO8601DateTime",
|
|
264
265
|
boolean: "Boolean",
|
|
265
266
|
integer: "Integer"
|
|
266
267
|
}[type.to_sym]
|
|
@@ -269,9 +270,11 @@ module Souls
|
|
|
269
270
|
def get_test_type type
|
|
270
271
|
{
|
|
271
272
|
bigint: 1,
|
|
273
|
+
float: 4.2,
|
|
272
274
|
string: '"MyString"',
|
|
273
275
|
text: '"MyString"',
|
|
274
276
|
datetime: "Time.now",
|
|
277
|
+
date: "Time.now",
|
|
275
278
|
boolean: false,
|
|
276
279
|
integer: 1
|
|
277
280
|
}[type.to_sym]
|
|
@@ -307,8 +310,9 @@ module Souls
|
|
|
307
310
|
f.each_line.with_index do |line, i|
|
|
308
311
|
if @on
|
|
309
312
|
break if line.include?("end") || line.include?("t.index")
|
|
313
|
+
field = "[String]" if line.include?("array: true")
|
|
310
314
|
type, name = line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
|
|
311
|
-
field
|
|
315
|
+
field ||= type_check type
|
|
312
316
|
case name
|
|
313
317
|
when "created_at", "updated_at"
|
|
314
318
|
next
|
|
@@ -328,7 +332,7 @@ module Souls
|
|
|
328
332
|
new_line.write <<~EOS
|
|
329
333
|
|
|
330
334
|
def resolve **args
|
|
331
|
-
#{class_name} =
|
|
335
|
+
#{class_name} = ::#{class_name.camelize}.new args
|
|
332
336
|
if #{class_name}.save
|
|
333
337
|
{ #{class_name}: #{class_name} }
|
|
334
338
|
else
|
|
@@ -367,8 +371,9 @@ module Souls
|
|
|
367
371
|
f.each_line.with_index do |line, i|
|
|
368
372
|
if @on
|
|
369
373
|
break if line.include?("end") || line.include?("t.index")
|
|
374
|
+
field = "[String]" if line.include?("array: true")
|
|
370
375
|
type, name = line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
|
|
371
|
-
field
|
|
376
|
+
field ||= type_check type
|
|
372
377
|
case name
|
|
373
378
|
when "created_at", "updated_at"
|
|
374
379
|
next
|
|
@@ -388,9 +393,9 @@ module Souls
|
|
|
388
393
|
new_line.write <<~EOS
|
|
389
394
|
|
|
390
395
|
def resolve **args
|
|
391
|
-
#{class_name} =
|
|
396
|
+
#{class_name} = ::#{class_name.camelize}.find args[:id]
|
|
392
397
|
#{class_name}.update args
|
|
393
|
-
{ #{class_name}:
|
|
398
|
+
{ #{class_name}: ::#{class_name.camelize}.find(args[:id]) }
|
|
394
399
|
rescue StandardError => error
|
|
395
400
|
GraphQL::ExecutionError.new error
|
|
396
401
|
end
|
|
@@ -419,7 +424,7 @@ module Souls
|
|
|
419
424
|
argument :id, Integer, required: true
|
|
420
425
|
|
|
421
426
|
def resolve id:
|
|
422
|
-
#{class_name} =
|
|
427
|
+
#{class_name} = ::#{class_name.camelize}.find id
|
|
423
428
|
#{class_name}.destroy
|
|
424
429
|
{ #{class_name}: #{class_name} }
|
|
425
430
|
rescue StandardError => error
|
|
@@ -433,20 +438,20 @@ module Souls
|
|
|
433
438
|
file_path
|
|
434
439
|
end
|
|
435
440
|
|
|
436
|
-
def create_confirm
|
|
437
|
-
puts "Directory already exists, Overwrite?? (Y/N)"
|
|
441
|
+
def create_confirm dir_path: ""
|
|
442
|
+
puts "Directory already exists, Overwrite?? (Y/N)\n#{dir_path}"
|
|
438
443
|
input = STDIN.gets.chomp
|
|
439
444
|
return true if input == "Y"
|
|
440
|
-
raise StandardError.new "Directory Already Exist
|
|
445
|
+
raise StandardError.new "Directory Already Exist!\n#{dir_path}"
|
|
441
446
|
end
|
|
442
447
|
|
|
443
448
|
def mutation class_name: "souls"
|
|
444
449
|
singularized_class_name = class_name.singularize
|
|
445
450
|
if Dir.exist? "./app/graphql/mutations/#{singularized_class_name}"
|
|
446
|
-
|
|
447
|
-
|
|
451
|
+
create_confirm dir_path: "./app/graphql/mutations/#{singularized_class_name}"
|
|
452
|
+
else
|
|
453
|
+
Dir.mkdir "./app/graphql/mutations/#{singularized_class_name}"
|
|
448
454
|
end
|
|
449
|
-
Dir.mkdir "./app/graphql/mutations/#{singularized_class_name}"
|
|
450
455
|
create_mutation_head class_name: singularized_class_name
|
|
451
456
|
create_mutation_params class_name: singularized_class_name
|
|
452
457
|
[
|
|
@@ -523,8 +528,9 @@ module Souls
|
|
|
523
528
|
f.each_line.with_index do |line, i|
|
|
524
529
|
if @on
|
|
525
530
|
new_line.write "\n" && break if line.include?("end") || line.include?("t.index")
|
|
531
|
+
field = "[String]" if line.include?("array: true")
|
|
526
532
|
type, name = line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
|
|
527
|
-
field
|
|
533
|
+
field ||= type_check type
|
|
528
534
|
new_line.write " field :#{name}, #{field}, null: true\n"
|
|
529
535
|
end
|
|
530
536
|
if table_check(line: line, class_name: class_name)
|
|
@@ -573,8 +579,9 @@ module Souls
|
|
|
573
579
|
f.each_line.with_index do |line, i|
|
|
574
580
|
if @on
|
|
575
581
|
new_line.write "\n" && break if line.include?("end") || line.include?("t.index")
|
|
582
|
+
field = '["tag1", "tag2", "tag3"]' if line.include?("array: true")
|
|
576
583
|
type, name = line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
|
|
577
|
-
field
|
|
584
|
+
field ||= get_test_type type
|
|
578
585
|
new_line.write " #{name} { #{field} }\n"
|
|
579
586
|
end
|
|
580
587
|
if table_check(line: line, class_name: class_name)
|
|
@@ -609,12 +616,7 @@ module Souls
|
|
|
609
616
|
f.write <<~EOS
|
|
610
617
|
RSpec.describe #{class_name.camelize}, type: :model do
|
|
611
618
|
it "作成する" do
|
|
612
|
-
expect(FactoryBot.build(:#{class_name})).to be_valid
|
|
613
|
-
end
|
|
614
|
-
|
|
615
|
-
it "同じtitleがあると作成できない" do
|
|
616
|
-
FactoryBot.build(:#{class_name}, title: "hey")
|
|
617
|
-
expect(FactoryBot.build(:#{class_name}, title: "hey")).to be_valid
|
|
619
|
+
expect(FactoryBot.build(:#{class_name.singularize})).to be_valid
|
|
618
620
|
end
|
|
619
621
|
end
|
|
620
622
|
EOS
|
|
@@ -663,7 +665,6 @@ module Souls
|
|
|
663
665
|
end
|
|
664
666
|
|
|
665
667
|
def migrate class_name: "souls"
|
|
666
|
-
# `rake db:migrate`
|
|
667
668
|
singularized_class_name = class_name.singularize
|
|
668
669
|
model_paths = model class_name: singularized_class_name
|
|
669
670
|
type_paths = type class_name: singularized_class_name
|
|
@@ -679,21 +680,22 @@ module Souls
|
|
|
679
680
|
query: query_path,
|
|
680
681
|
mutation: mutation_path,
|
|
681
682
|
add_query_type: [
|
|
682
|
-
"field :#{singularized_class_name}, resolver: Queries::#{singularized_class_name.camelize}",
|
|
683
|
-
"field :#{singularized_class_name.pluralize}, Types::#{singularized_class_name.camelize}Type.connection_type, null: true"
|
|
683
|
+
" field :#{singularized_class_name}, resolver: Queries::#{singularized_class_name.camelize}",
|
|
684
|
+
" field :#{singularized_class_name.pluralize}, Types::#{singularized_class_name.camelize}Type.connection_type, null: true"
|
|
684
685
|
],
|
|
685
686
|
add_mutation_type: [
|
|
686
|
-
"field :create_#{singularized_class_name}, mutation: Mutations::#{singularized_class_name.camelize}::Create#{singularized_class_name.camelize}",
|
|
687
|
-
"field :update_#{singularized_class_name}, mutation: Mutations::#{singularized_class_name.camelize}::Update#{singularized_class_name.camelize}",
|
|
688
|
-
"field :delete_#{singularized_class_name}, mutation: Mutations::#{singularized_class_name.camelize}::Delete#{singularized_class_name.camelize}"
|
|
687
|
+
" field :create_#{singularized_class_name}, mutation: Mutations::#{singularized_class_name.camelize}::Create#{singularized_class_name.camelize}",
|
|
688
|
+
" field :update_#{singularized_class_name}, mutation: Mutations::#{singularized_class_name.camelize}::Update#{singularized_class_name.camelize}",
|
|
689
|
+
" field :delete_#{singularized_class_name}, mutation: Mutations::#{singularized_class_name.camelize}::Delete#{singularized_class_name.camelize}"
|
|
689
690
|
]
|
|
690
691
|
]
|
|
691
692
|
end
|
|
692
693
|
|
|
693
694
|
def migrate_all
|
|
694
695
|
puts "◆◆◆ Let's Auto Generate CRUD API ◆◆◆\n"
|
|
696
|
+
`rake db:migrate`
|
|
695
697
|
paths = get_tables.map do |class_name|
|
|
696
|
-
migrate class_name: class_name
|
|
698
|
+
migrate class_name: class_name.singularize
|
|
697
699
|
end
|
|
698
700
|
puts "\n============== Model ======================\n\n"
|
|
699
701
|
paths.each do |class_name|
|
|
@@ -743,6 +745,12 @@ module Souls
|
|
|
743
745
|
path[:add_query_type].each { |line| puts line }
|
|
744
746
|
end
|
|
745
747
|
end
|
|
748
|
+
puts "\n\n ## Connection Type\n\n"
|
|
749
|
+
get_tables.each do |class_name|
|
|
750
|
+
puts " def #{class_name.pluralize}"
|
|
751
|
+
puts " #{class_name.camelize}.all.order(id: :desc)"
|
|
752
|
+
puts " end\n"
|
|
753
|
+
end
|
|
746
754
|
puts "\n#############################################################\n"
|
|
747
755
|
puts "# #\n"
|
|
748
756
|
puts "# Add These Lines at ./app/graphql/types/mutation_type.rb #\n"
|
data/lib/souls/version.rb
CHANGED