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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 76d16e22f896d21fad8dee314b75ddc65e42507d8fdabd494ed8f250ec785457
4
- data.tar.gz: 022b54f4f66325a19fb8877662411d6d4d00cf667bc2c04d83222dd77bffa1da
3
+ metadata.gz: dfc16affde84b15f23a6c4d1c97ed25862e5f5b1bfab48570fb8b2882930038e
4
+ data.tar.gz: '094139bfe2171b44beb293ac9467d7cb56965b28b3a90d32620dfb74e1adf88a'
5
5
  SHA512:
6
- metadata.gz: 9c3a5949f7b388f5bdd8863070e2704d25f4e94bc62f7434838b24b11c2cddacbe68d009ab6d089d518e5343e3f6c40d969333c926fc445df034435418ba450a
7
- data.tar.gz: 0d0131a7ac137d5fb15f502b2b863e7d666e7aa71796981f93b0b5c60dd1738cf6e5a40bded2e33c9fd766b2458a3d1e501f9b94716206d37c21bf163dd9210d
6
+ metadata.gz: f13ab04eacb55fc25652526912cb8253296072ccd0bedb3f5a71ca67ddf3f66d389d52104d3386989ad293499ae8df768aba0f9ca2c4e2123d86dc94455797a7
7
+ data.tar.gz: e9a15bac295d47b3125948dc9c3cc39a0bc608bbec109575216e342df4759d08e395ef3d72ed286b0bb7a54585fa66efbb9adf7d7fb9b3a5bf3d57c21556fb29
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- souls (0.9.4)
4
+ souls (0.10.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/exe/souls CHANGED
@@ -76,8 +76,8 @@ begin
76
76
  else
77
77
  end
78
78
  when "t", "test"
79
- puts `rubocop`
80
- puts `bundle exec rspec`
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}`
@@ -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 = type_check type
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} = #{class_name.camelize}.new args
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 = type_check type
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} = #{class_name.camelize}.find args[:id]
396
+ #{class_name} = ::#{class_name.camelize}.find args[:id]
392
397
  #{class_name}.update args
393
- { #{class_name}: #{class_name.camelize}.find(args[:id]) }
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} = #{class_name.camelize}.find id
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
- # create_confirm
447
- FileUtils.rm_r("./app/graphql/mutations/#{singularized_class_name}")
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 = type_check type
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 = get_test_type type
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"
@@ -1,3 +1,3 @@
1
1
  module Souls
2
- VERSION = "0.9.6"
2
+ VERSION = "0.10.2"
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.9.6
4
+ version: 0.10.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - POPPIN-FUMI