synvert-core 1.8.1 → 1.9.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6007d28c9a4371057b72bfbd4e73c23163cf52c384e7cef0a3fcdcd71b384fcd
4
- data.tar.gz: 5b43685d36948aaf52dd313fdf0e6198eefa73ff12813853d1f289577f58da07
3
+ metadata.gz: 0bd7dcc7605d1a18cc68ebfba86d5947960bd1320da0b5f7ae41abc8638fed62
4
+ data.tar.gz: 3023d5fb8a740da0ce0191bdd08f7435cc931e690714d2195391cf03586efa70
5
5
  SHA512:
6
- metadata.gz: bc762494a28bc325231e1903130fbd14056442646b463b2e336426e59830f2ee8216fb6caa29c50960fed82a75bc320d4196919b0bffb9ab2547674f19bc89ac
7
- data.tar.gz: 60e6b882a9b039c42acecb27581fca198482eeef15628ac9123daf4e08dd0bc109ebff3a1e5c2c7ac62ad8fd4fc7e6fdf65871d83b98a3a90c32b71702ff4057
6
+ metadata.gz: a3c7f43d890a491a7bb3356ec1695a79278a8c19cf61df4f296a1ea6562cbbcfa27764b36cbb22e06f9f27cd53157e2276392bba42856d58212fddb68e92ffac
7
+ data.tar.gz: 9959f0f8290157b96c83011ef770d59b40b845b236e0f8facf24cb6795cd7a837936a8969e380910df2892604dd25f569c66b9ff0c7aa5649e441b5ddf72b32a
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 1.9.1 (2022-09-23)
4
+
5
+ * Read / write absolute path
6
+
7
+ ## 1.9.0 (2022-09-20)
8
+
9
+ * Add `noop` dsl
10
+
3
11
  ## 1.8.1 (2022-09-17)
4
12
 
5
13
  * Fix test snippet, return test results
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- synvert-core (1.8.1)
4
+ synvert-core (1.9.1)
5
5
  activesupport (< 7.0.0)
6
6
  erubis
7
7
  node_mutation
@@ -49,7 +49,7 @@ GEM
49
49
  method_source (1.0.0)
50
50
  minitest (5.16.3)
51
51
  nenv (0.3.0)
52
- node_mutation (1.3.3)
52
+ node_mutation (1.4.1)
53
53
  activesupport (< 7.0.0)
54
54
  erubis
55
55
  node_query (1.6.0)
data/README.md CHANGED
@@ -96,3 +96,4 @@ Actions:
96
96
  * [replace_with](./Synvert/Core/Rewriter/Instance.html#replace_with-instance_method) - replace the whole code of current node
97
97
  * [warn](./Synvert/Core/Rewriter/Instance.html#warn-instance_method) - warn message
98
98
  * [replace_erb_stmt_with_expr](./Synvert/Core/Rewriter/Instance.html#replace_erb_stmt_with_expr-instance_method) - replace erb stmt code to expr code
99
+ * [noop](./Synvert/Core/Rewriter/Instance.html#noop-instance_method) - no operation
@@ -325,6 +325,11 @@ module Synvert::Core
325
325
  @current_mutation.wrap(@current_node, with: with)
326
326
  end
327
327
 
328
+ # Parse +noop dsl.
329
+ def noop
330
+ @current_mutation.noop(@current_node)
331
+ end
332
+
328
333
  # Parse +warn+ dsl, it creates a {Synvert::Core::Rewriter::Warning} to save warning message.
329
334
  # @example
330
335
  # within_files 'vendor/plugins' do
@@ -351,9 +356,9 @@ module Synvert::Core
351
356
  def process_file(file_path)
352
357
  puts file_path if Configuration.show_run_process
353
358
 
354
- @current_file = file_path
359
+ @current_file = File.join(Configuration.root_path, file_path)
355
360
  while true
356
- source = read_source(file_path)
361
+ source = read_source(@current_file)
357
362
  @current_mutation = NodeMutation.new(source)
358
363
  begin
359
364
  node = parse_code(file_path, source)
@@ -373,7 +378,7 @@ module Synvert::Core
373
378
  result = @current_mutation.process
374
379
  if result.affected?
375
380
  @rewriter.add_affected_file(file_path)
376
- write_source(file_path, result.new_source)
381
+ write_source(@current_file, result.new_source)
377
382
  end
378
383
  break unless result.conflicted?
379
384
  rescue Parser::SyntaxError
@@ -387,11 +392,11 @@ module Synvert::Core
387
392
  #
388
393
  # @param file_path [String]
389
394
  def test_file(file_path)
390
- @current_file = file_path
391
- source = read_source(file_path)
395
+ @current_file = File.join(Configuration.root_path, file_path)
396
+ source = read_source(@current_file)
392
397
  @current_mutation = NodeMutation.new(source)
393
398
  begin
394
- node = parse_code(file_path, source)
399
+ node = parse_code(@current_file, source)
395
400
 
396
401
  process_with_node(node) do
397
402
  instance_eval(&@block)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Synvert
4
4
  module Core
5
- VERSION = '1.8.1'
5
+ VERSION = '1.9.1'
6
6
  end
7
7
  end
@@ -176,6 +176,13 @@ module Synvert::Core
176
176
  instance.wrap with: 'module Foobar'
177
177
  end
178
178
 
179
+ it 'parses noop' do
180
+ instance.current_mutation = double
181
+ instance.current_node = double
182
+ expect(instance.current_mutation).to receive(:noop).with(instance.current_node)
183
+ instance.noop
184
+ end
185
+
179
186
  it 'parses warn' do
180
187
  expect(Rewriter::Warning).to receive(:new).with(instance, 'foobar')
181
188
  instance.warn 'foobar'
@@ -206,8 +213,8 @@ module Synvert::Core
206
213
  end
207
214
  EOS
208
215
  expect(Dir).to receive(:glob).with('spec/**/*_spec.rb').and_return(['spec/models/post_spec.rb'])
209
- expect(File).to receive(:read).with('spec/models/post_spec.rb', encoding: 'UTF-8').and_return(input)
210
- expect(File).to receive(:write).with('spec/models/post_spec.rb', output)
216
+ expect(File).to receive(:read).with('./spec/models/post_spec.rb', encoding: 'UTF-8').and_return(input)
217
+ expect(File).to receive(:write).with('./spec/models/post_spec.rb', output)
211
218
  instance.process
212
219
  end
213
220
 
@@ -231,8 +238,8 @@ module Synvert::Core
231
238
  end
232
239
  EOS
233
240
  expect(Dir).to receive(:glob).with('spec/spec_helper.rb').and_return(['spec/spec_helper.rb'])
234
- expect(File).to receive(:read).with('spec/spec_helper.rb', encoding: 'UTF-8').and_return(input)
235
- expect(File).not_to receive(:write).with('spec/spec_helper.rb', output)
241
+ expect(File).to receive(:read).with('./spec/spec_helper.rb', encoding: 'UTF-8').and_return(input)
242
+ expect(File).not_to receive(:write).with('./spec/spec_helper.rb', output)
236
243
  instance.process
237
244
  end
238
245
 
@@ -258,9 +265,9 @@ module Synvert::Core
258
265
  end
259
266
  EOS
260
267
  expect(Dir).to receive(:glob).with('spec/**/*_spec.rb').and_return(['spec/models/post_spec.rb']).twice
261
- expect(File).to receive(:read).with('spec/models/post_spec.rb', encoding: 'UTF-8').and_return(input)
262
- expect(File).to receive(:write).with('spec/models/post_spec.rb', output)
263
- expect(File).to receive(:read).with('spec/models/post_spec.rb', encoding: 'UTF-8').and_return(output)
268
+ expect(File).to receive(:read).with('./spec/models/post_spec.rb', encoding: 'UTF-8').and_return(input)
269
+ expect(File).to receive(:write).with('./spec/models/post_spec.rb', output)
270
+ expect(File).to receive(:read).with('./spec/models/post_spec.rb', encoding: 'UTF-8').and_return(output)
264
271
  instance.process
265
272
  instance.process
266
273
  expect(rewriter.affected_files).to be_include('spec/models/post_spec.rb')
@@ -285,7 +292,7 @@ module Synvert::Core
285
292
  end
286
293
  EOS
287
294
  expect(Dir).to receive(:glob).with('spec/**/*_spec.rb').and_return(['spec/models/post_spec.rb'])
288
- expect(File).to receive(:read).with('spec/models/post_spec.rb', encoding: 'UTF-8').and_return(input)
295
+ expect(File).to receive(:read).with('./spec/models/post_spec.rb', encoding: 'UTF-8').and_return(input)
289
296
  results = instance.test
290
297
  expect(results[0].file_path).to eq 'spec/models/post_spec.rb'
291
298
  expect(results[0].actions).to eq [
@@ -309,7 +316,7 @@ module Synvert::Core
309
316
  end
310
317
  EOS
311
318
  expect(Dir).to receive(:glob).with('spec/spec_helper.rb').and_return(['spec/spec_helper.rb'])
312
- expect(File).to receive(:read).with('spec/spec_helper.rb', encoding: 'UTF-8').and_return(input)
319
+ expect(File).to receive(:read).with('./spec/spec_helper.rb', encoding: 'UTF-8').and_return(input)
313
320
  result = instance.test
314
321
  expect(result[0].file_path).to eq 'spec/spec_helper.rb'
315
322
  expect(result[0].actions).to eq []
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.8.1
4
+ version: 1.9.1
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-09-17 00:00:00.000000000 Z
11
+ date: 2022-09-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport