souls 0.18.2 → 0.20.0
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.
Potentially problematic release.
This version of souls might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -0
- data/Gemfile.lock +1 -1
- data/README.md +7 -9
- data/Rakefile +9 -0
- data/exe/souls +30 -32
- data/lib/souls.rb +15 -37
- data/lib/souls/generate/application.rb +156 -0
- data/lib/souls/generate/model.rb +18 -0
- data/lib/souls/generate/mutation.rb +274 -0
- data/lib/souls/generate/policy.rb +50 -0
- data/lib/souls/generate/query.rb +56 -0
- data/lib/souls/generate/resolver.rb +153 -0
- data/lib/souls/generate/rspec_factory.rb +63 -0
- data/lib/souls/generate/rspec_model.rb +23 -0
- data/lib/souls/generate/rspec_mutation.rb +247 -0
- data/lib/souls/generate/rspec_policy.rb +50 -0
- data/lib/souls/generate/rspec_query.rb +169 -0
- data/lib/souls/generate/rspec_resolver.rb +189 -0
- data/lib/souls/generate/type.rb +83 -0
- data/lib/souls/init.rb +0 -1131
- data/lib/souls/version.rb +1 -1
- data/souls.gemspec +1 -1
- metadata +18 -6
- data/lib/souls/generate.rb +0 -520
@@ -0,0 +1,50 @@
|
|
1
|
+
module Souls
|
2
|
+
module Generate
|
3
|
+
class << self
|
4
|
+
## Generate Rspec Policy
|
5
|
+
def rspec_policy class_name: "souls"
|
6
|
+
dir_name = "./spec/policies"
|
7
|
+
FileUtils.mkdir_p dir_name unless Dir.exist? dir_name
|
8
|
+
file_path = "./spec/policies/#{class_name}_policy_spec.rb"
|
9
|
+
File.open(file_path, "w") do |new_line|
|
10
|
+
new_line.write <<~EOS
|
11
|
+
describe #{class_name.camelize}Policy do
|
12
|
+
subject { described_class.new(user, #{class_name.underscore}) }
|
13
|
+
|
14
|
+
let(:#{class_name.underscore}) { FactoryBot.create(:#{class_name.underscore}) }
|
15
|
+
|
16
|
+
context "being a visitor" do
|
17
|
+
let(:user) { FactoryBot.create(:user) }
|
18
|
+
|
19
|
+
it { is_expected.to permit_action(:index) }
|
20
|
+
it { is_expected.to permit_action(:show) }
|
21
|
+
it { is_expected.to forbid_actions([:create, :update, :delete]) }
|
22
|
+
end
|
23
|
+
|
24
|
+
context "being a retailer" do
|
25
|
+
let(:user) { FactoryBot.create(:user, user_role: 1) }
|
26
|
+
|
27
|
+
it { is_expected.to permit_action(:index) }
|
28
|
+
it { is_expected.to permit_action(:show) }
|
29
|
+
it { is_expected.to forbid_actions([:create, :update, :delete]) }
|
30
|
+
end
|
31
|
+
|
32
|
+
context "being a staff" do
|
33
|
+
let(:user) { FactoryBot.create(:user, user_role: 3) }
|
34
|
+
|
35
|
+
it { is_expected.to permit_actions([:create, :update, :delete]) }
|
36
|
+
end
|
37
|
+
|
38
|
+
context "being an administrator" do
|
39
|
+
let(:user) { FactoryBot.create(:user, user_role: 4) }
|
40
|
+
|
41
|
+
it { is_expected.to permit_actions([:create, :update, :delete]) }
|
42
|
+
end
|
43
|
+
end
|
44
|
+
EOS
|
45
|
+
end
|
46
|
+
file_path
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,169 @@
|
|
1
|
+
module Souls
|
2
|
+
module Generate
|
3
|
+
class << self
|
4
|
+
## Generate Rspec Query
|
5
|
+
def rspec_query_head class_name: "souls"
|
6
|
+
file_path = "./spec/queries/#{class_name.singularize}_spec.rb"
|
7
|
+
File.open(file_path, "w") do |f|
|
8
|
+
f.write <<~EOS
|
9
|
+
RSpec.describe \"#{class_name.camelize} Query テスト\" do
|
10
|
+
describe "#{class_name.camelize} データを取得する" do
|
11
|
+
EOS
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def rspec_query_after_head class_name: "souls"
|
16
|
+
file_path = "./spec/queries/#{class_name.singularize}_spec.rb"
|
17
|
+
path = "./db/schema.rb"
|
18
|
+
@on = false
|
19
|
+
@user_exist = false
|
20
|
+
@relation_params = []
|
21
|
+
File.open(file_path, "a") do |new_line|
|
22
|
+
File.open(path, "r") do |f|
|
23
|
+
f.each_line.with_index do |line, i|
|
24
|
+
if @on
|
25
|
+
if line.include?("end") || line.include?("t.index")
|
26
|
+
if @relation_params.empty?
|
27
|
+
new_line.write <<-EOS
|
28
|
+
let!(:#{class_name}) { FactoryBot.create(:#{class_name}) }
|
29
|
+
|
30
|
+
let(:query) do
|
31
|
+
data_id = Base64.encode64("#{class_name.camelize}:\#{#{class_name.singularize.underscore}.id}")
|
32
|
+
%(query {
|
33
|
+
#{class_name.singularize.camelize(:lower)}(id: \\"\#{data_id}\\") {
|
34
|
+
id
|
35
|
+
EOS
|
36
|
+
break
|
37
|
+
else
|
38
|
+
new_line.write <<-EOS
|
39
|
+
let(:#{class_name}) { FactoryBot.create(:#{class_name}, #{@relation_params.join(", ")}) }
|
40
|
+
|
41
|
+
let(:query) do
|
42
|
+
data_id = Base64.encode64("#{class_name.camelize}:\#{#{class_name.singularize.underscore}.id}")
|
43
|
+
%(query {
|
44
|
+
#{class_name.singularize.camelize(:lower)}(id: \\"\#{data_id}\\") {
|
45
|
+
id
|
46
|
+
EOS
|
47
|
+
break
|
48
|
+
end
|
49
|
+
end
|
50
|
+
_, name = line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
|
51
|
+
case name
|
52
|
+
when /$*_id\z/
|
53
|
+
relation_col = name.gsub("_id", "")
|
54
|
+
@relation_params << "#{name}: #{relation_col}.id"
|
55
|
+
new_line.write " let(:#{relation_col}) { FactoryBot.create(:#{relation_col}) }\n"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
if table_check(line: line, class_name: class_name)
|
59
|
+
@on = true
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def rspec_query_params class_name: "souls"
|
67
|
+
file_path = "./spec/queries/#{class_name.singularize}_spec.rb"
|
68
|
+
path = "./db/schema.rb"
|
69
|
+
@on = false
|
70
|
+
File.open(file_path, "a") do |new_line|
|
71
|
+
File.open(path, "r") do |f|
|
72
|
+
f.each_line.with_index do |line, i|
|
73
|
+
if @on
|
74
|
+
if line.include?("end") || line.include?("t.index")
|
75
|
+
new_line.write <<-EOS
|
76
|
+
}
|
77
|
+
}
|
78
|
+
)
|
79
|
+
end
|
80
|
+
|
81
|
+
subject(:result) do
|
82
|
+
SoulsApiSchema.execute(query).as_json
|
83
|
+
end
|
84
|
+
|
85
|
+
it "return #{class_name.camelize} Data" do
|
86
|
+
begin
|
87
|
+
a1 = result.dig("data", "#{class_name.singularize.camelize(:lower)}")
|
88
|
+
raise unless a1.present?
|
89
|
+
rescue
|
90
|
+
raise StandardError, result
|
91
|
+
end
|
92
|
+
expect(a1).to include(
|
93
|
+
"id" => be_a(String),
|
94
|
+
EOS
|
95
|
+
break
|
96
|
+
end
|
97
|
+
_, name = line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
|
98
|
+
case name
|
99
|
+
when "user_id", "created_at", "updated_at", /$*_id\z/
|
100
|
+
next
|
101
|
+
else
|
102
|
+
new_line.write " #{name.camelize(:lower)}\n"
|
103
|
+
end
|
104
|
+
end
|
105
|
+
if table_check(line: line, class_name: class_name)
|
106
|
+
@on = true
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
def rspec_query_end class_name: "souls"
|
114
|
+
file_path = "./spec/queries/#{class_name.singularize}_spec.rb"
|
115
|
+
path = "./db/schema.rb"
|
116
|
+
@on = false
|
117
|
+
File.open(file_path, "a") do |new_line|
|
118
|
+
File.open(path, "r") do |f|
|
119
|
+
f.each_line.with_index do |line, i|
|
120
|
+
if @on
|
121
|
+
if line.include?("end") || line.include?("t.index")
|
122
|
+
new_line.write <<~EOS
|
123
|
+
)
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
EOS
|
128
|
+
break
|
129
|
+
end
|
130
|
+
type, name = line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
|
131
|
+
field ||= type_check type
|
132
|
+
array_true = line.include?("array: true")
|
133
|
+
case name
|
134
|
+
when "user_id", "created_at", "updated_at", /$*_id\z/
|
135
|
+
next
|
136
|
+
else
|
137
|
+
case type
|
138
|
+
when "text", "date", "datetime"
|
139
|
+
if array_true
|
140
|
+
new_line.write " \"#{name.camelize(:lower)}\" => be_all(String),\n"
|
141
|
+
else
|
142
|
+
new_line.write " \"#{name.camelize(:lower)}\" => be_a(String),\n"
|
143
|
+
end
|
144
|
+
when "boolean"
|
145
|
+
new_line.write " \"#{name.singularize.camelize(:lower)}\" => be_in([true, false]),\n"
|
146
|
+
when "string", "bigint", "integer", "float"
|
147
|
+
new_line.write " \"#{name.singularize.camelize(:lower)}\" => be_a(#{field}),\n"
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
151
|
+
if table_check(line: line, class_name: class_name)
|
152
|
+
@on = true
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
157
|
+
file_path
|
158
|
+
end
|
159
|
+
|
160
|
+
def rspec_query class_name: "souls"
|
161
|
+
singularized_class_name = class_name.singularize
|
162
|
+
rspec_query_head class_name: singularized_class_name
|
163
|
+
rspec_query_after_head class_name: singularized_class_name
|
164
|
+
rspec_query_params class_name: singularized_class_name
|
165
|
+
rspec_query_end class_name: singularized_class_name
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
@@ -0,0 +1,189 @@
|
|
1
|
+
module Souls
|
2
|
+
module Generate
|
3
|
+
class << self
|
4
|
+
## Generate Rspec Resolver
|
5
|
+
def rspec_resolver_head class_name: "souls"
|
6
|
+
file_path = "./spec/resolvers/#{class_name.singularize}_search_spec.rb"
|
7
|
+
File.open(file_path, "w") do |f|
|
8
|
+
f.write <<~EOS
|
9
|
+
RSpec.describe \"#{class_name.camelize}Search Resolver テスト\" do
|
10
|
+
describe "削除フラグ false の #{class_name.camelize} を返却する" do
|
11
|
+
EOS
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def rspec_resolver_after_head class_name: "souls"
|
16
|
+
file_path = "./spec/resolvers/#{class_name.singularize}_search_spec.rb"
|
17
|
+
path = "./db/schema.rb"
|
18
|
+
@on = false
|
19
|
+
@user_exist = false
|
20
|
+
@relation_params = []
|
21
|
+
File.open(file_path, "a") do |new_line|
|
22
|
+
File.open(path, "r") do |f|
|
23
|
+
f.each_line.with_index do |line, i|
|
24
|
+
if @on
|
25
|
+
if line.include?("end") || line.include?("t.index")
|
26
|
+
if @relation_params.empty?
|
27
|
+
new_line.write <<-EOS
|
28
|
+
let!(:#{class_name}) { FactoryBot.create(:#{class_name}) }
|
29
|
+
|
30
|
+
let(:query) do
|
31
|
+
%(query {
|
32
|
+
#{class_name.singularize.camelize(:lower)}Search(filter: {
|
33
|
+
isDeleted: false
|
34
|
+
}) {
|
35
|
+
edges {
|
36
|
+
cursor
|
37
|
+
node {
|
38
|
+
id
|
39
|
+
EOS
|
40
|
+
else
|
41
|
+
new_line.write <<-EOS
|
42
|
+
let!(:#{class_name}) { FactoryBot.create(:#{class_name}, #{@relation_params.join(", ")}) }
|
43
|
+
|
44
|
+
let(:query) do
|
45
|
+
%(query {
|
46
|
+
#{class_name.singularize.camelize(:lower)}Search(filter: {
|
47
|
+
isDeleted: false
|
48
|
+
}) {
|
49
|
+
edges {
|
50
|
+
cursor
|
51
|
+
node {
|
52
|
+
id
|
53
|
+
EOS
|
54
|
+
end
|
55
|
+
break
|
56
|
+
end
|
57
|
+
_, name = line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
|
58
|
+
case name
|
59
|
+
when /$*_id\z/
|
60
|
+
relation_col = name.gsub("_id", "")
|
61
|
+
@relation_params << "#{name}: #{relation_col}.id"
|
62
|
+
new_line.write " let(:#{relation_col}) { FactoryBot.create(:#{relation_col}) }\n"
|
63
|
+
end
|
64
|
+
end
|
65
|
+
if table_check(line: line, class_name: class_name)
|
66
|
+
@on = true
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def rspec_resolver_params class_name: "souls"
|
74
|
+
file_path = "./spec/resolvers/#{class_name.singularize}_search_spec.rb"
|
75
|
+
path = "./db/schema.rb"
|
76
|
+
@on = false
|
77
|
+
File.open(file_path, "a") do |new_line|
|
78
|
+
File.open(path, "r") do |f|
|
79
|
+
f.each_line.with_index do |line, i|
|
80
|
+
if @on
|
81
|
+
if line.include?("end") || line.include?("t.index")
|
82
|
+
new_line.write <<-EOS
|
83
|
+
}
|
84
|
+
}
|
85
|
+
nodes {
|
86
|
+
id
|
87
|
+
}
|
88
|
+
pageInfo {
|
89
|
+
endCursor
|
90
|
+
hasNextPage
|
91
|
+
startCursor
|
92
|
+
hasPreviousPage
|
93
|
+
}
|
94
|
+
}
|
95
|
+
}
|
96
|
+
)
|
97
|
+
end
|
98
|
+
|
99
|
+
subject(:result) do
|
100
|
+
SoulsApiSchema.execute(query).as_json
|
101
|
+
end
|
102
|
+
|
103
|
+
it "return #{class_name.camelize} Data" do
|
104
|
+
begin
|
105
|
+
a1 = result.dig("data", "#{class_name.singularize.camelize(:lower)}Search", "edges")[0]["node"]
|
106
|
+
raise unless a1.present?
|
107
|
+
rescue
|
108
|
+
raise StandardError, result
|
109
|
+
end
|
110
|
+
expect(a1).to include(
|
111
|
+
"id" => be_a(String),
|
112
|
+
EOS
|
113
|
+
break
|
114
|
+
end
|
115
|
+
_, name = line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
|
116
|
+
case name
|
117
|
+
when "user_id", "created_at", "updated_at", /$*_id\z/
|
118
|
+
next
|
119
|
+
else
|
120
|
+
new_line.write " #{name.camelize(:lower)}\n"
|
121
|
+
end
|
122
|
+
end
|
123
|
+
if table_check(line: line, class_name: class_name)
|
124
|
+
@on = true
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
def rspec_resolver_end class_name: "souls"
|
132
|
+
file_path = "./spec/resolvers/#{class_name.singularize}_search_spec.rb"
|
133
|
+
path = "./db/schema.rb"
|
134
|
+
@on = false
|
135
|
+
File.open(file_path, "a") do |new_line|
|
136
|
+
File.open(path, "r") do |f|
|
137
|
+
f.each_line.with_index do |line, i|
|
138
|
+
if @on
|
139
|
+
if line.include?("end") || line.include?("t.index")
|
140
|
+
new_line.write <<~EOS
|
141
|
+
)
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
EOS
|
146
|
+
break
|
147
|
+
end
|
148
|
+
type, name = line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
|
149
|
+
field ||= type_check type
|
150
|
+
array_true = line.include?("array: true")
|
151
|
+
case name
|
152
|
+
when "user_id", "created_at", "updated_at", /$*_id\z/
|
153
|
+
next
|
154
|
+
else
|
155
|
+
case type
|
156
|
+
when "text", "date", "datetime"
|
157
|
+
if array_true
|
158
|
+
new_line.write " \"#{name.camelize(:lower)}\" => be_all(String),\n"
|
159
|
+
else
|
160
|
+
new_line.write " \"#{name.camelize(:lower)}\" => be_a(String),\n"
|
161
|
+
end
|
162
|
+
when "boolean"
|
163
|
+
new_line.write " \"#{name.singularize.camelize(:lower)}\" => be_in([true, false]),\n"
|
164
|
+
when "string", "bigint", "integer", "float"
|
165
|
+
new_line.write " \"#{name.singularize.camelize(:lower)}\" => be_a(#{field}),\n"
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
169
|
+
if table_check(line: line, class_name: class_name)
|
170
|
+
@on = true
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|
175
|
+
file_path
|
176
|
+
end
|
177
|
+
|
178
|
+
def rspec_resolver class_name: "souls"
|
179
|
+
singularized_class_name = class_name.singularize
|
180
|
+
file_path = "#{Dir.pwd}/spec/resolvers/#{singularized_class_name}_search_spec.rb"
|
181
|
+
return "Resolver already exist! #{file_path}" if File.exist? file_path
|
182
|
+
rspec_resolver_head class_name: singularized_class_name
|
183
|
+
rspec_resolver_after_head class_name: singularized_class_name
|
184
|
+
rspec_resolver_params class_name: singularized_class_name
|
185
|
+
rspec_resolver_end class_name: singularized_class_name
|
186
|
+
end
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
module Souls
|
2
|
+
module Generate
|
3
|
+
class << self
|
4
|
+
## Generate 2 Types
|
5
|
+
## 1. Type
|
6
|
+
## 2. Node Type
|
7
|
+
def create_type_head class_name: "souls"
|
8
|
+
file_path = "./app/graphql/types/#{class_name}_type.rb"
|
9
|
+
File.open(file_path, "w") do |f|
|
10
|
+
f.write <<~EOS
|
11
|
+
module Types
|
12
|
+
class #{class_name.camelize}Type < GraphQL::Schema::Object
|
13
|
+
implements GraphQL::Types::Relay::Node
|
14
|
+
|
15
|
+
EOS
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def create_type_params class_name: "souls"
|
20
|
+
file_path = "./app/graphql/types/#{class_name}_type.rb"
|
21
|
+
path = "./db/schema.rb"
|
22
|
+
@on = false
|
23
|
+
File.open(file_path, "a") do |new_line|
|
24
|
+
File.open(path, "r") do |f|
|
25
|
+
f.each_line.with_index do |line, i|
|
26
|
+
if @on
|
27
|
+
new_line.write "\n" && break if line.include?("end") || line.include?("t.index")
|
28
|
+
field = "[String]" if line.include?("array: true")
|
29
|
+
type, name = line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
|
30
|
+
field ||= type_check type
|
31
|
+
case name
|
32
|
+
when /$*_id\z/
|
33
|
+
new_line.write " field :#{name.gsub("_id", "")}, Types::#{name.gsub("_id", "").singularize.camelize}Type, null: false\n"
|
34
|
+
else
|
35
|
+
new_line.write " field :#{name}, #{field}, null: true\n"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
if table_check(line: line, class_name: class_name)
|
39
|
+
@on = true
|
40
|
+
new_line.write " global_id_field :id\n"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def create_type_end class_name: "souls"
|
48
|
+
file_path = "./app/graphql/types/#{class_name}_type.rb"
|
49
|
+
File.open(file_path, "a") do |f|
|
50
|
+
f.write <<~EOS
|
51
|
+
end
|
52
|
+
end
|
53
|
+
EOS
|
54
|
+
end
|
55
|
+
file_path
|
56
|
+
end
|
57
|
+
|
58
|
+
def node_type class_name: "souls"
|
59
|
+
file_path = "./app/graphql/types/#{class_name.singularize}_node_type.rb"
|
60
|
+
File.open(file_path, "w") do |f|
|
61
|
+
f.write <<~EOS
|
62
|
+
module Types
|
63
|
+
class #{class_name.camelize}NodeType < GraphQL::Schema::Object
|
64
|
+
field :node, Types::#{class_name.camelize}Type, null: true
|
65
|
+
end
|
66
|
+
end
|
67
|
+
EOS
|
68
|
+
end
|
69
|
+
file_path
|
70
|
+
end
|
71
|
+
|
72
|
+
def type class_name: "souls"
|
73
|
+
singularized_class_name = class_name.singularize
|
74
|
+
create_type_head class_name: singularized_class_name
|
75
|
+
create_type_params class_name: singularized_class_name
|
76
|
+
[
|
77
|
+
create_type_end(class_name: singularized_class_name),
|
78
|
+
node_type(class_name: singularized_class_name)
|
79
|
+
]
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|