synvert-core 1.18.0 → 1.19.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 +8 -0
- data/Gemfile.lock +2 -2
- data/README.md +0 -1
- data/lib/synvert/core/rewriter/instance.rb +1 -5
- data/lib/synvert/core/rewriter.rb +2 -32
- data/lib/synvert/core/utils.rb +38 -0
- data/lib/synvert/core/version.rb +1 -1
- data/spec/synvert/core/rewriter_spec.rb +3 -3
- data/spec/synvert/core/utils_spec.rb +25 -0
- 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: 8a431b26d98c476c389746269aade183f241a3c1cb2fabab27b87b2b0689510f
|
4
|
+
data.tar.gz: 61b1907dbadbef95ca5d8869b6c27f65e43f72dccd0f64ead4ad3cf15a5f9c01
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e3ee5356583c8450635e8296657860e7016a8dfe0214fb2518da72aa2631e7511672802e326553bd44b3de1dea7e683a0784ff58770c641dae76ab9bca86e317
|
7
|
+
data.tar.gz: d7426a0450fbfaf871c8083aa4d06b1a1bf439436ed964cfb8e2325e832a05b479b1f81ae71c2b3b103c614a02b7eb23ddfc4ac6311f14b7e161a54893bb040b
|
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.19.0)
|
5
5
|
activesupport (< 7.0.0)
|
6
6
|
erubis
|
7
7
|
node_mutation (>= 1.8.2)
|
@@ -59,7 +59,7 @@ GEM
|
|
59
59
|
parallel (1.22.1)
|
60
60
|
parser (3.2.0.0)
|
61
61
|
ast (~> 2.4.1)
|
62
|
-
parser_node_ext (0.
|
62
|
+
parser_node_ext (0.10.0)
|
63
63
|
parser
|
64
64
|
pry (0.14.1)
|
65
65
|
coderay (~> 1.1)
|
data/README.md
CHANGED
@@ -105,5 +105,4 @@ Attributes:
|
|
105
105
|
|
106
106
|
* [file_path](https://xinminlabs.github.io/synvert-core-ruby/Synvert/Core/Rewriter/Instance.html#file_path-instance_method) - current file path
|
107
107
|
* [node](https://xinminlabs.github.io/synvert-core-ruby/Synvert/Core/Rewriter/Instance.html#node-instance_method) - current ast node
|
108
|
-
* [query_adapter](https://xinminlabs.github.io/synvert-core-ruby/Synvert/Core/Rewriter/Instance.html#query_adapter-instance_method) - [query adapter](https://xinminlabs.github.io/node-query-ruby/NodeQuery/Adapter.html) to get some helper methods
|
109
108
|
* [mutation_adapter](https://xinminlabs.github.io/synvert-core-ruby/Synvert/Core/Rewriter/Instance.html#mutation_adapter-instance_method) - [mutation adapter](https://xinminlabs.github.io/node-mutation-ruby/NodeMutation/Adapter.html) to get some helper methods
|
@@ -30,11 +30,9 @@ module Synvert::Core
|
|
30
30
|
# @return file path
|
31
31
|
# @!attribute [rw] current_node
|
32
32
|
# @return current ast node
|
33
|
-
# @!attribute [r] query_adapter
|
34
|
-
# @return NodeQuery Adapter
|
35
33
|
# @!attribute [r] mutation_adapter
|
36
34
|
# @return NodeMutation Adapter
|
37
|
-
attr_reader :file_path, :current_node, :
|
35
|
+
attr_reader :file_path, :current_node, :mutation_adapter
|
38
36
|
attr_accessor :current_node
|
39
37
|
|
40
38
|
# Process the instance.
|
@@ -48,7 +46,6 @@ module Synvert::Core
|
|
48
46
|
source = read_source(absolute_file_path)
|
49
47
|
@current_mutation = NodeMutation.new(source)
|
50
48
|
@mutation_adapter = NodeMutation.adapter
|
51
|
-
@query_adapter = NodeQuery.adapter
|
52
49
|
begin
|
53
50
|
node = parse_code(@file_path, source)
|
54
51
|
|
@@ -85,7 +82,6 @@ module Synvert::Core
|
|
85
82
|
source = read_source(absolute_file_path)
|
86
83
|
@current_mutation = NodeMutation.new(source)
|
87
84
|
@mutation_adapter = NodeMutation.adapter
|
88
|
-
@query_adapter = NodeQuery.adapter
|
89
85
|
begin
|
90
86
|
node = parse_code(file_path, source)
|
91
87
|
|
@@ -347,46 +347,16 @@ module Synvert::Core
|
|
347
347
|
# @yieldparam file_path [String] file path.
|
348
348
|
def handle_one_file(file_patterns)
|
349
349
|
if Configuration.number_of_workers > 1
|
350
|
-
Parallel.map(
|
350
|
+
Parallel.map(Utils.glob(file_patterns), in_processes: Configuration.number_of_workers) do |file_path|
|
351
351
|
yield(file_path)
|
352
352
|
end
|
353
353
|
else
|
354
|
-
|
354
|
+
Utils.glob(file_patterns).map do |file_path|
|
355
355
|
yield(file_path)
|
356
356
|
end
|
357
357
|
end
|
358
358
|
end
|
359
359
|
|
360
|
-
# Get file paths.
|
361
|
-
# @return [Array<String>] file paths
|
362
|
-
def get_file_paths(file_patterns)
|
363
|
-
Dir.chdir(Configuration.root_path) do
|
364
|
-
only_paths = Configuration.only_paths.size > 0 ? Configuration.only_paths : ["."]
|
365
|
-
only_paths.flat_map do |only_path|
|
366
|
-
file_patterns.flat_map do |file_pattern|
|
367
|
-
pattern = only_path == "." ? file_pattern : File.join(only_path, file_pattern)
|
368
|
-
Dir.glob(pattern)
|
369
|
-
end
|
370
|
-
end - get_skip_files
|
371
|
-
end
|
372
|
-
end
|
373
|
-
|
374
|
-
# Get skip files.
|
375
|
-
# @return [Array<String>] skip files
|
376
|
-
def get_skip_files
|
377
|
-
Configuration.skip_paths.flat_map do |skip_path|
|
378
|
-
if File.directory?(skip_path)
|
379
|
-
Dir.glob(File.join(skip_path, "**/*"))
|
380
|
-
elsif File.file?(skip_path)
|
381
|
-
[skip_path]
|
382
|
-
elsif skip_path.end_with?("**") || skip_path.end_with?("**/")
|
383
|
-
Dir.glob(File.join(skip_path, "*"))
|
384
|
-
else
|
385
|
-
Dir.glob(skip_path)
|
386
|
-
end
|
387
|
-
end
|
388
|
-
end
|
389
|
-
|
390
360
|
def merge_test_results(results)
|
391
361
|
@test_results += results.select { |result| result.affected? }
|
392
362
|
end
|
data/lib/synvert/core/utils.rb
CHANGED
@@ -27,6 +27,18 @@ module Synvert::Core
|
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
+
# Glob file paths.
|
31
|
+
# @param file_patterns [Array<String>] file patterns
|
32
|
+
# @return [Array<String>] file paths
|
33
|
+
def glob(file_patterns)
|
34
|
+
Dir.chdir(Configuration.root_path) do
|
35
|
+
all_files = file_patterns.flat_map do |file_pattern|
|
36
|
+
Dir.glob(file_pattern)
|
37
|
+
end
|
38
|
+
filter_only_paths(all_files) - get_skip_files
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
30
42
|
private
|
31
43
|
|
32
44
|
def is_valid_url?(url)
|
@@ -65,6 +77,32 @@ module Synvert::Core
|
|
65
77
|
|
66
78
|
url.sub('//github.com/', '//raw.githubusercontent.com/').sub('/blob/', '/')
|
67
79
|
end
|
80
|
+
|
81
|
+
# Filter only paths with `Configuration.only_paths`.
|
82
|
+
# @return [Array<String>] filtered file paths
|
83
|
+
def filter_only_paths(all_files)
|
84
|
+
return all_files if Configuration.only_paths.size == 0
|
85
|
+
|
86
|
+
Configuration.only_paths.flat_map do |only_path|
|
87
|
+
all_files.filter { |file_path| file_path.starts_with?(only_path) }
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
# Get skip files.
|
92
|
+
# @return [Array<String>] skip files
|
93
|
+
def get_skip_files
|
94
|
+
Configuration.skip_paths.flat_map do |skip_path|
|
95
|
+
if File.directory?(skip_path)
|
96
|
+
Dir.glob(File.join(skip_path, "**/*"))
|
97
|
+
elsif File.file?(skip_path)
|
98
|
+
[skip_path]
|
99
|
+
elsif skip_path.end_with?("**") || skip_path.end_with?("**/")
|
100
|
+
Dir.glob(File.join(skip_path, "*"))
|
101
|
+
else
|
102
|
+
Dir.glob(skip_path)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
68
106
|
end
|
69
107
|
end
|
70
108
|
end
|
data/lib/synvert/core/version.rb
CHANGED
@@ -86,7 +86,7 @@ module Synvert::Core
|
|
86
86
|
end
|
87
87
|
|
88
88
|
it 'delegates process to instances if if_ruby matches' do
|
89
|
-
expect(
|
89
|
+
expect(Utils).to receive(:glob).with(['config/routes.rb']).and_return(['config/routes.rb'])
|
90
90
|
expect(File).to receive(:exist?).with('./.ruby-version').and_return(true)
|
91
91
|
expect(File).to receive(:read).with('./.ruby-version').and_return('2.0.0')
|
92
92
|
expect_any_instance_of(Rewriter::Instance).to receive(:process)
|
@@ -112,7 +112,7 @@ module Synvert::Core
|
|
112
112
|
end
|
113
113
|
|
114
114
|
it 'delegates process to instances if if_gem matches' do
|
115
|
-
expect(
|
115
|
+
expect(Utils).to receive(:glob).with(['config/routes.rb']).and_return(['config/routes.rb'])
|
116
116
|
expect_any_instance_of(Rewriter::GemSpec).to receive(:match?).and_return(true)
|
117
117
|
expect_any_instance_of(Rewriter::Instance).to receive(:process)
|
118
118
|
rewriter =
|
@@ -125,7 +125,7 @@ module Synvert::Core
|
|
125
125
|
end
|
126
126
|
|
127
127
|
it 'delegates process to instances if if_ruby and if_gem do not exist' do
|
128
|
-
expect(
|
128
|
+
expect(Utils).to receive(:glob).with(['config/routes.rb']).and_return(['config/routes.rb'])
|
129
129
|
expect_any_instance_of(Rewriter::Instance).to receive(:process)
|
130
130
|
rewriter =
|
131
131
|
Rewriter.new 'group', 'name' do
|
@@ -53,5 +53,30 @@ module Synvert::Core
|
|
53
53
|
end
|
54
54
|
end
|
55
55
|
end
|
56
|
+
|
57
|
+
describe '.glob' do
|
58
|
+
before do
|
59
|
+
Configuration.only_paths = []
|
60
|
+
Configuration.skip_paths = []
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'gets all files' do
|
64
|
+
expect(Dir).to receive(:glob).with('**/*.rb').and_return(['app/models/post.rb', 'app/controllers/posts_controller.rb'])
|
65
|
+
expect(described_class.glob(['**/*.rb'])).to eq(['app/models/post.rb', 'app/controllers/posts_controller.rb'])
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'filters only paths' do
|
69
|
+
Configuration.only_paths = ['app/models']
|
70
|
+
expect(Dir).to receive(:glob).with('**/*.rb').and_return(['app/models/post.rb', 'app/controllers/posts_controller.rb'])
|
71
|
+
expect(described_class.glob(['**/*.rb'])).to eq(['app/models/post.rb'])
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'skip files' do
|
75
|
+
Configuration.skip_paths = ['app/controllers/**/*']
|
76
|
+
expect(Dir).to receive(:glob).with('**/*.rb').and_return(['app/models/post.rb', 'app/controllers/posts_controller.rb'])
|
77
|
+
expect(Dir).to receive(:glob).with('app/controllers/**/*').and_return(['app/controllers/posts_controller.rb'])
|
78
|
+
expect(described_class.glob(['**/*.rb'])).to eq(['app/models/post.rb'])
|
79
|
+
end
|
80
|
+
end
|
56
81
|
end
|
57
82
|
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: 1.
|
4
|
+
version: 1.19.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: 2023-02-
|
11
|
+
date: 2023-02-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|