synvert-core 0.16.0 → 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.
- checksums.yaml +4 -4
- data/.travis.yml +6 -1
- data/CHANGELOG.md +16 -0
- data/lib/synvert/core.rb +1 -4
- data/lib/synvert/core/configuration.rb +9 -17
- data/lib/synvert/core/engine/erb.rb +29 -22
- data/lib/synvert/core/exceptions.rb +3 -3
- data/lib/synvert/core/node_ext.rb +102 -101
- data/lib/synvert/core/rewriter.rb +33 -19
- data/lib/synvert/core/rewriter/action.rb +3 -5
- data/lib/synvert/core/rewriter/action/append_action.rb +1 -1
- data/lib/synvert/core/rewriter/action/insert_action.rb +7 -3
- data/lib/synvert/core/rewriter/action/insert_after_action.rb +1 -1
- data/lib/synvert/core/rewriter/action/remove_action.rb +1 -1
- data/lib/synvert/core/rewriter/action/replace_erb_stmt_with_expr_action.rb +4 -3
- data/lib/synvert/core/rewriter/action/replace_with_action.rb +6 -4
- data/lib/synvert/core/rewriter/condition/if_exist_condition.rb +1 -1
- data/lib/synvert/core/rewriter/condition/if_only_exist_condition.rb +1 -2
- data/lib/synvert/core/rewriter/condition/unless_exist_condition.rb +1 -1
- data/lib/synvert/core/rewriter/gem_spec.rb +10 -10
- data/lib/synvert/core/rewriter/helper.rb +3 -5
- data/lib/synvert/core/rewriter/instance.rb +22 -19
- data/lib/synvert/core/rewriter/scope/within_scope.rb +18 -11
- data/lib/synvert/core/version.rb +1 -1
- data/spec/spec_helper.rb +1 -6
- data/spec/synvert/core/engine/erb_spec.rb +30 -30
- data/spec/synvert/core/node_ext_spec.rb +53 -52
- data/spec/synvert/core/rewriter/action/insert_action_spec.rb +8 -8
- data/spec/synvert/core/rewriter/action/insert_after_action_spec.rb +3 -3
- data/spec/synvert/core/rewriter/action/remove_action_spec.rb +1 -1
- data/spec/synvert/core/rewriter/action/replace_with_action_spec.rb +15 -11
- data/spec/synvert/core/rewriter/condition/if_exist_condition_spec.rb +17 -9
- data/spec/synvert/core/rewriter/condition/if_only_exist_condition_spec.rb +21 -12
- data/spec/synvert/core/rewriter/condition/unless_exist_condition_spec.rb +17 -9
- data/spec/synvert/core/rewriter/gem_spec_spec.rb +11 -10
- data/spec/synvert/core/rewriter/helper_spec.rb +34 -31
- data/spec/synvert/core/rewriter/instance_spec.rb +104 -70
- data/spec/synvert/core/rewriter/scope/goto_scope_spec.rb +8 -6
- data/spec/synvert/core/rewriter/scope/within_scope.rb +16 -9
- data/spec/synvert/core/rewriter_spec.rb +105 -68
- metadata +2 -4
- data/spec/synvert/core/configuration_spec.rb +0 -12
@@ -8,10 +8,11 @@ module Synvert::Core
|
|
8
8
|
rewriter = Rewriter.new('foo', 'bar')
|
9
9
|
Rewriter::Instance.new(rewriter, 'file pattern')
|
10
10
|
}
|
11
|
-
let(:source) {
|
11
|
+
let(:source) {
|
12
|
+
'
|
12
13
|
Factory.define :user do |user|
|
13
14
|
end
|
14
|
-
'
|
15
|
+
'
|
15
16
|
}
|
16
17
|
let(:node) { Parser::CurrentRuby.parse(source) }
|
17
18
|
before do
|
@@ -23,10 +24,11 @@ end
|
|
23
24
|
it 'call block with child node' do
|
24
25
|
run = false
|
25
26
|
type_in_scope = nil
|
26
|
-
scope =
|
27
|
-
|
28
|
-
|
29
|
-
|
27
|
+
scope =
|
28
|
+
Rewriter::GotoScope.new instance, :caller do
|
29
|
+
run = true
|
30
|
+
type_in_scope = node.type
|
31
|
+
end
|
30
32
|
scope.process
|
31
33
|
expect(run).to be_truthy
|
32
34
|
expect(type_in_scope).to eq :send
|
@@ -8,13 +8,14 @@ module Synvert::Core
|
|
8
8
|
rewriter = Rewriter.new('foo', 'bar')
|
9
9
|
Rewriter::Instance.new(rewriter, 'file pattern')
|
10
10
|
}
|
11
|
-
let(:source) {
|
11
|
+
let(:source) {
|
12
|
+
"
|
12
13
|
describe Post do
|
13
14
|
it 'gets post' do
|
14
15
|
FactoryGirl.create :post
|
15
16
|
end
|
16
17
|
end
|
17
|
-
"
|
18
|
+
"
|
18
19
|
}
|
19
20
|
let(:node) { Parser::CurrentRuby.parse(source) }
|
20
21
|
before do
|
@@ -25,9 +26,10 @@ end
|
|
25
26
|
describe '#process' do
|
26
27
|
it 'not call block if no matching node' do
|
27
28
|
run = false
|
28
|
-
scope =
|
29
|
-
|
30
|
-
|
29
|
+
scope =
|
30
|
+
Rewriter::WithinScope.new instance, type: 'send', message: 'missing' do
|
31
|
+
run = true
|
32
|
+
end
|
31
33
|
scope.process
|
32
34
|
expect(run).to be_falsey
|
33
35
|
end
|
@@ -35,10 +37,15 @@ end
|
|
35
37
|
it 'call block if there is matching node' do
|
36
38
|
run = false
|
37
39
|
type_in_scope = nil
|
38
|
-
scope =
|
39
|
-
|
40
|
-
|
41
|
-
|
40
|
+
scope =
|
41
|
+
Rewriter::WithinScope.new instance,
|
42
|
+
type: 'send',
|
43
|
+
receiver: 'FactoryGirl',
|
44
|
+
message: 'create',
|
45
|
+
arguments: [':post'] do
|
46
|
+
run = true
|
47
|
+
type_in_scope = node.type
|
48
|
+
end
|
42
49
|
scope.process
|
43
50
|
expect(run).to be_truthy
|
44
51
|
expect(type_in_scope).to eq :send
|
@@ -4,27 +4,36 @@ require 'spec_helper'
|
|
4
4
|
|
5
5
|
module Synvert::Core
|
6
6
|
describe Rewriter do
|
7
|
+
it '.execute' do
|
8
|
+
run = false
|
9
|
+
Rewriter.execute { run = true }
|
10
|
+
expect(run).to be_truthy
|
11
|
+
end
|
12
|
+
|
7
13
|
it 'parses description' do
|
8
|
-
rewriter =
|
9
|
-
|
10
|
-
|
14
|
+
rewriter =
|
15
|
+
Rewriter.new 'group', 'name' do
|
16
|
+
description 'rewriter description'
|
17
|
+
end
|
11
18
|
rewriter.process
|
12
19
|
expect(rewriter.description).to eq 'rewriter description'
|
13
20
|
end
|
14
21
|
|
15
22
|
it 'parses if_ruby' do
|
16
|
-
|
17
|
-
rewriter =
|
18
|
-
|
19
|
-
|
23
|
+
expect(Rewriter::RubyVersion).to receive(:new).with('2.0.0')
|
24
|
+
rewriter =
|
25
|
+
Rewriter.new 'group', 'name' do
|
26
|
+
if_ruby '2.0.0'
|
27
|
+
end
|
20
28
|
rewriter.process
|
21
29
|
end
|
22
30
|
|
23
31
|
it 'parses if_gem' do
|
24
|
-
expect(Rewriter::GemSpec).to receive(:new).with('synvert', {gte: '1.0.0'})
|
25
|
-
rewriter =
|
26
|
-
|
27
|
-
|
32
|
+
expect(Rewriter::GemSpec).to receive(:new).with('synvert', { gte: '1.0.0' })
|
33
|
+
rewriter =
|
34
|
+
Rewriter.new 'group', 'name' do
|
35
|
+
if_gem 'synvert', { gte: '1.0.0' }
|
36
|
+
end
|
28
37
|
rewriter.process
|
29
38
|
end
|
30
39
|
|
@@ -32,76 +41,90 @@ module Synvert::Core
|
|
32
41
|
it 'does nothing if if_ruby does not match' do
|
33
42
|
stub_const('RUBY_VERSION', '2.0.0')
|
34
43
|
expect_any_instance_of(Rewriter::Instance).not_to receive(:process)
|
35
|
-
rewriter =
|
36
|
-
|
37
|
-
|
38
|
-
|
44
|
+
rewriter =
|
45
|
+
Rewriter.new 'group', 'name' do
|
46
|
+
if_ruby '2.2.3'
|
47
|
+
within_file 'config/routes.rb' do
|
48
|
+
end
|
49
|
+
end
|
39
50
|
rewriter.process
|
40
51
|
end
|
41
52
|
|
42
53
|
it 'delegates process to instances if if_ruby matches' do
|
43
54
|
stub_const('RUBY_VERSION', '2.0.0')
|
44
55
|
expect_any_instance_of(Rewriter::Instance).to receive(:process)
|
45
|
-
rewriter =
|
46
|
-
|
47
|
-
|
48
|
-
|
56
|
+
rewriter =
|
57
|
+
Rewriter.new 'group', 'name' do
|
58
|
+
if_ruby '1.9.3'
|
59
|
+
within_file 'config/routes.rb' do
|
60
|
+
end
|
61
|
+
end
|
49
62
|
rewriter.process
|
50
63
|
end
|
51
64
|
|
52
65
|
it 'does nothing if if_gem does not match' do
|
53
66
|
expect_any_instance_of(Rewriter::GemSpec).to receive(:match?).and_return(false)
|
54
67
|
expect_any_instance_of(Rewriter::Instance).not_to receive(:process)
|
55
|
-
rewriter =
|
56
|
-
|
57
|
-
|
58
|
-
|
68
|
+
rewriter =
|
69
|
+
Rewriter.new 'group', 'name' do
|
70
|
+
if_gem 'synvert', '1.0.0'
|
71
|
+
within_file 'config/routes.rb' do
|
72
|
+
end
|
73
|
+
end
|
59
74
|
rewriter.process
|
60
75
|
end
|
61
76
|
|
62
77
|
it 'delegates process to instances if if_gem matches' do
|
63
78
|
expect_any_instance_of(Rewriter::GemSpec).to receive(:match?).and_return(true)
|
64
79
|
expect_any_instance_of(Rewriter::Instance).to receive(:process)
|
65
|
-
rewriter =
|
66
|
-
|
67
|
-
|
68
|
-
|
80
|
+
rewriter =
|
81
|
+
Rewriter.new 'group', 'name' do
|
82
|
+
if_gem 'synvert', '1.0.0'
|
83
|
+
within_file 'config/routes.rb' do
|
84
|
+
end
|
85
|
+
end
|
69
86
|
rewriter.process
|
70
87
|
end
|
71
88
|
|
72
89
|
it 'delegates process to instances if if_ruby and if_gem do not exist' do
|
73
90
|
expect_any_instance_of(Rewriter::Instance).to receive(:process)
|
74
|
-
rewriter =
|
75
|
-
|
76
|
-
|
91
|
+
rewriter =
|
92
|
+
Rewriter.new 'group', 'name' do
|
93
|
+
within_file 'config/routes.rb' do
|
94
|
+
end
|
95
|
+
end
|
77
96
|
rewriter.process
|
78
97
|
end
|
79
98
|
|
80
99
|
it 'does nothing in sandbox mode' do
|
81
100
|
expect_any_instance_of(Rewriter::GemSpec).not_to receive(:match?)
|
82
101
|
expect_any_instance_of(Rewriter::Instance).not_to receive(:process)
|
83
|
-
rewriter =
|
84
|
-
|
85
|
-
|
86
|
-
|
102
|
+
rewriter =
|
103
|
+
Rewriter.new 'group', 'name' do
|
104
|
+
if_gem 'synvert', '1.0.0'
|
105
|
+
within_file 'config/routes.rb' do
|
106
|
+
end
|
107
|
+
end
|
87
108
|
rewriter.process_with_sandbox
|
88
109
|
end
|
89
110
|
end
|
90
111
|
|
91
112
|
describe 'parses add_file' do
|
92
113
|
it 'creates a new file' do
|
93
|
-
rewriter =
|
94
|
-
|
95
|
-
|
114
|
+
rewriter =
|
115
|
+
Rewriter.new 'group', 'rewriter2' do
|
116
|
+
add_file 'foo.bar', 'FooBar'
|
117
|
+
end
|
96
118
|
rewriter.process
|
97
119
|
expect(File.read('./foo.bar')).to eq 'FooBar'
|
98
120
|
FileUtils.rm './foo.bar'
|
99
121
|
end
|
100
122
|
|
101
123
|
it 'does nothing in sandbox mode' do
|
102
|
-
rewriter =
|
103
|
-
|
104
|
-
|
124
|
+
rewriter =
|
125
|
+
Rewriter.new 'group', 'rewriter2' do
|
126
|
+
add_file 'foo.bar', 'FooBar'
|
127
|
+
end
|
105
128
|
rewriter.process_with_sandbox
|
106
129
|
expect(File.exist?('./foo.bar')).to be_falsey
|
107
130
|
end
|
@@ -110,26 +133,29 @@ module Synvert::Core
|
|
110
133
|
describe 'parses remove_file' do
|
111
134
|
it 'removes a file' do
|
112
135
|
FileUtils.touch './foo.bar'
|
113
|
-
rewriter =
|
114
|
-
|
115
|
-
|
136
|
+
rewriter =
|
137
|
+
Rewriter.new 'group', 'rewriter2' do
|
138
|
+
remove_file 'foo.bar'
|
139
|
+
end
|
116
140
|
rewriter.process
|
117
141
|
expect(File.exist?('./foo.bar')).to be_falsey
|
118
142
|
end
|
119
143
|
|
120
144
|
it 'does nothing if file not exist' do
|
121
|
-
rewriter =
|
122
|
-
|
123
|
-
|
145
|
+
rewriter =
|
146
|
+
Rewriter.new 'group', 'rewriter2' do
|
147
|
+
remove_file 'foo.bar'
|
148
|
+
end
|
124
149
|
rewriter.process
|
125
150
|
expect(File.exist?('./foo.bar')).to be_falsey
|
126
151
|
end
|
127
152
|
|
128
153
|
it 'does nothing in sandbox mode' do
|
129
154
|
FileUtils.touch './foo.bar'
|
130
|
-
rewriter =
|
131
|
-
|
132
|
-
|
155
|
+
rewriter =
|
156
|
+
Rewriter.new 'group', 'rewriter2' do
|
157
|
+
add_file 'foo.bar', 'FooBar'
|
158
|
+
end
|
133
159
|
rewriter.process_with_sandbox
|
134
160
|
expect(File.exist?('./foo.bar')).to be_truthy
|
135
161
|
FileUtils.rm './foo.bar'
|
@@ -139,46 +165,51 @@ module Synvert::Core
|
|
139
165
|
describe 'parses add_snippet' do
|
140
166
|
it 'processes the rewritter' do
|
141
167
|
rewriter1 = Rewriter.new 'group', 'rewriter1'
|
142
|
-
rewriter2 =
|
143
|
-
|
144
|
-
|
168
|
+
rewriter2 =
|
169
|
+
Rewriter.new 'group', 'rewriter2' do
|
170
|
+
add_snippet :group, :rewriter1
|
171
|
+
end
|
145
172
|
expect(rewriter1).to receive(:process)
|
146
173
|
rewriter2.process
|
147
174
|
end
|
148
175
|
|
149
176
|
it 'adds sub_snippets' do
|
150
177
|
rewriter1 = Rewriter.new 'group', 'rewriter1'
|
151
|
-
rewriter2 =
|
152
|
-
|
153
|
-
|
178
|
+
rewriter2 =
|
179
|
+
Rewriter.new 'group', 'rewriter2' do
|
180
|
+
add_snippet :group, :rewriter1
|
181
|
+
end
|
154
182
|
expect(rewriter1).to receive(:process)
|
155
183
|
rewriter2.process
|
156
184
|
expect(rewriter2.sub_snippets).to eq [rewriter1]
|
157
185
|
end
|
158
186
|
|
159
187
|
it 'raises RewriterNotFound' do
|
160
|
-
rewriter =
|
161
|
-
|
162
|
-
|
188
|
+
rewriter =
|
189
|
+
Rewriter.new 'group', 'name' do
|
190
|
+
add_snippet :group, :not_exist
|
191
|
+
end
|
163
192
|
expect { rewriter.process }.to raise_error(RewriterNotFound)
|
164
193
|
end
|
165
194
|
end
|
166
195
|
|
167
196
|
it 'parses helper_method' do
|
168
|
-
rewriter =
|
169
|
-
|
170
|
-
'
|
197
|
+
rewriter =
|
198
|
+
Rewriter.new 'group', 'name' do
|
199
|
+
helper_method 'dynamic_helper' do |_arg1, _arg2|
|
200
|
+
'dynamic result'
|
201
|
+
end
|
171
202
|
end
|
172
|
-
end
|
173
203
|
rewriter.process
|
174
204
|
instance = Rewriter::Instance.new(rewriter, '*.rb')
|
175
205
|
expect(instance.dynamic_helper('arg1', 'arg2')).to eq 'dynamic result'
|
176
206
|
end
|
177
207
|
|
178
208
|
it 'parses todo' do
|
179
|
-
rewriter =
|
180
|
-
|
181
|
-
|
209
|
+
rewriter =
|
210
|
+
Rewriter.new 'group', 'name' do
|
211
|
+
todo "this rewriter doesn't do blah blah blah"
|
212
|
+
end
|
182
213
|
rewriter.process
|
183
214
|
expect(rewriter.todo).to eq "this rewriter doesn't do blah blah blah"
|
184
215
|
end
|
@@ -199,11 +230,17 @@ module Synvert::Core
|
|
199
230
|
Rewriter.call 'group', 'rewriter'
|
200
231
|
end
|
201
232
|
|
233
|
+
it 'registers and calls rewriter in sandbox mode' do
|
234
|
+
rewriter = Rewriter.new 'group', 'rewriter'
|
235
|
+
expect(rewriter).to receive(:process_with_sandbox)
|
236
|
+
Rewriter.call 'group', 'rewriter', true
|
237
|
+
end
|
238
|
+
|
202
239
|
it 'raises RewriterNotFound if rewriter not found' do
|
203
240
|
expect { Rewriter.call 'group', 'rewriter' }.to raise_error(RewriterNotFound)
|
204
241
|
end
|
205
242
|
|
206
|
-
context
|
243
|
+
context 'exist?' do
|
207
244
|
it 'returns true if rewriter exists' do
|
208
245
|
Rewriter.new 'group', 'rewriter'
|
209
246
|
expect(Rewriter.exist?('group', 'rewriter')).to be_truthy
|
@@ -214,7 +251,7 @@ module Synvert::Core
|
|
214
251
|
end
|
215
252
|
end
|
216
253
|
|
217
|
-
context
|
254
|
+
context 'available' do
|
218
255
|
it 'lists empty rewriters' do
|
219
256
|
expect(Rewriter.availables).to eq({})
|
220
257
|
end
|
@@ -222,7 +259,7 @@ module Synvert::Core
|
|
222
259
|
it 'registers and lists all available rewriters' do
|
223
260
|
rewriter1 = Rewriter.new 'group', 'rewriter1'
|
224
261
|
rewriter2 = Rewriter.new 'group', 'rewriter2'
|
225
|
-
expect(Rewriter.availables).to eq({'group' => {'rewriter1' => rewriter1, 'rewriter2' => rewriter2}})
|
262
|
+
expect(Rewriter.availables).to eq({ 'group' => { 'rewriter1' => rewriter1, 'rewriter2' => rewriter2 } })
|
226
263
|
end
|
227
264
|
end
|
228
265
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: synvert-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.20.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Richard Huang
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-02-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: parser
|
@@ -167,7 +167,6 @@ files:
|
|
167
167
|
- lib/synvert/core/version.rb
|
168
168
|
- spec/spec_helper.rb
|
169
169
|
- spec/support/parser_helper.rb
|
170
|
-
- spec/synvert/core/configuration_spec.rb
|
171
170
|
- spec/synvert/core/engine/erb_spec.rb
|
172
171
|
- spec/synvert/core/node_ext_spec.rb
|
173
172
|
- spec/synvert/core/rewriter/action/append_action_spec.rb
|
@@ -216,7 +215,6 @@ summary: convert ruby code to better syntax.
|
|
216
215
|
test_files:
|
217
216
|
- spec/spec_helper.rb
|
218
217
|
- spec/support/parser_helper.rb
|
219
|
-
- spec/synvert/core/configuration_spec.rb
|
220
218
|
- spec/synvert/core/engine/erb_spec.rb
|
221
219
|
- spec/synvert/core/node_ext_spec.rb
|
222
220
|
- spec/synvert/core/rewriter/action/append_action_spec.rb
|