synvert-core 1.12.0 → 1.13.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/Gemfile.lock +3 -3
- data/README.md +1 -0
- data/lib/synvert/core/rewriter/instance.rb +27 -18
- data/lib/synvert/core/version.rb +1 -1
- data/spec/synvert/core/rewriter/instance_spec.rb +10 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d3d907ab2e51c1861a28d12934cf453f63df79fc23e072c1005013c5f9b137be
|
4
|
+
data.tar.gz: 16e8425a70a74b779b36265eec12aacca4b6073e5911052b0114726a740f6e99
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3a73e71ccb24cbdf40fe515fcb732e242e27e5dbac5b130bc9e88d19b8c3ef315cc7c3e00195d3d4e15f6a24bd4fb89336686ae379451e3fa7433548bd3402c8
|
7
|
+
data.tar.gz: c6e026527d96e8766a330626c330d280c6ab650834e71b56c64c4cf81a4dd7d0911d89919c16e0f651208e0d0ce1c9c3b36f6c08f4c9f5f7d04d0af4849a713d
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
synvert-core (1.
|
4
|
+
synvert-core (1.13.0)
|
5
5
|
activesupport (< 7.0.0)
|
6
6
|
erubis
|
7
7
|
node_mutation
|
@@ -50,10 +50,10 @@ GEM
|
|
50
50
|
method_source (1.0.0)
|
51
51
|
minitest (5.16.3)
|
52
52
|
nenv (0.3.0)
|
53
|
-
node_mutation (1.
|
53
|
+
node_mutation (1.5.0)
|
54
54
|
activesupport (< 7.0.0)
|
55
55
|
erubis
|
56
|
-
node_query (1.
|
56
|
+
node_query (1.8.1)
|
57
57
|
activesupport (< 7.0.0)
|
58
58
|
notiffany (0.1.3)
|
59
59
|
nenv (~> 0.1)
|
data/README.md
CHANGED
@@ -90,6 +90,7 @@ Actions:
|
|
90
90
|
* [prepend](./Synvert/Core/Rewriter/Instance.html#prepend-instance_method) - prepend the code to the bottom of current node body
|
91
91
|
* [insert](./Synvert/Core/Rewriter/Instance.html#insert-instance_method) - insert code
|
92
92
|
* [insert_after](./Synvert/Core/Rewriter/Instance.html#insert_after-instance_method) - insert the code next to the current node
|
93
|
+
* [insert_before](./Synvert/Core/Rewriter/Instance.html#insert_before-instance_method) - insert the code previous to the current node
|
93
94
|
* [replace](./Synvert/Core/Rewriter/Instance.html#replace-instance_method) - replace the code of specified child nodes
|
94
95
|
* [delete](./Synvert/Core/Rewriter/Instance.html#delete-instance_method) - delete the code specified child nodes
|
95
96
|
* [wrap](./Synvert/Core/Rewriter/Instance.html#wrap-instance_method) - wrap the current node with code
|
@@ -166,8 +166,7 @@ module Synvert::Core
|
|
166
166
|
Rewriter::IfOnlyExistCondition.new(self, nql_or_rules, &block).process
|
167
167
|
end
|
168
168
|
|
169
|
-
# Parse +append+ dsl, it
|
170
|
-
# append the code to the bottom of current node body.
|
169
|
+
# Parse +append+ dsl, it appends the code to the bottom of current node body.
|
171
170
|
# @example
|
172
171
|
# # def teardown
|
173
172
|
# # clean_something
|
@@ -185,8 +184,7 @@ module Synvert::Core
|
|
185
184
|
@current_mutation.append(@current_node, code)
|
186
185
|
end
|
187
186
|
|
188
|
-
# Parse +prepend+ dsl, it
|
189
|
-
# prepend the code to the top of current node body.
|
187
|
+
# Parse +prepend+ dsl, it prepends the code to the top of current node body.
|
190
188
|
# @example
|
191
189
|
# # def setup
|
192
190
|
# # do_something
|
@@ -204,7 +202,7 @@ module Synvert::Core
|
|
204
202
|
@current_mutation.prepend(@current_node, code)
|
205
203
|
end
|
206
204
|
|
207
|
-
# Parse +insert+ dsl, it
|
205
|
+
# Parse +insert+ dsl, it inserts code.
|
208
206
|
# @example
|
209
207
|
# # open('http://test.com')
|
210
208
|
# # =>
|
@@ -219,8 +217,7 @@ module Synvert::Core
|
|
219
217
|
@current_mutation.insert(@current_node, code, at: at, to: to)
|
220
218
|
end
|
221
219
|
|
222
|
-
# Parse +insert_after+ dsl, it
|
223
|
-
# insert the code next to the current node.
|
220
|
+
# Parse +insert_after+ dsl, it inserts the code next to the current node.
|
224
221
|
# @example
|
225
222
|
# # Synvert::Application.config.secret_token = "0447aa931d42918bfb934750bb78257088fb671186b5d1b6f9fddf126fc8a14d34f1d045cefab3900751c3da121a8dd929aec9bafe975f1cabb48232b4002e4e"
|
226
223
|
# # =>
|
@@ -231,11 +228,26 @@ module Synvert::Core
|
|
231
228
|
# end
|
232
229
|
# @param code [String] code need to be inserted.
|
233
230
|
def insert_after(code)
|
234
|
-
|
231
|
+
column = ' ' * NodeMutation.adapter.get_start_loc(@current_node).column
|
232
|
+
@current_mutation.insert(@current_node, "\n#{column}#{code}", { at: 'end' })
|
235
233
|
end
|
236
234
|
|
237
|
-
# Parse +
|
238
|
-
#
|
235
|
+
# Parse +insert_before+ dsl, it inserts the code previous to the current node.
|
236
|
+
# @example
|
237
|
+
# # Synvert::Application.config.secret_token = "0447aa931d42918bfb934750bb78257088fb671186b5d1b6f9fddf126fc8a14d34f1d045cefab3900751c3da121a8dd929aec9bafe975f1cabb48232b4002e4e"
|
238
|
+
# # =>
|
239
|
+
# # Synvert::Application.config.secret_key_base = "bf4f3f46924ecd9adcb6515681c78144545bba454420973a274d7021ff946b8ef043a95ca1a15a9d1b75f9fbdf85d1a3afaf22f4e3c2f3f78e24a0a188b581df"
|
240
|
+
# # Synvert::Application.config.secret_token = "0447aa931d42918bfb934750bb78257088fb671186b5d1b6f9fddf126fc8a14d34f1d045cefab3900751c3da121a8dd929aec9bafe975f1cabb48232b4002e4e"
|
241
|
+
# with_node type: 'send', message: 'secret_token=' do
|
242
|
+
# insert_before "{{receiver}}.secret_key_base = \"#{SecureRandom.hex(64)}\""
|
243
|
+
# end
|
244
|
+
# @param code [String] code need to be inserted.
|
245
|
+
def insert_before(code)
|
246
|
+
column = ' ' * NodeMutation.adapter.get_start_loc(@current_node).column
|
247
|
+
@current_mutation.insert(@current_node, "#{code}\n#{column}", { at: 'beginning' })
|
248
|
+
end
|
249
|
+
|
250
|
+
# Parse +replace_erb_stmt_with_expr+ dsl, it replaces erb stmt code to expr code.
|
239
251
|
# @example
|
240
252
|
# # <% form_for post do |f| %>
|
241
253
|
# # <% end %>
|
@@ -249,8 +261,7 @@ module Synvert::Core
|
|
249
261
|
@current_mutation.actions << Rewriter::ReplaceErbStmtWithExprAction.new(@current_node).process
|
250
262
|
end
|
251
263
|
|
252
|
-
# Parse +replace_with+ dsl, it
|
253
|
-
# replace the whole code of current node.
|
264
|
+
# Parse +replace_with+ dsl, it replaces the whole code of current node.
|
254
265
|
# @example
|
255
266
|
# # obj.stub(:foo => 1, :bar => 2)
|
256
267
|
# # =>
|
@@ -263,8 +274,7 @@ module Synvert::Core
|
|
263
274
|
@current_mutation.replace_with(@current_node, code)
|
264
275
|
end
|
265
276
|
|
266
|
-
# Parse +replace+ dsl, it
|
267
|
-
# replace the code of specified child nodes.
|
277
|
+
# Parse +replace+ dsl, it replaces the code of specified child nodes.
|
268
278
|
# @example
|
269
279
|
# # assert(object.empty?)
|
270
280
|
# # =>
|
@@ -279,7 +289,7 @@ module Synvert::Core
|
|
279
289
|
@current_mutation.replace(@current_node, *selectors, with: with)
|
280
290
|
end
|
281
291
|
|
282
|
-
# Parse +remove+ dsl, it
|
292
|
+
# Parse +remove+ dsl, it removes current node.
|
283
293
|
# @example
|
284
294
|
# with_node type: 'send', message: { in: %w[puts p] } do
|
285
295
|
# remove
|
@@ -290,7 +300,7 @@ module Synvert::Core
|
|
290
300
|
@current_mutation.remove(@current_node, **options)
|
291
301
|
end
|
292
302
|
|
293
|
-
# Parse +delete+ dsl, it
|
303
|
+
# Parse +delete+ dsl, it deletes child nodes.
|
294
304
|
# @example
|
295
305
|
# # FactoryBot.create(...)
|
296
306
|
# # =>
|
@@ -305,8 +315,7 @@ module Synvert::Core
|
|
305
315
|
@current_mutation.delete(@current_node, *selectors, **options)
|
306
316
|
end
|
307
317
|
|
308
|
-
# Parse +wrap+ dsl, it
|
309
|
-
# wrap current node with code.
|
318
|
+
# Parse +wrap+ dsl, it wraps current node with code.
|
310
319
|
# @example
|
311
320
|
# # class Foobar
|
312
321
|
# # end
|
data/lib/synvert/core/version.rb
CHANGED
@@ -127,10 +127,19 @@ module Synvert::Core
|
|
127
127
|
it 'parses insert_after' do
|
128
128
|
instance.current_mutation = double
|
129
129
|
instance.current_node = double
|
130
|
-
expect(
|
130
|
+
expect(NodeMutation).to receive_message_chain(:adapter, :get_start_loc, :column).and_return(2)
|
131
|
+
expect(instance.current_mutation).to receive(:insert).with(instance.current_node, "\n Foobar", at: 'end')
|
131
132
|
instance.insert_after 'Foobar'
|
132
133
|
end
|
133
134
|
|
135
|
+
it 'parses insert_before' do
|
136
|
+
instance.current_mutation = double
|
137
|
+
instance.current_node = double
|
138
|
+
expect(NodeMutation).to receive_message_chain(:adapter, :get_start_loc, :column).and_return(2)
|
139
|
+
expect(instance.current_mutation).to receive(:insert).with(instance.current_node, "Foobar\n ", at: 'beginning')
|
140
|
+
instance.insert_before 'Foobar'
|
141
|
+
end
|
142
|
+
|
134
143
|
it 'parses replace_erb_stmt_with_expr' do
|
135
144
|
instance.current_mutation = double
|
136
145
|
instance.current_node = double
|
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.
|
4
|
+
version: 1.13.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: 2022-10-
|
11
|
+
date: 2022-10-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|