synvert-core 1.21.6 → 1.21.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 +4 -4
- data/.github/workflows/main.yml +6 -5
- data/CHANGELOG.md +5 -0
- data/Gemfile +0 -1
- data/Gemfile.lock +8 -9
- data/lib/synvert/core/engine/erb.rb +6 -8
- data/lib/synvert/core/rewriter/instance.rb +4 -4
- data/lib/synvert/core/rewriter.rb +14 -5
- data/lib/synvert/core/snippet_not_found_error.rb +1 -1
- data/lib/synvert/core/strategy.rb +1 -1
- data/lib/synvert/core/utils.rb +8 -4
- data/lib/synvert/core/version.rb +1 -1
- data/lib/synvert/core.rb +0 -1
- data/spec/synvert/core/engine/erb_spec.rb +8 -5
- data/spec/synvert/core/rewriter/instance_spec.rb +64 -15
- data/spec/synvert/core/rewriter_spec.rb +21 -17
- data/spec/synvert/core/utils_spec.rb +19 -4
- data/synvert-core-ruby.gemspec +1 -2
- metadata +5 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0d33e2874a1d23b725a4d2bb62e8cfd03d71b9c82e22fbe9a349336ac19f6eab
|
4
|
+
data.tar.gz: 74a56b255b08c5f017fe0717dbd644cfc61983a06c6c7c0b0ec86f77d6566ff1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a98c6ded4885bebda395ad253cb826ce1e82ad06d734cc0bfbd00b592676c6dde8aac530d30d2d27beb3b7ca314519a782de91fa0e97905ea4c1fd62122eef98
|
7
|
+
data.tar.gz: ec1d2ac24a8f9066bb228363b961cc1e93da96f501cbfb166fb398cb21a3bd80d5ee496b261e0901289b6fed3d9749fdf04cd5b2db458853caf742ceca5c5691
|
data/.github/workflows/main.yml
CHANGED
@@ -11,10 +11,10 @@ jobs:
|
|
11
11
|
runs-on: ubuntu-latest
|
12
12
|
strategy:
|
13
13
|
matrix:
|
14
|
-
ruby-version: ['2.
|
14
|
+
ruby-version: ['2.7', '3.0', '3.1', '3.2']
|
15
15
|
|
16
16
|
steps:
|
17
|
-
- uses: actions/checkout@
|
17
|
+
- uses: actions/checkout@v3
|
18
18
|
- name: Set up Ruby
|
19
19
|
uses: ruby/setup-ruby@v1
|
20
20
|
with:
|
@@ -28,10 +28,11 @@ jobs:
|
|
28
28
|
needs: test
|
29
29
|
name: Update gh-pages to docs
|
30
30
|
steps:
|
31
|
-
- uses: actions/checkout@
|
32
|
-
- uses:
|
31
|
+
- uses: actions/checkout@v3
|
32
|
+
- uses: ruby/setup-ruby@v1
|
33
33
|
with:
|
34
|
-
ruby-version: '3.
|
34
|
+
ruby-version: '3.2'
|
35
|
+
bundler-cache: true
|
35
36
|
- name: Install required gem dependencies
|
36
37
|
run: gem install yard redcarpet github-markup --no-document
|
37
38
|
- name: Build YARD Ruby Documentation
|
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,10 +1,9 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
synvert-core (1.21.
|
4
|
+
synvert-core (1.21.7)
|
5
5
|
activesupport (< 7.0.0)
|
6
|
-
|
7
|
-
node_mutation (>= 1.9.2)
|
6
|
+
node_mutation (>= 1.12.1)
|
8
7
|
node_query (>= 1.12.0)
|
9
8
|
parallel
|
10
9
|
parser
|
@@ -13,7 +12,7 @@ PATH
|
|
13
12
|
GEM
|
14
13
|
remote: https://rubygems.org/
|
15
14
|
specs:
|
16
|
-
activesupport (6.1.7.
|
15
|
+
activesupport (6.1.7.3)
|
17
16
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
18
17
|
i18n (>= 1.6, < 2)
|
19
18
|
minitest (>= 5.1)
|
@@ -21,10 +20,10 @@ GEM
|
|
21
20
|
zeitwerk (~> 2.3)
|
22
21
|
ast (2.4.2)
|
23
22
|
coderay (1.1.3)
|
24
|
-
concurrent-ruby (1.2.
|
23
|
+
concurrent-ruby (1.2.2)
|
25
24
|
diff-lcs (1.5.0)
|
26
25
|
erubis (2.7.0)
|
27
|
-
fakefs (
|
26
|
+
fakefs (2.4.0)
|
28
27
|
ffi (1.15.5)
|
29
28
|
formatador (1.1.0)
|
30
29
|
guard (2.18.0)
|
@@ -48,16 +47,16 @@ GEM
|
|
48
47
|
rb-inotify (~> 0.9, >= 0.9.10)
|
49
48
|
lumberjack (1.2.8)
|
50
49
|
method_source (1.0.0)
|
51
|
-
minitest (5.
|
50
|
+
minitest (5.18.0)
|
52
51
|
nenv (0.3.0)
|
53
|
-
node_mutation (1.
|
52
|
+
node_mutation (1.12.1)
|
54
53
|
erubis
|
55
54
|
node_query (1.12.0)
|
56
55
|
notiffany (0.1.3)
|
57
56
|
nenv (~> 0.1)
|
58
57
|
shellany (~> 0.0)
|
59
58
|
parallel (1.22.1)
|
60
|
-
parser (3.2.1.
|
59
|
+
parser (3.2.1.1)
|
61
60
|
ast (~> 2.4.1)
|
62
61
|
parser_node_ext (1.0.0)
|
63
62
|
parser
|
@@ -1,19 +1,17 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'erubis'
|
4
|
-
|
5
3
|
module Synvert::Core
|
6
4
|
module Engine
|
7
5
|
class Erb
|
8
6
|
class << self
|
9
|
-
#
|
7
|
+
# Encode erb string, leave only ruby code, replace other erb code with whitespace.
|
10
8
|
#
|
11
|
-
# @param source [String] erb
|
12
|
-
# @return [String] ruby
|
9
|
+
# @param source [String] erb code.
|
10
|
+
# @return [String] encoded ruby code.
|
13
11
|
def encode(source)
|
14
|
-
source.gsub(
|
15
|
-
.
|
16
|
-
.
|
12
|
+
source.gsub(/%>.*?<%=?/m) { |str| ' ' * str.size }
|
13
|
+
.sub(/^.*?<%=?/m) { |str| ' ' * str.size }
|
14
|
+
.sub(/%>.*?$/m) { |str| ' ' * str.size }
|
17
15
|
end
|
18
16
|
end
|
19
17
|
end
|
@@ -20,7 +20,7 @@ module Synvert::Core
|
|
20
20
|
@block = block
|
21
21
|
strategy = NodeMutation::Strategy::KEEP_RUNNING
|
22
22
|
if rewriter.options[:strategy] == Strategy::ALLOW_INSERT_AT_SAME_POSITION
|
23
|
-
strategy |=
|
23
|
+
strategy |= NodeMutation::Strategy::ALLOW_INSERT_AT_SAME_POSITION
|
24
24
|
end
|
25
25
|
NodeMutation.configure({ strategy: strategy, tab_width: Configuration.tab_width })
|
26
26
|
rewriter.helpers.each { |helper| singleton_class.send(:define_method, helper[:name], &helper[:block]) }
|
@@ -90,7 +90,6 @@ module Synvert::Core
|
|
90
90
|
end
|
91
91
|
end
|
92
92
|
|
93
|
-
|
94
93
|
# Gets current node, it allows to get current node in block code.
|
95
94
|
#
|
96
95
|
# @return [Parser::AST::Node]
|
@@ -404,7 +403,8 @@ module Synvert::Core
|
|
404
403
|
if str.include?(quote) && !str.include?(another_quote)
|
405
404
|
return "#{another_quote}#{str}#{another_quote}"
|
406
405
|
end
|
407
|
-
|
406
|
+
|
407
|
+
escaped_str = str.gsub(quote) { |_char| '\\' + quote }
|
408
408
|
quote + escaped_str + quote
|
409
409
|
end
|
410
410
|
|
@@ -413,7 +413,7 @@ module Synvert::Core
|
|
413
413
|
# @param tab_size [Integer] tab size
|
414
414
|
# @return [String]
|
415
415
|
def add_leading_spaces(str, tab_size: 1)
|
416
|
-
" " * Configuration.tab_width * tab_size + str;
|
416
|
+
(" " * Configuration.tab_width * tab_size) + str;
|
417
417
|
end
|
418
418
|
|
419
419
|
private
|
@@ -94,7 +94,15 @@ module Synvert::Core
|
|
94
94
|
# @return [Array<Object>] the test results
|
95
95
|
# @!attribute [rw] options
|
96
96
|
# @return [Hash] the rewriter options
|
97
|
-
attr_reader :group,
|
97
|
+
attr_reader :group,
|
98
|
+
:name,
|
99
|
+
:sub_snippets,
|
100
|
+
:helpers,
|
101
|
+
:warnings,
|
102
|
+
:affected_files,
|
103
|
+
:ruby_version,
|
104
|
+
:gem_spec,
|
105
|
+
:test_results
|
98
106
|
attr_accessor :options
|
99
107
|
|
100
108
|
# Initialize a Rewriter.
|
@@ -230,10 +238,11 @@ module Synvert::Core
|
|
230
238
|
instance.process
|
231
239
|
end
|
232
240
|
else
|
233
|
-
results =
|
234
|
-
|
235
|
-
|
236
|
-
|
241
|
+
results =
|
242
|
+
handle_one_file(Array(file_patterns)) do |file_path|
|
243
|
+
instance = Rewriter::Instance.new(self, file_path, &block)
|
244
|
+
instance.test
|
245
|
+
end
|
237
246
|
merge_test_results(results)
|
238
247
|
end
|
239
248
|
end
|
data/lib/synvert/core/utils.rb
CHANGED
@@ -15,14 +15,17 @@ module Synvert::Core
|
|
15
15
|
if is_valid_url?(snippet_name)
|
16
16
|
uri = URI.parse(format_url(snippet_name))
|
17
17
|
return uri.open.read if remote_snippet_exists?(uri)
|
18
|
+
|
18
19
|
raise SnippetNotFoundError.new("#{snippet_name} nout found")
|
19
20
|
elsif is_valid_file?(snippet_name)
|
20
21
|
return File.read(snippet_name)
|
21
22
|
else
|
22
23
|
snippet_path = snippet_expand_path(snippet_name)
|
23
24
|
return File.read(snippet_path) if File.exist?(snippet_path)
|
25
|
+
|
24
26
|
snippet_uri = URI.parse(format_url(remote_snippet_url(snippet_name)))
|
25
27
|
return snippet_uri.open.read if remote_snippet_exists?(snippet_uri)
|
28
|
+
|
26
29
|
raise SnippetNotFoundError.new("#{snippet_name} nout found")
|
27
30
|
end
|
28
31
|
end
|
@@ -32,9 +35,10 @@ module Synvert::Core
|
|
32
35
|
# @return [Array<String>] file paths
|
33
36
|
def glob(file_patterns)
|
34
37
|
Dir.chdir(Configuration.root_path) do
|
35
|
-
all_files =
|
36
|
-
|
37
|
-
|
38
|
+
all_files =
|
39
|
+
file_patterns.flat_map do |file_pattern|
|
40
|
+
Dir.glob(file_pattern)
|
41
|
+
end
|
38
42
|
filter_only_paths(all_files) - get_skip_files
|
39
43
|
end
|
40
44
|
end
|
@@ -105,4 +109,4 @@ module Synvert::Core
|
|
105
109
|
end
|
106
110
|
end
|
107
111
|
end
|
108
|
-
end
|
112
|
+
end
|
data/lib/synvert/core/version.rb
CHANGED
data/lib/synvert/core.rb
CHANGED
@@ -34,11 +34,14 @@ module Synvert::Core
|
|
34
34
|
<% end %>
|
35
35
|
<% end %>
|
36
36
|
EOF
|
37
|
-
|
38
|
-
expect(
|
39
|
-
expect(
|
40
|
-
expect(
|
41
|
-
expect(
|
37
|
+
encoded_source = Engine::Erb.encode(source)
|
38
|
+
expect(encoded_source).to be_include 'content_for :head do'
|
39
|
+
expect(encoded_source).to be_include " asset_path('bg.png')"
|
40
|
+
expect(encoded_source).to be_include 'post = Post.find(:first)'
|
41
|
+
expect(encoded_source).to be_include "link_to_function 'test', \"confirm('test');\""
|
42
|
+
expect(encoded_source).to be_include 'end'
|
43
|
+
expect(encoded_source).not_to be_include 'style'
|
44
|
+
expect(encoded_source).not_to be_include 'div'
|
42
45
|
end
|
43
46
|
end
|
44
47
|
end
|
@@ -12,7 +12,12 @@ module Synvert::Core
|
|
12
12
|
it 'parses find_node' do
|
13
13
|
scope = double
|
14
14
|
block = proc {}
|
15
|
-
expect(Rewriter::WithinScope).to receive(:new).with(
|
15
|
+
expect(Rewriter::WithinScope).to receive(:new).with(
|
16
|
+
instance,
|
17
|
+
'.send[message=create]',
|
18
|
+
{},
|
19
|
+
&block
|
20
|
+
).and_return(scope)
|
16
21
|
expect(scope).to receive(:process)
|
17
22
|
instance.find_node('.send[message=create]', &block)
|
18
23
|
end
|
@@ -99,28 +104,44 @@ module Synvert::Core
|
|
99
104
|
it 'parses append' do
|
100
105
|
instance.instance_variable_set(:@current_mutation, double)
|
101
106
|
instance.current_node = double
|
102
|
-
expect(instance.instance_variable_get(:@current_mutation)).to receive(:append).with(
|
107
|
+
expect(instance.instance_variable_get(:@current_mutation)).to receive(:append).with(
|
108
|
+
instance.current_node,
|
109
|
+
'Foobar'
|
110
|
+
)
|
103
111
|
instance.append 'Foobar'
|
104
112
|
end
|
105
113
|
|
106
114
|
it 'parses prepend' do
|
107
115
|
instance.instance_variable_set(:@current_mutation, double)
|
108
116
|
instance.current_node = double
|
109
|
-
expect(instance.instance_variable_get(:@current_mutation)).to receive(:prepend).with(
|
117
|
+
expect(instance.instance_variable_get(:@current_mutation)).to receive(:prepend).with(
|
118
|
+
instance.current_node,
|
119
|
+
'Foobar'
|
120
|
+
)
|
110
121
|
instance.prepend 'Foobar'
|
111
122
|
end
|
112
123
|
|
113
124
|
it 'parses insert at end' do
|
114
125
|
instance.instance_variable_set(:@current_mutation, double)
|
115
126
|
instance.current_node = double
|
116
|
-
expect(instance.instance_variable_get(:@current_mutation)).to receive(:insert).with(
|
127
|
+
expect(instance.instance_variable_get(:@current_mutation)).to receive(:insert).with(
|
128
|
+
instance.current_node,
|
129
|
+
'Foobar',
|
130
|
+
at: 'end',
|
131
|
+
to: 'receiver'
|
132
|
+
)
|
117
133
|
instance.insert 'Foobar', to: 'receiver'
|
118
134
|
end
|
119
135
|
|
120
136
|
it 'parses insert at beginning' do
|
121
137
|
instance.instance_variable_set(:@current_mutation, double)
|
122
138
|
instance.current_node = double
|
123
|
-
expect(instance.instance_variable_get(:@current_mutation)).to receive(:insert).with(
|
139
|
+
expect(instance.instance_variable_get(:@current_mutation)).to receive(:insert).with(
|
140
|
+
instance.current_node,
|
141
|
+
'Foobar',
|
142
|
+
at: 'beginning',
|
143
|
+
to: nil
|
144
|
+
)
|
124
145
|
instance.insert 'Foobar', at: 'beginning'
|
125
146
|
end
|
126
147
|
|
@@ -128,7 +149,12 @@ module Synvert::Core
|
|
128
149
|
instance.instance_variable_set(:@current_mutation, double)
|
129
150
|
instance.current_node = double
|
130
151
|
expect(NodeMutation).to receive_message_chain(:adapter, :get_start_loc, :column).and_return(2)
|
131
|
-
expect(instance.instance_variable_get(:@current_mutation)).to receive(:insert).with(
|
152
|
+
expect(instance.instance_variable_get(:@current_mutation)).to receive(:insert).with(
|
153
|
+
instance.current_node,
|
154
|
+
"\n Foobar",
|
155
|
+
at: 'end',
|
156
|
+
to: nil
|
157
|
+
)
|
132
158
|
instance.insert_after 'Foobar'
|
133
159
|
end
|
134
160
|
|
@@ -136,7 +162,12 @@ module Synvert::Core
|
|
136
162
|
instance.instance_variable_set(:@current_mutation, double)
|
137
163
|
instance.current_node = double
|
138
164
|
expect(NodeMutation).to receive_message_chain(:adapter, :get_start_loc, :column).and_return(2)
|
139
|
-
expect(instance.instance_variable_get(:@current_mutation)).to receive(:insert).with(
|
165
|
+
expect(instance.instance_variable_get(:@current_mutation)).to receive(:insert).with(
|
166
|
+
instance.current_node,
|
167
|
+
"Foobar\n ",
|
168
|
+
at: 'beginning',
|
169
|
+
to: nil
|
170
|
+
)
|
140
171
|
instance.insert_before 'Foobar'
|
141
172
|
end
|
142
173
|
|
@@ -153,35 +184,53 @@ module Synvert::Core
|
|
153
184
|
it 'parses replace_with' do
|
154
185
|
instance.instance_variable_set(:@current_mutation, double)
|
155
186
|
instance.current_node = double
|
156
|
-
expect(instance.instance_variable_get(:@current_mutation)).to receive(:replace_with).with(
|
187
|
+
expect(instance.instance_variable_get(:@current_mutation)).to receive(:replace_with).with(
|
188
|
+
instance.current_node,
|
189
|
+
'Foobar'
|
190
|
+
)
|
157
191
|
instance.replace_with 'Foobar'
|
158
192
|
end
|
159
193
|
|
160
194
|
it 'parses replace with' do
|
161
195
|
instance.instance_variable_set(:@current_mutation, double)
|
162
196
|
instance.current_node = double
|
163
|
-
expect(instance.instance_variable_get(:@current_mutation)).to receive(:replace).with(
|
197
|
+
expect(instance.instance_variable_get(:@current_mutation)).to receive(:replace).with(
|
198
|
+
instance.current_node,
|
199
|
+
:message,
|
200
|
+
with: 'Foobar'
|
201
|
+
)
|
164
202
|
instance.replace :message, with: 'Foobar'
|
165
203
|
end
|
166
204
|
|
167
205
|
it 'parses remove' do
|
168
206
|
instance.instance_variable_set(:@current_mutation, double)
|
169
207
|
instance.current_node = double
|
170
|
-
expect(instance.instance_variable_get(:@current_mutation)).to receive(:remove).with(
|
208
|
+
expect(instance.instance_variable_get(:@current_mutation)).to receive(:remove).with(
|
209
|
+
instance.current_node,
|
210
|
+
and_comma: true
|
211
|
+
)
|
171
212
|
instance.remove and_comma: true
|
172
213
|
end
|
173
214
|
|
174
215
|
it 'parses delete' do
|
175
216
|
instance.instance_variable_set(:@current_mutation, double)
|
176
217
|
instance.current_node = double
|
177
|
-
expect(instance.instance_variable_get(:@current_mutation)).to receive(:delete).with(
|
218
|
+
expect(instance.instance_variable_get(:@current_mutation)).to receive(:delete).with(
|
219
|
+
instance.current_node,
|
220
|
+
:dot,
|
221
|
+
:message,
|
222
|
+
and_comma: true
|
223
|
+
)
|
178
224
|
instance.delete :dot, :message, and_comma: true
|
179
225
|
end
|
180
226
|
|
181
227
|
it 'parses wrap with' do
|
182
228
|
instance.instance_variable_set(:@current_mutation, double)
|
183
229
|
instance.current_node = double
|
184
|
-
expect(instance.instance_variable_get(:@current_mutation)).to receive(:wrap).with(
|
230
|
+
expect(instance.instance_variable_get(:@current_mutation)).to receive(:wrap).with(
|
231
|
+
instance.current_node,
|
232
|
+
with: 'module Foobar'
|
233
|
+
)
|
185
234
|
instance.wrap with: 'module Foobar'
|
186
235
|
end
|
187
236
|
|
@@ -330,8 +379,8 @@ module Synvert::Core
|
|
330
379
|
results = instance.test
|
331
380
|
expect(results.file_path).to eq 'spec/models/post_spec.rb'
|
332
381
|
expect(results.actions).to eq [
|
333
|
-
|
334
|
-
|
382
|
+
NodeMutation::Struct::Action.new(35, 59, 'create :user'),
|
383
|
+
NodeMutation::Struct::Action.new(69, 105, 'create :post, user: user')
|
335
384
|
]
|
336
385
|
end
|
337
386
|
|
@@ -369,7 +418,7 @@ module Synvert::Core
|
|
369
418
|
expect(File).to receive(:read).with('./app/views/posts/_form.html.erb', encoding: 'UTF-8').and_return(input)
|
370
419
|
result = instance.test
|
371
420
|
expect(result.file_path).to eq 'app/views/posts/_form.html.erb'
|
372
|
-
expect(result.actions).to eq [
|
421
|
+
expect(result.actions).to eq [NodeMutation::Struct::Action.new(2, 2, '=')]
|
373
422
|
end
|
374
423
|
end
|
375
424
|
|
@@ -33,13 +33,14 @@ module Synvert::Core
|
|
33
33
|
|
34
34
|
describe '#process' do
|
35
35
|
it 'rewrites the file' do
|
36
|
-
rewriter =
|
37
|
-
|
38
|
-
|
39
|
-
|
36
|
+
rewriter =
|
37
|
+
Rewriter.new('group', 'name') do
|
38
|
+
within_files '**/*.rb' do
|
39
|
+
with_node node_type: 'class', name: 'Foobar' do
|
40
|
+
replace :name, with: 'Synvert'
|
41
|
+
end
|
40
42
|
end
|
41
43
|
end
|
42
|
-
end
|
43
44
|
input = "class Foobar\nend"
|
44
45
|
output = "class Synvert\nend"
|
45
46
|
FakeFS do
|
@@ -52,13 +53,14 @@ module Synvert::Core
|
|
52
53
|
|
53
54
|
describe '#test' do
|
54
55
|
it 'gets test results' do
|
55
|
-
rewriter =
|
56
|
-
|
57
|
-
|
58
|
-
|
56
|
+
rewriter =
|
57
|
+
Rewriter.new('group', 'name') do
|
58
|
+
within_files '**/*.rb' do
|
59
|
+
with_node node_type: 'class', name: 'Foobar' do
|
60
|
+
replace :name, with: 'Synvert'
|
61
|
+
end
|
59
62
|
end
|
60
63
|
end
|
61
|
-
end
|
62
64
|
input = "class Foobar\nend"
|
63
65
|
FakeFS do
|
64
66
|
File.write("code.rb", input)
|
@@ -66,7 +68,7 @@ module Synvert::Core
|
|
66
68
|
expect(results[0].file_path).to eq '/code.rb'
|
67
69
|
expect(results[0].affected?).to be_truthy
|
68
70
|
expect(results[0].conflicted?).to be_falsey
|
69
|
-
expect(results[0].actions).to eq [
|
71
|
+
expect(results[0].actions).to eq [NodeMutation::Struct::Action.new(6, 12, 'Synvert')]
|
70
72
|
end
|
71
73
|
end
|
72
74
|
end
|
@@ -226,9 +228,10 @@ module Synvert::Core
|
|
226
228
|
it 'adds snippet by http url' do
|
227
229
|
expect(Utils).to receive(:remote_snippet_exists?).with(URI.parse('http://synvert.net/foo/bar.rb')).and_return(true)
|
228
230
|
expect_any_instance_of(URI::HTTP).to receive(:open).and_return(StringIO.new("Rewriter.new 'group', 'sub_rewriter' do\nend"))
|
229
|
-
rewriter =
|
230
|
-
|
231
|
-
|
231
|
+
rewriter =
|
232
|
+
Rewriter.new 'group', 'rewriter' do
|
233
|
+
add_snippet 'http://synvert.net/foo/bar.rb'
|
234
|
+
end
|
232
235
|
rewriter.process
|
233
236
|
expect(Rewriter.fetch('group', 'sub_rewriter')).not_to be_nil
|
234
237
|
end
|
@@ -236,9 +239,10 @@ module Synvert::Core
|
|
236
239
|
it 'adds snippet by file path' do
|
237
240
|
expect(File).to receive(:exist?).and_return(true)
|
238
241
|
expect(File).to receive(:read).and_return("Rewriter.new 'group', 'sub_rewriter' do\nend")
|
239
|
-
rewriter =
|
240
|
-
|
241
|
-
|
242
|
+
rewriter =
|
243
|
+
Rewriter.new 'group', 'rewriter' do
|
244
|
+
add_snippet '/home/richard/foo/bar.rb'
|
245
|
+
end
|
242
246
|
rewriter.process
|
243
247
|
expect(Rewriter.fetch('group', 'sub_rewriter')).not_to be_nil
|
244
248
|
end
|
@@ -61,22 +61,37 @@ module Synvert::Core
|
|
61
61
|
end
|
62
62
|
|
63
63
|
it 'gets all files' do
|
64
|
-
expect(Dir).to receive(:glob).with('**/*.rb').and_return(
|
64
|
+
expect(Dir).to receive(:glob).with('**/*.rb').and_return(
|
65
|
+
[
|
66
|
+
'app/models/post.rb',
|
67
|
+
'app/controllers/posts_controller.rb'
|
68
|
+
]
|
69
|
+
)
|
65
70
|
expect(described_class.glob(['**/*.rb'])).to eq(['app/models/post.rb', 'app/controllers/posts_controller.rb'])
|
66
71
|
end
|
67
72
|
|
68
73
|
it 'filters only paths' do
|
69
74
|
Configuration.only_paths = ['app/models']
|
70
|
-
expect(Dir).to receive(:glob).with('**/*.rb').and_return(
|
75
|
+
expect(Dir).to receive(:glob).with('**/*.rb').and_return(
|
76
|
+
[
|
77
|
+
'app/models/post.rb',
|
78
|
+
'app/controllers/posts_controller.rb'
|
79
|
+
]
|
80
|
+
)
|
71
81
|
expect(described_class.glob(['**/*.rb'])).to eq(['app/models/post.rb'])
|
72
82
|
end
|
73
83
|
|
74
84
|
it 'skip files' do
|
75
85
|
Configuration.skip_paths = ['app/controllers/**/*']
|
76
|
-
expect(Dir).to receive(:glob).with('**/*.rb').and_return(
|
86
|
+
expect(Dir).to receive(:glob).with('**/*.rb').and_return(
|
87
|
+
[
|
88
|
+
'app/models/post.rb',
|
89
|
+
'app/controllers/posts_controller.rb'
|
90
|
+
]
|
91
|
+
)
|
77
92
|
expect(Dir).to receive(:glob).with('app/controllers/**/*').and_return(['app/controllers/posts_controller.rb'])
|
78
93
|
expect(described_class.glob(['**/*.rb'])).to eq(['app/models/post.rb'])
|
79
94
|
end
|
80
95
|
end
|
81
96
|
end
|
82
|
-
end
|
97
|
+
end
|
data/synvert-core-ruby.gemspec
CHANGED
@@ -20,9 +20,8 @@ Gem::Specification.new do |spec|
|
|
20
20
|
spec.require_paths = ["lib"]
|
21
21
|
|
22
22
|
spec.add_runtime_dependency "activesupport", "< 7.0.0"
|
23
|
-
spec.add_runtime_dependency "erubis"
|
24
23
|
spec.add_runtime_dependency "node_query", ">= 1.12.0"
|
25
|
-
spec.add_runtime_dependency "node_mutation", ">= 1.
|
24
|
+
spec.add_runtime_dependency "node_mutation", ">= 1.12.1"
|
26
25
|
spec.add_runtime_dependency "parser"
|
27
26
|
spec.add_runtime_dependency "parser_node_ext", ">= 1.0.0"
|
28
27
|
spec.add_runtime_dependency "parallel"
|
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: 1.21.
|
4
|
+
version: 1.21.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Richard Huang
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-03-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -24,20 +24,6 @@ dependencies:
|
|
24
24
|
- - "<"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 7.0.0
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: erubis
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ">="
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
34
|
-
type: :runtime
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - ">="
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
41
27
|
- !ruby/object:Gem::Dependency
|
42
28
|
name: node_query
|
43
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -58,14 +44,14 @@ dependencies:
|
|
58
44
|
requirements:
|
59
45
|
- - ">="
|
60
46
|
- !ruby/object:Gem::Version
|
61
|
-
version: 1.
|
47
|
+
version: 1.12.1
|
62
48
|
type: :runtime
|
63
49
|
prerelease: false
|
64
50
|
version_requirements: !ruby/object:Gem::Requirement
|
65
51
|
requirements:
|
66
52
|
- - ">="
|
67
53
|
- !ruby/object:Gem::Version
|
68
|
-
version: 1.
|
54
|
+
version: 1.12.1
|
69
55
|
- !ruby/object:Gem::Dependency
|
70
56
|
name: parser
|
71
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -188,7 +174,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
188
174
|
- !ruby/object:Gem::Version
|
189
175
|
version: '0'
|
190
176
|
requirements: []
|
191
|
-
rubygems_version: 3.4.
|
177
|
+
rubygems_version: 3.4.6
|
192
178
|
signing_key:
|
193
179
|
specification_version: 4
|
194
180
|
summary: convert ruby code to better syntax.
|