souls 0.44.6 → 0.45.3
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 +4 -4
- data/README.md +5 -2
- data/exe/souls +9 -1
- data/lib/souls/api/generate/application.rb +145 -143
- data/lib/souls/api/generate/connection.rb +1 -1
- data/lib/souls/api/generate/edge.rb +1 -1
- data/lib/souls/api/generate/model.rb +1 -1
- data/lib/souls/api/generate/mutation.rb +221 -219
- data/lib/souls/api/generate/policy.rb +1 -1
- data/lib/souls/api/generate/query.rb +49 -47
- data/lib/souls/api/generate/resolver.rb +123 -121
- data/lib/souls/api/generate/rspec_factory.rb +49 -47
- data/lib/souls/api/generate/rspec_model.rb +1 -1
- data/lib/souls/api/generate/rspec_mutation.rb +215 -213
- data/lib/souls/api/generate/rspec_policy.rb +1 -1
- data/lib/souls/api/generate/rspec_query.rb +134 -132
- data/lib/souls/api/generate/rspec_resolver.rb +159 -157
- data/lib/souls/api/generate/type.rb +4 -4
- data/lib/souls/cli/create/index.rb +1 -1
- data/lib/souls/version.rb +1 -1
- data/lib/souls/versions/.souls_api_version +1 -1
- data/lib/souls/versions/.souls_worker_version +1 -1
- data/lib/souls/worker/generate/mailer.rb +1 -0
- data/lib/souls/worker/generate/mutation.rb +11 -2
- metadata +1 -1
@@ -1,7 +1,7 @@
|
|
1
1
|
module Souls
|
2
2
|
module Api::Generate
|
3
3
|
## Generate Rspec Policy
|
4
|
-
def self.rspec_policy(class_name: "
|
4
|
+
def self.rspec_policy(class_name: "user")
|
5
5
|
dir_name = "./spec/policies"
|
6
6
|
FileUtils.mkdir_p(dir_name) unless Dir.exist?(dir_name)
|
7
7
|
file_path = "./spec/policies/#{class_name}_policy_spec.rb"
|
@@ -1,169 +1,171 @@
|
|
1
1
|
module Souls
|
2
2
|
module Api::Generate
|
3
3
|
## Generate Rspec Query
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
describe "#{class_name.camelize}
|
12
|
-
|
4
|
+
class << self
|
5
|
+
def rspec_query_head(class_name: "user")
|
6
|
+
file_dir = "./spec/queries/"
|
7
|
+
FileUtils.mkdir_p(file_dir) unless Dir.exist?(file_dir)
|
8
|
+
file_path = "./spec/queries/#{class_name.singularize}_spec.rb"
|
9
|
+
File.open(file_path, "w") do |f|
|
10
|
+
f.write(<<~TEXT)
|
11
|
+
RSpec.describe \"#{class_name.camelize} Query テスト\" do
|
12
|
+
describe "#{class_name.camelize} データを取得する" do
|
13
|
+
TEXT
|
14
|
+
end
|
13
15
|
end
|
14
|
-
end
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
17
|
+
def rspec_query_after_head(class_name: "user")
|
18
|
+
file_path = "./spec/queries/#{class_name.singularize}_spec.rb"
|
19
|
+
path = "./db/schema.rb"
|
20
|
+
@on = false
|
21
|
+
@user_exist = false
|
22
|
+
@relation_params = []
|
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
|
+
if line.include?("t.index") || line.strip == "end"
|
28
|
+
if @relation_params.empty?
|
29
|
+
new_line.write(<<-TEXT)
|
30
|
+
let!(:#{class_name}) { FactoryBot.create(:#{class_name}) }
|
30
31
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
32
|
+
let(:query) do
|
33
|
+
data_id = Base64.encode64("#{class_name.camelize}:\#{#{class_name.singularize.underscore}.id}")
|
34
|
+
%(query {
|
35
|
+
#{class_name.singularize.camelize(:lower)}(id: \\"\#{data_id}\\") {
|
36
|
+
id
|
37
|
+
TEXT
|
38
|
+
else
|
39
|
+
new_line.write(<<-TEXT)
|
40
|
+
let(:#{class_name}) { FactoryBot.create(:#{class_name}, #{@relation_params.join(', ')}) }
|
40
41
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
42
|
+
let(:query) do
|
43
|
+
data_id = Base64.encode64("#{class_name.camelize}:\#{#{class_name.singularize.underscore}.id}")
|
44
|
+
%(query {
|
45
|
+
#{class_name.singularize.camelize(:lower)}(id: \\"\#{data_id}\\") {
|
46
|
+
id
|
47
|
+
TEXT
|
48
|
+
end
|
49
|
+
break
|
50
|
+
end
|
51
|
+
_, name = line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
|
52
|
+
case name
|
53
|
+
when /$*_id\z/
|
54
|
+
relation_col = name.gsub("_id", "")
|
55
|
+
@relation_params << "#{name}: #{relation_col}.id"
|
56
|
+
new_line.write(" let(:#{relation_col}) { FactoryBot.create(:#{relation_col}) }\n")
|
47
57
|
end
|
48
|
-
break
|
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
58
|
end
|
59
|
+
@on = true if table_check(line: line, class_name: class_name)
|
57
60
|
end
|
58
|
-
@on = true if table_check(line: line, class_name: class_name)
|
59
61
|
end
|
60
62
|
end
|
61
63
|
end
|
62
|
-
end
|
63
64
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
65
|
+
def rspec_query_params(class_name: "user")
|
66
|
+
file_path = "./spec/queries/#{class_name.singularize}_spec.rb"
|
67
|
+
path = "./db/schema.rb"
|
68
|
+
@on = false
|
69
|
+
File.open(file_path, "a") do |new_line|
|
70
|
+
File.open(path, "r") do |f|
|
71
|
+
f.each_line.with_index do |line, _i|
|
72
|
+
if @on
|
73
|
+
if line.include?("t.index") || line.strip == "end"
|
74
|
+
new_line.write(<<-TEXT)
|
75
|
+
}
|
74
76
|
}
|
75
|
-
|
76
|
-
|
77
|
-
end
|
78
|
-
|
79
|
-
subject(:result) do
|
80
|
-
SoulsApiSchema.execute(query).as_json
|
81
|
-
end
|
77
|
+
)
|
78
|
+
end
|
82
79
|
|
83
|
-
|
84
|
-
|
85
|
-
a1 = result.dig("data", "#{class_name.singularize.camelize(:lower)}")
|
86
|
-
raise unless a1.present?
|
87
|
-
rescue
|
88
|
-
raise StandardError, result
|
80
|
+
subject(:result) do
|
81
|
+
SoulsApiSchema.execute(query).as_json
|
89
82
|
end
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
83
|
+
|
84
|
+
it "return #{class_name.camelize} Data" do
|
85
|
+
begin
|
86
|
+
a1 = result.dig("data", "#{class_name.singularize.camelize(:lower)}")
|
87
|
+
raise unless a1.present?
|
88
|
+
rescue
|
89
|
+
raise StandardError, result
|
90
|
+
end
|
91
|
+
expect(a1).to include(
|
92
|
+
"id" => be_a(String),
|
93
|
+
TEXT
|
94
|
+
break
|
95
|
+
end
|
96
|
+
_, name = line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
|
97
|
+
case name
|
98
|
+
when "user_id", "created_at", "updated_at", /$*_id\z/
|
99
|
+
next
|
100
|
+
else
|
101
|
+
new_line.write(" #{name.camelize(:lower)}\n")
|
102
|
+
end
|
101
103
|
end
|
104
|
+
@on = true if table_check(line: line, class_name: class_name)
|
102
105
|
end
|
103
|
-
@on = true if table_check(line: line, class_name: class_name)
|
104
106
|
end
|
105
107
|
end
|
106
108
|
end
|
107
|
-
end
|
108
109
|
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
110
|
+
def rspec_query_end(class_name: "user")
|
111
|
+
file_path = "./spec/queries/#{class_name.singularize}_spec.rb"
|
112
|
+
path = "./db/schema.rb"
|
113
|
+
@on = false
|
114
|
+
File.open(file_path, "a") do |new_line|
|
115
|
+
File.open(path, "r") do |f|
|
116
|
+
f.each_line.with_index do |line, _i|
|
117
|
+
if @on
|
118
|
+
if line.include?("t.index") || line.strip == "end"
|
119
|
+
new_line.write(<<~TEXT)
|
120
|
+
)
|
121
|
+
end
|
120
122
|
end
|
121
123
|
end
|
124
|
+
TEXT
|
125
|
+
break
|
126
|
+
end
|
127
|
+
type, name = line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
|
128
|
+
field ||= type_check(type)
|
129
|
+
array_true = line.include?("array: true")
|
130
|
+
case name
|
131
|
+
when "user_id", "created_at", "updated_at", /$*_id\z/
|
132
|
+
next
|
133
|
+
else
|
134
|
+
case type
|
135
|
+
when "text", "date", "datetime"
|
136
|
+
if array_true
|
137
|
+
new_line.write(" \"#{name.camelize(:lower)}\" => be_all(String),\n")
|
138
|
+
else
|
139
|
+
new_line.write(" \"#{name.camelize(:lower)}\" => be_a(String),\n")
|
140
|
+
end
|
141
|
+
when "boolean"
|
142
|
+
new_line.write(" \"#{name.singularize.camelize(:lower)}\" => be_in([true, false]),\n")
|
143
|
+
when "string", "bigint", "integer", "float"
|
144
|
+
new_line.write(" \"#{name.singularize.camelize(:lower)}\" => be_a(#{field}),\n")
|
122
145
|
end
|
123
|
-
TEXT
|
124
|
-
break
|
125
|
-
end
|
126
|
-
type, name = line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
|
127
|
-
field ||= type_check(type)
|
128
|
-
array_true = line.include?("array: true")
|
129
|
-
case name
|
130
|
-
when "user_id", "created_at", "updated_at", /$*_id\z/
|
131
|
-
next
|
132
|
-
else
|
133
|
-
case type
|
134
|
-
when "text", "date", "datetime"
|
135
|
-
if array_true
|
136
|
-
new_line.write(" \"#{name.camelize(:lower)}\" => be_all(String),\n")
|
137
|
-
else
|
138
|
-
new_line.write(" \"#{name.camelize(:lower)}\" => be_a(String),\n")
|
139
|
-
end
|
140
|
-
when "boolean"
|
141
|
-
new_line.write(" \"#{name.singularize.camelize(:lower)}\" => be_in([true, false]),\n")
|
142
|
-
when "string", "bigint", "integer", "float"
|
143
|
-
new_line.write(" \"#{name.singularize.camelize(:lower)}\" => be_a(#{field}),\n")
|
144
146
|
end
|
145
147
|
end
|
148
|
+
@on = true if table_check(line: line, class_name: class_name)
|
146
149
|
end
|
147
|
-
@on = true if table_check(line: line, class_name: class_name)
|
148
150
|
end
|
149
151
|
end
|
152
|
+
file_path
|
150
153
|
end
|
151
|
-
file_path
|
152
|
-
end
|
153
154
|
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
155
|
+
def rspec_query(class_name: "user")
|
156
|
+
singularized_class_name = class_name.singularize
|
157
|
+
file_path = "./spec/queries/#{singularized_class_name}_spec.rb"
|
158
|
+
return "RspecQuery already exist! #{file_path}" if File.exist?(file_path)
|
158
159
|
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
160
|
+
rspec_query_head(class_name: singularized_class_name)
|
161
|
+
rspec_query_after_head(class_name: singularized_class_name)
|
162
|
+
rspec_query_params(class_name: singularized_class_name)
|
163
|
+
rspec_query_end(class_name: singularized_class_name)
|
164
|
+
puts(Paint % ["Created file! : %{white_text}", :green, { white_text: [file_path.to_s, :white] }])
|
165
|
+
file_path
|
166
|
+
rescue StandardError => e
|
167
|
+
raise(StandardError, e)
|
168
|
+
end
|
167
169
|
end
|
168
170
|
end
|
169
171
|
end
|
@@ -1,196 +1,198 @@
|
|
1
1
|
module Souls
|
2
2
|
module Api::Generate
|
3
3
|
## Generate Rspec Resolver
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
describe "
|
12
|
-
|
4
|
+
class << self
|
5
|
+
def rspec_resolver_head(class_name: "user")
|
6
|
+
file_dir = "./spec/resolvers/"
|
7
|
+
FileUtils.mkdir_p(file_dir) unless Dir.exist?(file_dir)
|
8
|
+
file_path = "./spec/resolvers/#{class_name.singularize}_search_spec.rb"
|
9
|
+
File.open(file_path, "w") do |f|
|
10
|
+
f.write(<<~TEXT)
|
11
|
+
RSpec.describe \"#{class_name.camelize}Search Resolver テスト\" do
|
12
|
+
describe "削除フラグ false の #{class_name.camelize} を返却する" do
|
13
|
+
TEXT
|
14
|
+
end
|
13
15
|
end
|
14
|
-
end
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
17
|
+
def rspec_resolver_after_head(class_name: "user")
|
18
|
+
file_path = "./spec/resolvers/#{class_name.singularize}_search_spec.rb"
|
19
|
+
path = "./db/schema.rb"
|
20
|
+
@on = false
|
21
|
+
@user_exist = false
|
22
|
+
@relation_params = []
|
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
|
+
if line.include?("t.index") || line.strip == "end"
|
28
|
+
if @relation_params.empty?
|
29
|
+
new_line.write(<<-TEXT)
|
30
|
+
let!(:#{class_name}) { FactoryBot.create(:#{class_name}) }
|
30
31
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
32
|
+
let(:query) do
|
33
|
+
%(query {
|
34
|
+
#{class_name.singularize.camelize(:lower)}Search(filter: {
|
35
|
+
isDeleted: false
|
36
|
+
}) {
|
37
|
+
edges {
|
38
|
+
cursor
|
39
|
+
node {
|
40
|
+
id
|
41
|
+
TEXT
|
42
|
+
else
|
43
|
+
new_line.write(<<-TEXT)
|
44
|
+
let!(:#{class_name}) { FactoryBot.create(:#{class_name}, #{@relation_params.join(', ')}) }
|
44
45
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
46
|
+
let(:query) do
|
47
|
+
%(query {
|
48
|
+
#{class_name.singularize.camelize(:lower)}Search(filter: {
|
49
|
+
isDeleted: false
|
50
|
+
}) {
|
51
|
+
edges {
|
52
|
+
cursor
|
53
|
+
node {
|
54
|
+
id
|
55
|
+
TEXT
|
56
|
+
end
|
57
|
+
break
|
58
|
+
end
|
59
|
+
_, name = line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
|
60
|
+
case name
|
61
|
+
when /$*_id\z/
|
62
|
+
relation_col = name.gsub("_id", "")
|
63
|
+
@relation_params << "#{name}: #{relation_col}.id"
|
64
|
+
new_line.write(" let(:#{relation_col}) { FactoryBot.create(:#{relation_col}) }\n")
|
55
65
|
end
|
56
|
-
break
|
57
|
-
end
|
58
|
-
_, name = line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
|
59
|
-
case name
|
60
|
-
when /$*_id\z/
|
61
|
-
relation_col = name.gsub("_id", "")
|
62
|
-
@relation_params << "#{name}: #{relation_col}.id"
|
63
|
-
new_line.write(" let(:#{relation_col}) { FactoryBot.create(:#{relation_col}) }\n")
|
64
66
|
end
|
67
|
+
@on = true if table_check(line: line, class_name: class_name)
|
65
68
|
end
|
66
|
-
@on = true if table_check(line: line, class_name: class_name)
|
67
69
|
end
|
68
70
|
end
|
69
71
|
end
|
70
|
-
end
|
71
72
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
73
|
+
def rspec_resolver_params(class_name: "user")
|
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?("t.index") || line.strip == "end"
|
82
|
+
new_line.write(<<-TEXT)
|
83
|
+
}
|
84
|
+
}
|
85
|
+
nodes {
|
86
|
+
id
|
87
|
+
}
|
88
|
+
pageInfo {
|
89
|
+
endCursor
|
90
|
+
hasNextPage
|
91
|
+
startCursor
|
92
|
+
hasPreviousPage
|
82
93
|
}
|
83
|
-
}
|
84
|
-
nodes {
|
85
|
-
id
|
86
|
-
}
|
87
|
-
pageInfo {
|
88
|
-
endCursor
|
89
|
-
hasNextPage
|
90
|
-
startCursor
|
91
|
-
hasPreviousPage
|
92
94
|
}
|
93
95
|
}
|
94
|
-
|
95
|
-
|
96
|
-
end
|
97
|
-
|
98
|
-
subject(:result) do
|
99
|
-
SoulsApiSchema.execute(query).as_json
|
100
|
-
end
|
96
|
+
)
|
97
|
+
end
|
101
98
|
|
102
|
-
|
103
|
-
|
104
|
-
a1 = result.dig("data", "#{class_name.singularize.camelize(:lower)}Search", "edges")[0]["node"]
|
105
|
-
raise unless a1.present?
|
106
|
-
rescue
|
107
|
-
raise StandardError, result
|
99
|
+
subject(:result) do
|
100
|
+
SoulsApiSchema.execute(query).as_json
|
108
101
|
end
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
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
|
+
TEXT
|
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
|
120
122
|
end
|
123
|
+
@on = true if table_check(line: line, class_name: class_name)
|
121
124
|
end
|
122
|
-
@on = true if table_check(line: line, class_name: class_name)
|
123
125
|
end
|
124
126
|
end
|
125
127
|
end
|
126
|
-
end
|
127
128
|
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
129
|
+
def rspec_resolver_end(class_name: "user")
|
130
|
+
file_path = "./spec/resolvers/#{class_name.singularize}_search_spec.rb"
|
131
|
+
path = "./db/schema.rb"
|
132
|
+
@on = false
|
133
|
+
File.open(file_path, "a") do |new_line|
|
134
|
+
File.open(path, "r") do |f|
|
135
|
+
f.each_line.with_index do |line, _i|
|
136
|
+
if @on
|
137
|
+
if line.include?("t.index") || line.strip == "end"
|
138
|
+
new_line.write(<<~TEXT)
|
139
|
+
)
|
140
|
+
end
|
139
141
|
end
|
140
142
|
end
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
143
|
+
TEXT
|
144
|
+
break
|
145
|
+
end
|
146
|
+
type, name = line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
|
147
|
+
field ||= type_check(type)
|
148
|
+
array_true = line.include?("array: true")
|
149
|
+
case name
|
150
|
+
when "user_id", "created_at", "updated_at", /$*_id\z/
|
151
|
+
next
|
152
|
+
else
|
153
|
+
case type
|
154
|
+
when "text", "date", "datetime"
|
155
|
+
if array_true
|
156
|
+
new_line.write(" \"#{name.camelize(:lower)}\" => be_all(String),\n")
|
157
|
+
else
|
158
|
+
new_line.write(" \"#{name.camelize(:lower)}\" => be_a(String),\n")
|
159
|
+
end
|
160
|
+
when "boolean"
|
161
|
+
if array_true
|
162
|
+
new_line.write(" \"#{name.camelize(:lower)}\" => be_all([true, false]),\n")
|
163
|
+
else
|
164
|
+
new_line.write(" \"#{name.singularize.camelize(:lower)}\" => be_in([true, false]),\n")
|
165
|
+
end
|
166
|
+
when "string", "bigint", "integer", "float"
|
167
|
+
if array_true
|
168
|
+
new_line.write(" \"#{name.camelize(:lower)}\" => be_all(#{field}),\n")
|
169
|
+
else
|
170
|
+
new_line.write(" \"#{name.singularize.camelize(:lower)}\" => be_a(#{field}),\n")
|
171
|
+
end
|
170
172
|
end
|
171
173
|
end
|
172
174
|
end
|
175
|
+
@on = true if table_check(line: line, class_name: class_name)
|
173
176
|
end
|
174
|
-
@on = true if table_check(line: line, class_name: class_name)
|
175
177
|
end
|
176
178
|
end
|
179
|
+
file_path
|
177
180
|
end
|
178
|
-
file_path
|
179
|
-
end
|
180
181
|
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
182
|
+
def rspec_resolver(class_name: "user")
|
183
|
+
singularized_class_name = class_name.singularize
|
184
|
+
file_path = "./spec/resolvers/#{singularized_class_name}_search_spec.rb"
|
185
|
+
return "Resolver already exist! #{file_path}" if File.exist?(file_path)
|
185
186
|
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
187
|
+
rspec_resolver_head(class_name: singularized_class_name)
|
188
|
+
rspec_resolver_after_head(class_name: singularized_class_name)
|
189
|
+
rspec_resolver_params(class_name: singularized_class_name)
|
190
|
+
rspec_resolver_end(class_name: singularized_class_name)
|
191
|
+
puts(Paint % ["Created file! : %{white_text}", :green, { white_text: [file_path.to_s, :white] }])
|
192
|
+
file_path
|
193
|
+
rescue StandardError => e
|
194
|
+
raise(StandardError, e)
|
195
|
+
end
|
194
196
|
end
|
195
197
|
end
|
196
198
|
end
|