souls 0.23.5 → 0.23.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +73 -138
- data/Gemfile.lock +1 -1
- data/Rakefile +2 -2
- data/exe/souls +68 -68
- data/lib/souls.rb +153 -141
- data/lib/souls/gcloud/compute.rb +61 -51
- data/lib/souls/gcloud/iam.rb +22 -24
- data/lib/souls/generate/application.rb +160 -160
- data/lib/souls/generate/connection.rb +13 -15
- data/lib/souls/generate/edge.rb +13 -15
- data/lib/souls/generate/model.rb +16 -17
- data/lib/souls/generate/mutation.rb +225 -221
- data/lib/souls/generate/policy.rb +44 -45
- data/lib/souls/generate/query.rb +49 -49
- data/lib/souls/generate/resolver.rb +121 -124
- data/lib/souls/generate/rspec_factory.rb +49 -52
- data/lib/souls/generate/rspec_model.rb +17 -18
- data/lib/souls/generate/rspec_mutation.rb +193 -199
- data/lib/souls/generate/rspec_policy.rb +38 -39
- data/lib/souls/generate/rspec_query.rb +133 -140
- data/lib/souls/generate/rspec_resolver.rb +147 -154
- data/lib/souls/generate/type.rb +34 -25
- data/lib/souls/init.rb +51 -50
- data/lib/souls/version.rb +2 -1
- data/souls.gemspec +12 -7
- metadata +5 -5
@@ -1,180 +1,180 @@
|
|
1
1
|
module Souls
|
2
2
|
module Generate
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
end
|
3
|
+
## Common Methods
|
4
|
+
def self.generated_paths(class_name: "user")
|
5
|
+
singularized_class_name = class_name.singularize.underscore
|
6
|
+
pluralized_class_name = class_name.pluralize.underscore
|
7
|
+
[
|
8
|
+
"./app/models/#{singularized_class_name}.rb",
|
9
|
+
"./app/policies/#{singularized_class_name}_policy.rb",
|
10
|
+
"./app/graphql/mutations/create_#{singularized_class_name}.rb",
|
11
|
+
"./app/graphql/mutations/delete_#{singularized_class_name}.rb",
|
12
|
+
"./app/graphql/mutations/destroy_delete_#{singularized_class_name}.rb",
|
13
|
+
"./app/graphql/mutations/update_#{singularized_class_name}.rb",
|
14
|
+
"./app/graphql/queries/#{singularized_class_name}.rb",
|
15
|
+
"./app/graphql/queries/#{pluralized_class_name}.rb",
|
16
|
+
"./app/graphql/resolvers/#{singularized_class_name}_search.rb",
|
17
|
+
"./app/graphql/types/#{singularized_class_name}_type.rb",
|
18
|
+
"./app/graphql/types/edges/#{singularized_class_name}_edge.rb",
|
19
|
+
"./app/graphql/types/connections/#{singularized_class_name}_connection.rb",
|
20
|
+
"./spec/factories/#{pluralized_class_name}.rb",
|
21
|
+
"./spec/mutations/#{singularized_class_name}_spec.rb",
|
22
|
+
"./spec/models/#{singularized_class_name}_spec.rb",
|
23
|
+
"./spec/queries/#{singularized_class_name}_spec.rb",
|
24
|
+
"./spec/policies/#{singularized_class_name}_policy_spec.rb",
|
25
|
+
"./spec/resolvers/#{singularized_class_name}_search_spec.rb"
|
26
|
+
]
|
27
|
+
end
|
29
28
|
|
30
|
-
|
31
|
-
|
32
|
-
|
29
|
+
def self.get_type_and_name(line)
|
30
|
+
line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
|
31
|
+
end
|
33
32
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
end
|
33
|
+
def self.get_tables
|
34
|
+
path = "./db/schema.rb"
|
35
|
+
tables = []
|
36
|
+
File.open(path, "r") do |f|
|
37
|
+
f.each_line.with_index do |line, _i|
|
38
|
+
tables << line.split("\"")[1] if line.include?("create_table")
|
41
39
|
end
|
42
|
-
tables
|
43
40
|
end
|
41
|
+
tables
|
42
|
+
end
|
44
43
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
44
|
+
def self.test_dir
|
45
|
+
FileUtils.mkdir_p("./app/graphql/mutations")
|
46
|
+
FileUtils.mkdir_p("./app/graphql/queries")
|
47
|
+
FileUtils.mkdir_p("./app/graphql/types")
|
48
|
+
FileUtils.mkdir_p("./app/graphql/resolvers")
|
49
|
+
FileUtils.mkdir_p("./app/models")
|
50
|
+
FileUtils.mkdir_p("./app/policies")
|
51
|
+
FileUtils.mkdir_p("./spec/factories")
|
52
|
+
FileUtils.mkdir_p("./spec/queries")
|
53
|
+
FileUtils.mkdir_p("./spec/mutations")
|
54
|
+
FileUtils.mkdir_p("./spec/models")
|
55
|
+
FileUtils.mkdir_p("./spec/resolvers")
|
56
|
+
FileUtils.mkdir_p("./spec/policies")
|
57
|
+
FileUtils.mkdir_p("./config")
|
58
|
+
FileUtils.touch("./config/souls.rb")
|
59
|
+
FileUtils.mkdir_p("./db/")
|
60
|
+
FileUtils.touch("./db/schema.rb")
|
61
|
+
puts("test dir created!")
|
62
|
+
end
|
64
63
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
64
|
+
def self.type_check(type)
|
65
|
+
{
|
66
|
+
bigint: "Integer",
|
67
|
+
string: "String",
|
68
|
+
float: "Float",
|
69
|
+
text: "String",
|
70
|
+
datetime: "String",
|
71
|
+
date: "String",
|
72
|
+
boolean: "Boolean",
|
73
|
+
integer: "Integer"
|
74
|
+
}[type.to_sym]
|
75
|
+
end
|
77
76
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
77
|
+
def self.get_test_type(type)
|
78
|
+
{
|
79
|
+
bigint: 1,
|
80
|
+
float: 4.2,
|
81
|
+
string: '"MyString"',
|
82
|
+
text: '"MyString"',
|
83
|
+
datetime: "Time.now",
|
84
|
+
date: "Time.now",
|
85
|
+
boolean: false,
|
86
|
+
integer: 1
|
87
|
+
}[type.to_sym]
|
88
|
+
end
|
90
89
|
|
91
|
-
|
92
|
-
|
93
|
-
return true
|
94
|
-
end
|
95
|
-
false
|
96
|
-
end
|
90
|
+
def self.table_check(line: "", class_name: "")
|
91
|
+
if line.include?("create_table") && (line.split[1].gsub("\"", "").gsub(",", "") == class_name.pluralize.to_s)
|
97
92
|
|
98
|
-
|
99
|
-
singularized_class_name = class_name.singularize
|
100
|
-
model(class_name: singularized_class_name)
|
101
|
-
type(class_name: singularized_class_name)
|
102
|
-
edge(class_name: singularized_class_name)
|
103
|
-
connection(class_name: singularized_class_name)
|
104
|
-
resolver(class_name: singularized_class_name)
|
105
|
-
rspec_factory(class_name: singularized_class_name)
|
106
|
-
rspec_model(class_name: singularized_class_name)
|
107
|
-
rspec_mutation(class_name: singularized_class_name)
|
108
|
-
rspec_query(class_name: singularized_class_name)
|
109
|
-
rspec_resolver(class_name: singularized_class_name)
|
110
|
-
query(class_name: singularized_class_name)
|
111
|
-
mutation(class_name: singularized_class_name)
|
112
|
-
policy(class_name: singularized_class_name)
|
113
|
-
rspec_policy(class_name: singularized_class_name)
|
114
|
-
rescue StandardError => e
|
115
|
-
raise StandardError, e
|
93
|
+
return true
|
116
94
|
end
|
117
95
|
|
118
|
-
|
119
|
-
|
120
|
-
pluralized_class_name = class_name.pluralize.underscore
|
121
|
-
FileUtils.rm "./app/models/#{singularized_class_name}.rb"
|
122
|
-
FileUtils.rm "./app/policies/#{singularized_class_name}_policy.rb"
|
123
|
-
FileUtils.rm_rf "./app/graphql/mutations/#{singularized_class_name}"
|
124
|
-
FileUtils.rm "./app/graphql/queries/#{singularized_class_name}.rb"
|
125
|
-
FileUtils.rm "./app/graphql/queries/#{pluralized_class_name}.rb"
|
126
|
-
FileUtils.rm "./app/graphql/resolvers/#{singularized_class_name}_search.rb"
|
127
|
-
FileUtils.rm "./app/graphql/types/#{singularized_class_name}_type.rb"
|
128
|
-
FileUtils.rm "./app/graphql/types/edges/#{singularized_class_name}_edge.rb"
|
129
|
-
FileUtils.rm "./app/graphql/types/connections/#{singularized_class_name}_connection.rb"
|
130
|
-
FileUtils.rm "./spec/factories/#{pluralized_class_name}.rb"
|
131
|
-
FileUtils.rm "./spec/mutations/#{singularized_class_name}_spec.rb"
|
132
|
-
FileUtils.rm "./spec/models/#{singularized_class_name}_spec.rb"
|
133
|
-
FileUtils.rm "./spec/queries/#{singularized_class_name}_spec.rb"
|
134
|
-
FileUtils.rm "./spec/policies/#{singularized_class_name}_policy_spec.rb"
|
135
|
-
FileUtils.rm "./spec/resolvers/#{singularized_class_name}_search_spec.rb"
|
136
|
-
puts "deleted #{class_name.camelize} CRUD!"
|
137
|
-
rescue StandardError => error
|
138
|
-
puts error
|
139
|
-
end
|
96
|
+
false
|
97
|
+
end
|
140
98
|
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
99
|
+
def self.migrate(class_name: "souls")
|
100
|
+
singularized_class_name = class_name.singularize
|
101
|
+
model(class_name: singularized_class_name)
|
102
|
+
type(class_name: singularized_class_name)
|
103
|
+
edge(class_name: singularized_class_name)
|
104
|
+
connection(class_name: singularized_class_name)
|
105
|
+
resolver(class_name: singularized_class_name)
|
106
|
+
rspec_factory(class_name: singularized_class_name)
|
107
|
+
rspec_model(class_name: singularized_class_name)
|
108
|
+
rspec_mutation(class_name: singularized_class_name)
|
109
|
+
rspec_query(class_name: singularized_class_name)
|
110
|
+
rspec_resolver(class_name: singularized_class_name)
|
111
|
+
query(class_name: singularized_class_name)
|
112
|
+
mutation(class_name: singularized_class_name)
|
113
|
+
policy(class_name: singularized_class_name)
|
114
|
+
rspec_policy(class_name: singularized_class_name)
|
115
|
+
rescue StandardError => e
|
116
|
+
raise(StandardError, e)
|
117
|
+
end
|
158
118
|
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
119
|
+
def self.delete_all(class_name: "souls")
|
120
|
+
singularized_class_name = class_name.singularize.underscore
|
121
|
+
pluralized_class_name = class_name.pluralize.underscore
|
122
|
+
FileUtils.rm("./app/models/#{singularized_class_name}.rb")
|
123
|
+
FileUtils.rm("./app/policies/#{singularized_class_name}_policy.rb")
|
124
|
+
FileUtils.rm_rf("./app/graphql/mutations/#{singularized_class_name}")
|
125
|
+
FileUtils.rm("./app/graphql/queries/#{singularized_class_name}.rb")
|
126
|
+
FileUtils.rm("./app/graphql/queries/#{pluralized_class_name}.rb")
|
127
|
+
FileUtils.rm("./app/graphql/resolvers/#{singularized_class_name}_search.rb")
|
128
|
+
FileUtils.rm("./app/graphql/types/#{singularized_class_name}_type.rb")
|
129
|
+
FileUtils.rm("./app/graphql/types/edges/#{singularized_class_name}_edge.rb")
|
130
|
+
FileUtils.rm("./app/graphql/types/connections/#{singularized_class_name}_connection.rb")
|
131
|
+
FileUtils.rm("./spec/factories/#{pluralized_class_name}.rb")
|
132
|
+
FileUtils.rm("./spec/mutations/#{singularized_class_name}_spec.rb")
|
133
|
+
FileUtils.rm("./spec/models/#{singularized_class_name}_spec.rb")
|
134
|
+
FileUtils.rm("./spec/queries/#{singularized_class_name}_spec.rb")
|
135
|
+
FileUtils.rm("./spec/policies/#{singularized_class_name}_policy_spec.rb")
|
136
|
+
FileUtils.rm("./spec/resolvers/#{singularized_class_name}_search_spec.rb")
|
137
|
+
puts("deleted #{class_name.camelize} CRUD!")
|
138
|
+
rescue StandardError => e
|
139
|
+
puts(e)
|
140
|
+
end
|
167
141
|
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
142
|
+
def self.update_delete(class_name: "souls")
|
143
|
+
singularized_class_name = class_name.singularize.underscore
|
144
|
+
pluralized_class_name = class_name.pluralize.underscore
|
145
|
+
FileUtils.rm_rf("./app/graphql/mutations/#{singularized_class_name}")
|
146
|
+
FileUtils.rm("./app/graphql/queries/#{singularized_class_name}.rb")
|
147
|
+
FileUtils.rm("./app/graphql/queries/#{pluralized_class_name}.rb")
|
148
|
+
FileUtils.rm("./app/graphql/resolvers/#{singularized_class_name}_search.rb")
|
149
|
+
FileUtils.rm("./app/graphql/types/#{singularized_class_name}_type.rb")
|
150
|
+
FileUtils.rm("./app/graphql/types/edges/#{singularized_class_name}_edge.rb")
|
151
|
+
FileUtils.rm("./app/graphql/types/connections/#{singularized_class_name}_connection.rb")
|
152
|
+
FileUtils.rm("./spec/mutations/#{singularized_class_name}_spec.rb")
|
153
|
+
FileUtils.rm("./spec/queries/#{singularized_class_name}_spec.rb")
|
154
|
+
FileUtils.rm("./spec/resolvers/#{singularized_class_name}_search_spec.rb")
|
155
|
+
puts("deleted #{class_name.camelize} CRUD!")
|
156
|
+
rescue StandardError => e
|
157
|
+
puts(e)
|
158
|
+
end
|
159
|
+
|
160
|
+
def self.single_migrate(class_name: "user")
|
161
|
+
puts("◆◆◆ Let's Auto Generate CRUD API SET ◆◆◆\n")
|
162
|
+
migrate(class_name: class_name)
|
163
|
+
puts("Generated #{class_name.camelize} CRUD Files\n")
|
164
|
+
Souls::Generate.generated_paths(class_name: class_name).each { |f| puts(f) }
|
165
|
+
puts("\nAll files created from ./db/schema.rb")
|
166
|
+
puts("\n\n")
|
167
|
+
end
|
168
|
+
|
169
|
+
def self.migrate_all
|
170
|
+
puts("◆◆◆ SOULs CRUD Assist ◆◆◆\n")
|
171
|
+
get_tables.each do |class_name|
|
172
|
+
migrate(class_name: class_name.singularize)
|
173
|
+
puts("Generated #{class_name.camelize} CRUD Files\n")
|
174
|
+
Souls::Generate.generated_paths(class_name: class_name).each { |f| puts(f) }
|
175
|
+
puts("\n")
|
177
176
|
end
|
177
|
+
puts("\nAll files created from ./db/schema.rb\n\n You're all set ;)")
|
178
178
|
end
|
179
179
|
end
|
180
180
|
end
|
@@ -1,21 +1,19 @@
|
|
1
1
|
module Souls
|
2
2
|
module Generate
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
EOS
|
13
|
-
end
|
14
|
-
puts Paint % ["Created file! : %{white_text}", :green, { white_text: [file_path.to_s, :white] }]
|
15
|
-
file_path
|
16
|
-
rescue StandardError => e
|
17
|
-
raise StandardError, e
|
3
|
+
def self.connection(class_name: "souls")
|
4
|
+
singularized_class_name = class_name.underscore.singularize
|
5
|
+
file_path = "./app/graphql/types/connections/#{singularized_class_name}_connection.rb"
|
6
|
+
File.open(file_path, "w") do |f|
|
7
|
+
f.write(<<~TEXT)
|
8
|
+
class Types::#{singularized_class_name.camelize}Connection < Types::BaseConnection
|
9
|
+
edge_type(Types::#{singularized_class_name.camelize}Edge)
|
10
|
+
end
|
11
|
+
TEXT
|
18
12
|
end
|
13
|
+
puts(Paint % ["Created file! : %{white_text}", :green, { white_text: [file_path.to_s, :white] }])
|
14
|
+
file_path
|
15
|
+
rescue StandardError => e
|
16
|
+
raise(StandardError, e)
|
19
17
|
end
|
20
18
|
end
|
21
19
|
end
|
data/lib/souls/generate/edge.rb
CHANGED
@@ -1,21 +1,19 @@
|
|
1
1
|
module Souls
|
2
2
|
module Generate
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
EOS
|
13
|
-
end
|
14
|
-
puts Paint % ["Created file! : %{white_text}", :green, { white_text: [file_path.to_s, :white] }]
|
15
|
-
file_path
|
16
|
-
rescue StandardError => e
|
17
|
-
raise StandardError, e
|
3
|
+
def self.edge(class_name: "souls")
|
4
|
+
singularized_class_name = class_name.underscore.singularize
|
5
|
+
file_path = "./app/graphql/types/edges/#{singularized_class_name}_edge.rb"
|
6
|
+
File.open(file_path, "w") do |f|
|
7
|
+
f.write(<<~TEXT)
|
8
|
+
class Types::#{singularized_class_name.camelize}Edge < Types::BaseEdge
|
9
|
+
node_type(Types::#{singularized_class_name.camelize}Type)
|
10
|
+
end
|
11
|
+
TEXT
|
18
12
|
end
|
13
|
+
puts(Paint % ["Created file! : %{white_text}", :green, { white_text: [file_path.to_s, :white] }])
|
14
|
+
file_path
|
15
|
+
rescue StandardError => e
|
16
|
+
raise(StandardError, e)
|
19
17
|
end
|
20
18
|
end
|
21
19
|
end
|
data/lib/souls/generate/model.rb
CHANGED
@@ -1,23 +1,22 @@
|
|
1
1
|
module Souls
|
2
2
|
module Generate
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
end
|
16
|
-
puts Paint % ["Created file! : %{white_text}", :green, { white_text: [file_path.to_s, :white] }]
|
17
|
-
file_path
|
18
|
-
rescue StandardError => e
|
19
|
-
raise StandardError, e
|
3
|
+
## Generate Model
|
4
|
+
def self.model(class_name: "souls")
|
5
|
+
file_dir = "./app/models/"
|
6
|
+
FileUtils.mkdir_p(file_dir) unless Dir.exist?(file_dir)
|
7
|
+
file_path = "#{file_dir}#{class_name.singularize}.rb"
|
8
|
+
return "Model already exist! #{file_path}" if File.exist?(file_path)
|
9
|
+
|
10
|
+
File.open(file_path, "w") do |f|
|
11
|
+
f.write(<<~TEXT)
|
12
|
+
class #{class_name.camelize} < ActiveRecord::Base
|
13
|
+
end
|
14
|
+
TEXT
|
20
15
|
end
|
16
|
+
puts(Paint % ["Created file! : %{white_text}", :green, { white_text: [file_path.to_s, :white] }])
|
17
|
+
file_path
|
18
|
+
rescue StandardError => e
|
19
|
+
raise(StandardError, e)
|
21
20
|
end
|
22
21
|
end
|
23
22
|
end
|