synvert-core 1.18.0 → 1.18.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 32daaff5e515783785e74b94839328eb08fc1a0c48e6bae047079f0575bba411
4
- data.tar.gz: fde8c7b9081f4a32e6f63e9ee9e6ced1878debf41541f822da788e26b756233f
3
+ metadata.gz: 036a5a2a642e96b611185e400b4f458be77f2622c3ef996bdac4bc0cbda1df70
4
+ data.tar.gz: 51ec847622d9018176f4dceb51a2a9ac623c1129abea3012d6e2faab650ee7f2
5
5
  SHA512:
6
- metadata.gz: 8608a8c3576c5ce5f778c8547a74dfefa99ff166b0137a758972fa910cf7ffa9a7ed4642b8724c6789cf8b203cccd06315ee956451053c577c54899a299405dd
7
- data.tar.gz: d400c921693d29c5ffded99b0874514724f29604e974aee1c69fb551c0f2cf25b09b3230bcb816fed6b1e9903965d01feb2d9912fe4fcd0d4bc86cf3df03f9f8
6
+ metadata.gz: 6c739ddf2691480f5d53fe0033eb24a5c0e784116fec98eff71a58d1d1745a853790121a89979b32624fcb65ea104b837a744b9353fde8ef74ef227433e9be7f
7
+ data.tar.gz: 95ad1ab6a96a33f0299aa012f7731915a7af3794b805b5e5743ddd2d11c48e29dc34019773a3948b96db94aea814d928558c0ee0409a750dae3e85c6d503ec67
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 1.18.1 (2023-02-05)
4
+
5
+ * Fix glob with only paths
6
+
3
7
  ## 1.18.0 (2023-02-01)
4
8
 
5
9
  * Remove `todo` dsl
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- synvert-core (1.18.0)
4
+ synvert-core (1.18.1)
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.9.0)
62
+ parser_node_ext (0.10.0)
63
63
  parser
64
64
  pry (0.14.1)
65
65
  coderay (~> 1.1)
@@ -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(get_file_paths(file_patterns), in_processes: Configuration.number_of_workers) do |file_path|
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
- get_file_paths(file_patterns).map do |file_path|
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
@@ -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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Synvert
4
4
  module Core
5
- VERSION = '1.18.0'
5
+ VERSION = '1.18.1'
6
6
  end
7
7
  end
@@ -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(Dir).to receive(:glob).with('config/routes.rb').and_return(['config/routes.rb'])
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(Dir).to receive(:glob).with('config/routes.rb').and_return(['config/routes.rb'])
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(Dir).to receive(:glob).with('config/routes.rb').and_return(['config/routes.rb'])
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.18.0
4
+ version: 1.18.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: 2023-02-01 00:00:00.000000000 Z
11
+ date: 2023-02-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport