souls 0.16.2 → 0.16.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: 379d74f36f45442d0a3140ecef6d0138e502fcb00ca4d83be79a68cbf204dbbb
4
- data.tar.gz: e71e854b0e31bdf14421c8d15769731d8c1db1d7f5e0aa02e55d7ca57fc3fa14
3
+ metadata.gz: 8f0df698e69275cc28c4f58e2b83bab33ad7ee2d3f34cc928bda1d7b42198ca5
4
+ data.tar.gz: fa40ef64c0ade791ef760a3d912f0d97fb7fb6ff39db09c07022af44f821cea6
5
5
  SHA512:
6
- metadata.gz: eb489b527ea9ff1237f32ee0a7c7316122790730f2d92e7b5e95b6002d4077822d6d29b396fc1e5d45b73987368cf456b5d41026ff5f8b3aa7359c17aee5894d
7
- data.tar.gz: 9bd62c23a3d81bff36057e91b38260172493ff714254af06fabfa44f98f2c30c4dfb044c280b8eeb747da78531ed2e520ea0e1f75766732ea40e3851a9c91712
6
+ metadata.gz: c27e742bca22479ce7967648984220104d8ede75172e73e3ff541e8a4649a3fed658630e94f7e3bc02b9480a39ba16545c3026c22fc2ce11b25c75a49c90d7e1
7
+ data.tar.gz: a1cd25dc4863a3639cf466f186ad01e832a910b5f974444c6c52c66c54f6b89c235843535560d0f5ae610b457364a06aeecb34171d0520bfa4e5ca4090d8d078
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.16.1)
4
+ souls (0.16.7)
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
@@ -33,7 +33,12 @@ begin
33
33
  when "media", "admin"
34
34
  system "yarn dev"
35
35
  else
36
- system "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]
@@ -82,16 +87,28 @@ 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
93
  system "rake db:create && rake db:create RACK_ENV=test"
87
94
  when "db:migrate"
88
- system "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
102
  system "rake db:seed"
91
103
  when "db:migrate:reset"
92
- system "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
- system "rubocop"
111
+ system "rubocop -a"
95
112
  system "bundle exec rspec"
96
113
  when "run"
97
114
  system "docker build . -t souls:latest"
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,134 @@ 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
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"
68
+ end
69
+ end
70
+ @on = true if table_check(line: line, class_name: class_name)
71
+ end
72
+ end
73
+ end
74
+ end
38
75
 
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
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
42
84
 
43
- def apply_filter(scope, value)
44
- branches = normalize_filters(value).inject { |a, b| a.or(b) }
45
- scope.merge branches
46
- 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
47
88
 
48
- def apply_first(scope, value)
49
- scope.limit(value)
50
- end
89
+ def apply_filter(scope, value)
90
+ branches = normalize_filters(value).inject { |a, b| a.or(b) }
91
+ scope.merge branches
92
+ end
51
93
 
52
- def apply_skip(scope, value)
53
- scope.offset(value)
54
- end
94
+ def normalize_filters(value, branches = [])
95
+ scope = ::#{class_name.camelize}.all
96
+ EOS
97
+ end
98
+ end
55
99
 
56
- def decode_global_key id
57
- _, data_id = SoulsApiSchema.from_global_id id
58
- data_id
100
+ def resolver_before_end class_name: "souls"
101
+ file_path = "./app/graphql/resolvers/#{class_name.singularize}_search.rb"
102
+ path = "./db/schema.rb"
103
+ @on = false
104
+ @user_exist = false
105
+ @relation_params = []
106
+ File.open(file_path, "a") do |new_line|
107
+ File.open(path, "r") do |f|
108
+ f.each_line.with_index do |line, i|
109
+ if @on
110
+ if line.include?("end") || line.include?("t.index")
111
+ break
59
112
  end
113
+ _, name = get_type_and_name(line)
114
+ if line.include?("array: true")
115
+ new_line.write " scope = scope.where(\"#{name} @> ARRAY[?]::text[]\", value[:#{name}]) if value[:#{name}]\n"
116
+ next
117
+ end
118
+ case name
119
+ when "user_id"
120
+ @user_exist = true
121
+ when /$*_id\z/
122
+ @relation_params << name
123
+ new_line.write " scope = scope.where(#{name}: decode_global_key(value[:#{name}])) if value[:#{name}]\n"
124
+ when "created_at", "updated_at"
125
+ next
126
+ else
127
+ new_line.write " scope = scope.where(#{name}: value[:#{name}]) if value[:#{name}]\n"
128
+ end
129
+ end
130
+ @on = true if table_check(line: line, class_name: class_name)
131
+ end
132
+ end
133
+ end
134
+ end
60
135
 
61
- def normalize_filters(value, branches = [])
62
- scope = ::#{class_name.camelize}.all
63
-
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]
136
+ def resolver_end class_name: "souls"
137
+ file_path = "./app/graphql/resolvers/#{class_name.singularize}_search.rb"
138
+ File.open(file_path, "a") do |f|
139
+ f.write <<-EOS
140
+ scope = scope.where(is_deleted: value[:is_deleted]) if value[:is_deleted]
141
+ scope = scope.where("created_at >= ?", value[:start_date]) if value[:start_date]
142
+ scope = scope.where("created_at <= ?", value[:end_date]) if value[:end_date]
67
143
 
68
- branches << scope
144
+ branches << scope
69
145
 
70
- value[:OR].inject(branches) { |s, v| normalize_filters(v, s) } if value[:OR].present?
146
+ value[:OR].inject(branches) { |s, v| normalize_filters(v, s) } if value[:OR].present?
71
147
 
72
- branches
73
- end
74
- end
75
- end
148
+ branches
149
+ end
150
+ end
151
+ end
76
152
  EOS
77
153
  end
78
154
  [file_path]
79
155
  end
80
156
 
157
+ def resolver class_name: "souls"
158
+ singularized_class_name = class_name.singularize.underscore
159
+ resolver_head class_name: singularized_class_name
160
+ resolver_params class_name: singularized_class_name
161
+ resolver_after_params class_name: singularized_class_name
162
+ resolver_before_end class_name: singularized_class_name
163
+ resolver_end class_name: singularized_class_name
164
+ end
165
+
81
166
  def job class_name: "send_mail"
82
167
  file_path = "./app/jobs/#{class_name.singularize}_job.rb"
83
168
  return ["Job already exist! #{file_path}"] if File.exist? file_path
@@ -280,6 +365,26 @@ end
280
365
  rspec_resolver_params class_name: singularized_class_name
281
366
  rspec_resolver_end class_name: singularized_class_name
282
367
  end
368
+
369
+ def delete_all class_name: "souls"
370
+ singularized_class_name = class_name.singularize.underscore
371
+ pluralized_class_name = class_name.pluralize.underscore
372
+ FileUtils.rm "./app/models/#{singularized_class_name}.rb"
373
+ FileUtils.rm_rf "./app/graphql/mutations/#{singularized_class_name}"
374
+ FileUtils.rm "./app/graphql/queries/#{singularized_class_name}.rb"
375
+ FileUtils.rm "./app/graphql/queries/#{pluralized_class_name}.rb"
376
+ FileUtils.rm "./app/graphql/resolvers/#{singularized_class_name}_search.rb"
377
+ FileUtils.rm "./app/graphql/types/#{singularized_class_name}_type.rb"
378
+ FileUtils.rm "./app/graphql/types/#{singularized_class_name}_node_type.rb"
379
+ FileUtils.rm "./spec/factories/#{pluralized_class_name}.rb"
380
+ FileUtils.rm "./spec/mutations/#{singularized_class_name}_spec.rb"
381
+ FileUtils.rm "./spec/models/#{singularized_class_name}_spec.rb"
382
+ FileUtils.rm "./spec/queries/#{singularized_class_name}_spec.rb"
383
+ FileUtils.rm "./spec/resolvers/#{singularized_class_name}_search_spec.rb"
384
+ puts "deleted #{class_name.camelize} CRUD!"
385
+ rescue StandardError => error
386
+ puts error
387
+ end
283
388
  end
284
389
  end
285
390
  end
data/lib/souls/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Souls
2
- VERSION = "0.16.2"
2
+ VERSION = "0.16.7"
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.2
4
+ version: 0.16.7
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-18 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
  - - ">="