souls 0.16.1 → 0.16.6

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: 1c8579754eee9ff09aacd11cd34ec2226db30119240a65c76828abef617afe8a
4
- data.tar.gz: 16ae0929960bec81e1117dce6c8dee35331680706283f189dfb982dea66317b2
3
+ metadata.gz: a327229d00231e3a106e8dd748d083b4fe4a5bc776960144b2eeeed15c0a5a4b
4
+ data.tar.gz: 6fc169ee068d88ac46f2673bd48d89c2e1afb4bfbf75a753a357fe2615166454
5
5
  SHA512:
6
- metadata.gz: 9511ab49084de3324e0a065a468c2940d6fc27e8dd1e7ef6a602a03a22db9ca9a79b0110903869a0acf3b591e0493ed329284f8bdc6b7e2d48116a06c6e239a3
7
- data.tar.gz: 546f6339a8ac3c5fd6b7661bdbce6befe0a9efd98dd1d3d1fac821ec5b5ff22d5d3a4b7be84b1d8bbba60ce0ceda4599bc62fde01fab6275abf7113d54ce0d41
6
+ metadata.gz: 05e475df2a78f94bfa8a3f55441ca563d30b17e7ef6c5c4b5bc39f95a4633864ea785f6b07d798667f6022980ab1bfa0d05f160f0c3a35d5b94444a8b2a46d44
7
+ data.tar.gz: 20b59cdf504c52fb19154f2fb9a89951f0220c0ba1a9fa27c02ccec2b32a2abf5946c253634427a699bcc3a5633f5e1016e21cd4971c3e214a8121c897a2f29e
data/.irbrc CHANGED
@@ -0,0 +1 @@
1
+ require "./lib/souls"
data/.rubocop.yml CHANGED
@@ -79,6 +79,9 @@ Style/HashSyntax:
79
79
  - "**/*.rake"
80
80
  - "Rakefile"
81
81
 
82
+ Layout/HeredocIndentation:
83
+ Enabled: false
84
+
82
85
  Style/IfUnlessModifier:
83
86
  Enabled: false
84
87
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- souls (0.15.9)
4
+ souls (0.16.6)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -19,13 +19,13 @@ GEM
19
19
  concurrent-ruby (1.1.8)
20
20
  diff-lcs (1.4.4)
21
21
  ffi (1.14.2)
22
- i18n (1.8.8)
22
+ i18n (1.8.9)
23
23
  concurrent-ruby (~> 1.0)
24
24
  language_server-protocol (3.15.0.1)
25
25
  listen (3.4.1)
26
26
  rb-fsevent (~> 0.10, >= 0.10.3)
27
27
  rb-inotify (~> 0.9, >= 0.9.10)
28
- minitest (5.14.3)
28
+ minitest (5.14.4)
29
29
  parallel (1.20.1)
30
30
  parser (2.7.2.0)
31
31
  ast (~> 2.4.1)
@@ -34,8 +34,8 @@ GEM
34
34
  rb-fsevent (0.10.4)
35
35
  rb-inotify (0.10.1)
36
36
  ffi (~> 1.0)
37
- rbs (1.0.4)
38
- regexp_parser (2.0.3)
37
+ rbs (1.0.6)
38
+ regexp_parser (2.1.1)
39
39
  rexml (3.2.4)
40
40
  rspec (3.1.0)
41
41
  rspec-core (~> 3.1.0)
@@ -76,7 +76,7 @@ GEM
76
76
  zeitwerk (2.4.2)
77
77
 
78
78
  PLATFORMS
79
- ruby
79
+ x86_64-darwin-20
80
80
 
81
81
  DEPENDENCIES
82
82
  activesupport (= 6.1.0)
@@ -87,4 +87,4 @@ DEPENDENCIES
87
87
  steep (= 0.39.0)
88
88
 
89
89
  BUNDLED WITH
90
- 2.2.4
90
+ 2.2.11
data/README.md CHANGED
@@ -76,72 +76,10 @@ And Create Your APP
76
76
  4. Media Web
77
77
  5. Admin Web
78
78
 
79
- ## Usage - 1. GraphQL API
80
79
 
81
- ```bash
82
- # Ruby version (using rbenv)
83
- $ ruby -v
84
- ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x86_64-darwin20]
80
+ ## SOULs Document
85
81
 
86
- # Install xcode
87
- $ xcode-select --install
88
-
89
- # Install PostgreSQL (Mac env)
90
- $ brew install postgresql
91
-
92
- # Install redis
93
- $ brew install redis
94
-
95
- # Version Check
96
- $ souls -v
97
-
98
- # Init SOULs App
99
- $ souls new app_name
100
- $ cd app_name
101
- $ bundle
102
-
103
- # Run Dev & Test DB
104
- $ souls i run_psql
105
-
106
- # Create DB
107
- $ souls db:create
108
-
109
- # Migrate DB
110
- $ souls db:migrate
111
-
112
- # Create Test DB
113
- $ souls db:seed
114
-
115
- # Development (localhost:3000/playground)
116
- $ souls s
117
-
118
- # Development with Worker (localhost:3000/playground; localhost:3000/sidekiq)
119
- $ foreman start -f Procfile.dev
120
-
121
- # Test
122
- $ bundle exec rspec
123
-
124
- # Deploy (Edit: ./cloudbuild.yml)
125
- $ souls deploy
126
-
127
- # Run Infra Command
128
- $ souls i `method_name`
129
- ```
130
-
131
- ## SOULs Scaffold
132
- SOULs Scaffold creates CRUD API from `./db/schema.rb`
133
-
134
- ```bash
135
- # Create migration file
136
- $ souls g migration user
137
-
138
- # Edit migration file
139
- # Migrate DB
140
- $ souls db:migrate
141
-
142
- # SOULs Scaffold
143
- $ souls g migrate user
144
- ```
82
+ - [SOULs Document](https://elsoul.github.io/souls_doc/)
145
83
 
146
84
 
147
85
 
data/exe/souls CHANGED
@@ -25,7 +25,7 @@ begin
25
25
  when "service"
26
26
  system "bundle exec rake run_server"
27
27
  else
28
- `bundle exec puma -p 3000 -e development`
28
+ system "foreman start -f Procfile.dev"
29
29
  end
30
30
  when "c", "console"
31
31
  strain = Souls.configuration.strain
@@ -33,7 +33,12 @@ begin
33
33
  when "media", "admin"
34
34
  system "yarn dev"
35
35
  else
36
- `bundle exec irb`
36
+ case ARGV[1]
37
+ when "RACK_ENV=production"
38
+ system "bundle exec irb RACK_ENV=production"
39
+ else
40
+ system "bundle exec irb"
41
+ end
37
42
  end
38
43
  when "i", "infra"
39
44
  Souls.send ARGV[1]
@@ -66,7 +71,7 @@ begin
66
71
  when "migrate_all"
67
72
  Souls::Init.migrate_all
68
73
  when "migration"
69
- STDOUT.write `rake db:create_migration NAME=#{ARGV[2]}`
74
+ system "rake db:create_migration NAME=create_#{ARGV[2]}"
70
75
  when "rspec_factory"
71
76
  Souls::Init.rspec_factory class_name: ARGV[2]
72
77
  when "rspec_model"
@@ -82,23 +87,35 @@ begin
82
87
  else
83
88
  "SOULs!"
84
89
  end
90
+ when "d"
91
+ Souls::Init.delete_all class_name: ARGV[1]
85
92
  when "db:create"
86
- STDOUT.write `rake db:create && rake db:create RACK_ENV=test`
93
+ system "rake db:create && rake db:create RACK_ENV=test"
87
94
  when "db:migrate"
88
- STDOUT.write `rake db:migrate && rake db:migrate RACK_ENV=test`
95
+ case ARGV[1]
96
+ when "RACK_ENV=production"
97
+ system "rake db:migrate RACK_ENV=production"
98
+ else
99
+ system "rake db:migrate && rake db:migrate RACK_ENV=test"
100
+ end
89
101
  when "db:seed"
90
- STDOUT.write `rake db:seed`
102
+ system "rake db:seed"
91
103
  when "db:migrate:reset"
92
- STDOUT.write `rake db:migrate:reset && rake db:migrate:reset RACK_ENV=test`
104
+ case ARGV[1]
105
+ when "RACK_ENV=production"
106
+ system "rake db:migrate:reset RACK_ENV=production DISABLE_DATABASE_ENVIRONMENT_CHECK=1"
107
+ else
108
+ system "rake db:migrate:reset && rake db:migrate:reset RACK_ENV=test"
109
+ end
93
110
  when "t", "test"
94
- STDOUT.write `rubocop`
95
- STDOUT.write `bundle exec rspec`
111
+ system "rubocop -a"
112
+ system "bundle exec rspec"
96
113
  when "run"
97
- STDOUT.write `docker build . -t souls:latest`
98
- STDOUT.write `docker run --rm -p 3000:3000 souls:latest`
114
+ system "docker build . -t souls:latest"
115
+ system "docker run --rm -p 3000:3000 souls:latest"
99
116
  when "deploy"
100
117
  project_id = Souls.configuration.project_id
101
- STDOUT.write `gcloud builds submit --config=cloudbuild.yml --project #{project_id}`
118
+ system "gcloud builds submit --config=cloudbuild.yml --project #{project_id}"
102
119
  else
103
120
  puts "Welcome to SOULs!"
104
121
  end
data/lib/souls.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  require "souls/version"
2
+ require "active_support/core_ext/string/inflections"
2
3
  require "souls/init"
3
4
  require "souls/generate"
4
5
  require "json"
5
- require "active_support/core_ext/string/inflections"
6
6
  require "fileutils"
7
7
 
8
8
  module Souls
@@ -1,6 +1,10 @@
1
1
  module Souls
2
2
  module Init
3
3
  class << self
4
+ def get_type_and_name line
5
+ line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
6
+ end
7
+
4
8
  def node_type class_name: "souls"
5
9
  file_path = "./app/graphql/types/#{class_name.singularize}_node_type.rb"
6
10
  File.open(file_path, "w") do |f|
@@ -15,9 +19,10 @@ module Souls
15
19
  [file_path]
16
20
  end
17
21
 
18
- def resolver class_name: "souls"
22
+ def resolver_head class_name: "souls"
19
23
  FileUtils.mkdir_p "./app/graphql/resolvers" unless Dir.exist? "./app/graphql/resolvers"
20
24
  file_path = "./app/graphql/resolvers/#{class_name.singularize}_search.rb"
25
+ @relation_params = []
21
26
  return ["Resolver already exist! #{file_path}"] if File.exist? file_path
22
27
  File.open(file_path, "w") do |f|
23
28
  f.write <<~EOS
@@ -30,54 +35,147 @@ module Souls
30
35
 
31
36
  class #{class_name.camelize}Filter < ::Types::BaseInputObject
32
37
  argument :OR, [self], required: false
38
+ EOS
39
+ end
40
+ end
33
41
 
34
- argument :is_deleted, Boolean, required: false
35
- argument :start_date, String, required: false
36
- argument :end_date, String, required: false
42
+ def resolver_params class_name: "souls"
43
+ file_path = "./app/graphql/resolvers/#{class_name.singularize}_search.rb"
44
+ path = "./db/schema.rb"
45
+ @on = false
46
+ @user_exist = false
47
+ @relation_params = []
48
+ File.open(file_path, "a") do |new_line|
49
+ File.open(path, "r") do |f|
50
+ f.each_line.with_index do |line, i|
51
+ if @on
52
+ if line.include?("end") || line.include?("t.index")
53
+ break
37
54
  end
38
-
39
- option :filter, type: #{class_name.camelize}Filter, with: :apply_filter
40
- option :first, type: types.Int, with: :apply_first
41
- option :skip, type: types.Int, with: :apply_skip
42
-
43
- def apply_filter(scope, value)
44
- branches = normalize_filters(value).inject { |a, b| a.or(b) }
45
- scope.merge branches
55
+ field = "[String]" if line.include?("array: true")
56
+ type, name = get_type_and_name(line)
57
+ field ||= type_check type
58
+ case name
59
+ when "user_id"
60
+ @user_exist = true
61
+ when /$*_id\z/
62
+ @relation_params << name
63
+ new_line.write " argument :#{name}, String, required: false\n"
64
+ when "created_at", "updated_at"
65
+ next
66
+ else
67
+ new_line.write " argument :#{name}, #{field}, required: false\n"
46
68
  end
69
+ end
70
+ @on = true if table_check(line: line, class_name: class_name)
71
+ end
72
+ end
73
+ end
74
+ end
47
75
 
48
- def apply_first(scope, value)
49
- scope.limit(value)
50
- end
76
+ def resolver_after_params class_name: "souls"
77
+ file_path = "./app/graphql/resolvers/#{class_name.singularize}_search.rb"
78
+ File.open(file_path, "a") do |f|
79
+ f.write <<-EOS
80
+ argument :is_deleted, Boolean, required: false
81
+ argument :start_date, String, required: false
82
+ argument :end_date, String, required: false
83
+ end
51
84
 
52
- def apply_skip(scope, value)
53
- scope.offset(value)
54
- end
85
+ option :filter, type: #{class_name.camelize}Filter, with: :apply_filter
86
+ option :first, type: types.Int, with: :apply_first
87
+ option :skip, type: types.Int, with: :apply_skip
55
88
 
56
- def decode_global_key id
57
- _, data_id = SoulsApiSchema.from_global_id id
58
- data_id
59
- end
89
+ def apply_filter(scope, value)
90
+ branches = normalize_filters(value).inject { |a, b| a.or(b) }
91
+ scope.merge branches
92
+ end
60
93
 
61
- def normalize_filters(value, branches = [])
62
- scope = ::#{class_name.camelize}.all
94
+ def apply_first(scope, value)
95
+ scope.limit(value)
96
+ end
63
97
 
64
- scope = scope.where(is_deleted: value[:is_deleted]) if value[:is_deleted]
65
- scope = scope.where("created_at >= ?", value[:start_date]) if value[:start_date]
66
- scope = scope.where("created_at <= ?", value[:end_date]) if value[:end_date]
98
+ def apply_skip(scope, value)
99
+ scope.offset(value)
100
+ end
67
101
 
68
- branches << scope
102
+ def decode_global_key id
103
+ _, data_id = SoulsApiSchema.from_global_id id
104
+ data_id
105
+ end
69
106
 
70
- value[:OR].inject(branches) { |s, v| normalize_filters(v, s) } if value[:OR].present?
107
+ def normalize_filters(value, branches = [])
108
+ scope = ::#{class_name.camelize}.all
109
+ EOS
110
+ end
111
+ end
71
112
 
72
- branches
113
+ def resolver_before_end class_name: "souls"
114
+ file_path = "./app/graphql/resolvers/#{class_name.singularize}_search.rb"
115
+ path = "./db/schema.rb"
116
+ @on = false
117
+ @user_exist = false
118
+ @relation_params = []
119
+ File.open(file_path, "a") do |new_line|
120
+ File.open(path, "r") do |f|
121
+ f.each_line.with_index do |line, i|
122
+ if @on
123
+ if line.include?("end") || line.include?("t.index")
124
+ break
125
+ end
126
+ _, name = get_type_and_name(line)
127
+ if line.include?("array: true")
128
+ new_line.write " scope = scope.where(\"#{name} @> ARRAY[?]::text[]\", value[:#{name}]) if value[:#{name}]\n"
129
+ next
130
+ end
131
+ case name
132
+ when "user_id"
133
+ @user_exist = true
134
+ when /$*_id\z/
135
+ @relation_params << name
136
+ new_line.write " scope = scope.where(#{name}: decode_global_key(value[:#{name}])) if value[:#{name}]\n"
137
+ when "created_at", "updated_at"
138
+ next
139
+ else
140
+ new_line.write " scope = scope.where(#{name}: value[:#{name}]) if value[:#{name}]\n"
73
141
  end
74
142
  end
143
+ @on = true if table_check(line: line, class_name: class_name)
75
144
  end
145
+ end
146
+ end
147
+ end
148
+
149
+ def resolver_end class_name: "souls"
150
+ file_path = "./app/graphql/resolvers/#{class_name.singularize}_search.rb"
151
+ File.open(file_path, "a") do |f|
152
+ f.write <<-EOS
153
+ scope = scope.where(is_deleted: value[:is_deleted]) if value[:is_deleted]
154
+ scope = scope.where("created_at >= ?", value[:start_date]) if value[:start_date]
155
+ scope = scope.where("created_at <= ?", value[:end_date]) if value[:end_date]
156
+
157
+ branches << scope
158
+
159
+ value[:OR].inject(branches) { |s, v| normalize_filters(v, s) } if value[:OR].present?
160
+
161
+ branches
162
+ end
163
+ end
164
+ end
76
165
  EOS
77
166
  end
78
167
  [file_path]
79
168
  end
80
169
 
170
+ def resolver class_name: "souls"
171
+ singularized_class_name = class_name.singularize.underscore
172
+ resolver_head class_name: singularized_class_name
173
+ resolver_params class_name: singularized_class_name
174
+ resolver_after_params class_name: singularized_class_name
175
+ resolver_before_end class_name: singularized_class_name
176
+ resolver_end class_name: singularized_class_name
177
+ end
178
+
81
179
  def job class_name: "send_mail"
82
180
  file_path = "./app/jobs/#{class_name.singularize}_job.rb"
83
181
  return ["Job already exist! #{file_path}"] if File.exist? file_path
@@ -280,6 +378,26 @@ end
280
378
  rspec_resolver_params class_name: singularized_class_name
281
379
  rspec_resolver_end class_name: singularized_class_name
282
380
  end
381
+
382
+ def delete_all class_name: "souls"
383
+ singularized_class_name = class_name.singularize.underscore
384
+ pluralized_class_name = class_name.pluralize.underscore
385
+ FileUtils.rm "./app/models/#{singularized_class_name}.rb"
386
+ FileUtils.rm_rf "./app/graphql/mutations/#{singularized_class_name}"
387
+ FileUtils.rm "./app/graphql/queries/#{singularized_class_name}.rb"
388
+ FileUtils.rm "./app/graphql/queries/#{pluralized_class_name}.rb"
389
+ FileUtils.rm "./app/graphql/resolvers/#{singularized_class_name}_search.rb"
390
+ FileUtils.rm "./app/graphql/types/#{singularized_class_name}_type.rb"
391
+ FileUtils.rm "./app/graphql/types/#{singularized_class_name}_node_type.rb"
392
+ FileUtils.rm "./spec/factories/#{pluralized_class_name}.rb"
393
+ FileUtils.rm "./spec/mutations/#{singularized_class_name}_spec.rb"
394
+ FileUtils.rm "./spec/models/#{singularized_class_name}_spec.rb"
395
+ FileUtils.rm "./spec/queries/#{singularized_class_name}_spec.rb"
396
+ FileUtils.rm "./spec/resolvers/#{singularized_class_name}_search_spec.rb"
397
+ puts "deleted #{class_name.camelize} CRUD!"
398
+ rescue StandardError => error
399
+ puts error
400
+ end
283
401
  end
284
402
  end
285
403
  end
data/lib/souls/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Souls
2
- VERSION = "0.16.1"
2
+ VERSION = "0.16.6"
3
3
  end
data/souls.gemspec CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.description = "SOULS is a Web Application Framework for Microservices on Multi Cloud Platform such as Google Cloud Platform, Amazon Web Services, and Alibaba Cloud. Auto deploy with scalable condition. You can focus on business logic. No more infra problems."
11
11
  spec.homepage = "https://github.com/elsoul/souls"
12
12
  spec.license = "Apache-2.0"
13
- spec.required_ruby_version = Gem::Requirement.new(">= 2.7.0")
13
+ spec.required_ruby_version = Gem::Requirement.new(">= 3.0.0")
14
14
 
15
15
  spec.metadata["homepage_uri"] = spec.homepage
16
16
  spec.metadata["source_code_uri"] = "https://github.com/elsoul/souls"
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.16.1
4
+ version: 0.16.6
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-02-15 00:00:00.000000000 Z
13
+ date: 2021-03-02 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.
@@ -63,7 +63,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
63
63
  requirements:
64
64
  - - ">="
65
65
  - !ruby/object:Gem::Version
66
- version: 2.7.0
66
+ version: 3.0.0
67
67
  required_rubygems_version: !ruby/object:Gem::Requirement
68
68
  requirements:
69
69
  - - ">="