synvert-core 1.32.1 → 1.33.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 +1 -1
- data/lib/synvert/core/configuration.rb +9 -0
- data/lib/synvert/core/utils.rb +19 -8
- data/lib/synvert/core/version.rb +1 -1
- data/spec/synvert/core/utils_spec.rb +34 -8
- 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: 279c659ed3a5da5cda7a67c95ef3cc74601d2f64d7dc70ae29431ef8ec4a9929
|
4
|
+
data.tar.gz: 65caaa8ccc16f8789137b8269ad5ec45c6fe1c9d9198dc0b940b09ad3e3e06cd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f45bf64e55621191bfe3a17c689d337d0b25fd356217dd8965876540514bb4b5d04cabb25a834b0567dfba538c93095b12ba281cc02c90a596ec34f8b3dc9231
|
7
|
+
data.tar.gz: 45c5c88b22be8e616cda46e518ee304333d3a8973f58b174182950eef2b958b16ed880311085cf63dc022fe79f8ec3e45fab3a32d23891db829dc5ba8066e075
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -7,6 +7,7 @@ module Synvert::Core
|
|
7
7
|
# @!attribute [w] root_path
|
8
8
|
# @!attribute [w] skip_paths
|
9
9
|
# @!attribute [w] only_paths
|
10
|
+
# @!attribute [w] respect_gitignore
|
10
11
|
# @!attribute [w] show_run_process
|
11
12
|
# @!attribute [w] number_of_workers
|
12
13
|
# @!attribute [w] single_quote
|
@@ -16,6 +17,7 @@ module Synvert::Core
|
|
16
17
|
attr_writer :root_path,
|
17
18
|
:skip_paths,
|
18
19
|
:only_paths,
|
20
|
+
:respect_gitignore,
|
19
21
|
:show_run_process,
|
20
22
|
:number_of_workers,
|
21
23
|
:single_quote,
|
@@ -44,6 +46,13 @@ module Synvert::Core
|
|
44
46
|
@only_paths || []
|
45
47
|
end
|
46
48
|
|
49
|
+
# Check if respect .gitignore
|
50
|
+
#
|
51
|
+
# @return [Boolean] default is true
|
52
|
+
def respect_gitignore
|
53
|
+
@respect_gitignore.nil? ? true : @respect_gitignore
|
54
|
+
end
|
55
|
+
|
47
56
|
# Check if show run process.
|
48
57
|
#
|
49
58
|
# @return [Boolean] default is false
|
data/lib/synvert/core/utils.rb
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
require 'net/http'
|
4
4
|
require 'uri'
|
5
5
|
require 'open-uri'
|
6
|
+
require 'open3'
|
6
7
|
|
7
8
|
module Synvert::Core
|
8
9
|
class Utils
|
@@ -35,11 +36,21 @@ module Synvert::Core
|
|
35
36
|
# @return [Array<String>] file paths
|
36
37
|
def glob(file_patterns)
|
37
38
|
Dir.chdir(Configuration.root_path) do
|
38
|
-
all_files =
|
39
|
-
|
40
|
-
|
39
|
+
all_files = file_patterns.flat_map { |pattern| Dir.glob(pattern) }
|
40
|
+
ignored_files = []
|
41
|
+
|
42
|
+
if Configuration.respect_gitignore
|
43
|
+
Open3.popen3('git check-ignore --stdin') do |stdin, stdout, stderr, wait_thr|
|
44
|
+
stdin.puts(all_files.join("\n"))
|
45
|
+
stdin.close
|
46
|
+
|
47
|
+
ignored_files = stdout.read.split("\n")
|
41
48
|
end
|
42
|
-
|
49
|
+
end
|
50
|
+
|
51
|
+
filtered_files = filter_only_paths(all_files - ignored_files)
|
52
|
+
|
53
|
+
filtered_files -= get_explicitly_skipped_files
|
43
54
|
end
|
44
55
|
end
|
45
56
|
|
@@ -85,16 +96,16 @@ module Synvert::Core
|
|
85
96
|
# Filter only paths with `Configuration.only_paths`.
|
86
97
|
# @return [Array<String>] filtered file paths
|
87
98
|
def filter_only_paths(all_files)
|
88
|
-
return all_files if Configuration.only_paths.
|
99
|
+
return all_files if Configuration.only_paths.empty?
|
89
100
|
|
90
101
|
Configuration.only_paths.flat_map do |only_path|
|
91
102
|
all_files.filter { |file_path| file_path.starts_with?(only_path) }
|
92
103
|
end
|
93
104
|
end
|
94
105
|
|
95
|
-
# Get
|
96
|
-
# @return [Array<String>]
|
97
|
-
def
|
106
|
+
# Get skipped files.
|
107
|
+
# @return [Array<String>] skipped files
|
108
|
+
def get_explicitly_skipped_files
|
98
109
|
Configuration.skip_paths.flat_map do |skip_path|
|
99
110
|
if File.directory?(skip_path)
|
100
111
|
Dir.glob(File.join(skip_path, "**/*"))
|
data/lib/synvert/core/version.rb
CHANGED
@@ -58,16 +58,42 @@ module Synvert::Core
|
|
58
58
|
before do
|
59
59
|
Configuration.only_paths = []
|
60
60
|
Configuration.skip_paths = []
|
61
|
+
Configuration.respect_gitignore = false
|
61
62
|
end
|
62
63
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
64
|
+
context 'Configuration.respect_gitignore is false' do
|
65
|
+
it 'gets all files' do
|
66
|
+
expect(Dir).to receive(:glob).with('**/*.rb').and_return(
|
67
|
+
[
|
68
|
+
'app/models/post.rb',
|
69
|
+
'app/controllers/posts_controller.rb'
|
70
|
+
]
|
71
|
+
)
|
72
|
+
expect(described_class.glob(['**/*.rb'])).to eq(['app/models/post.rb', 'app/controllers/posts_controller.rb'])
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
context 'Configuration.respect_gitignore is true' do
|
77
|
+
before do
|
78
|
+
Configuration.respect_gitignore = true
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'correctly filters out ignored files' do
|
82
|
+
file_patterns = ["**/*.rb"]
|
83
|
+
all_files = ["app/models/post.rb", "app/controllers/posts_controller.rb", "app/controllers/temp.tmp"]
|
84
|
+
not_ignored_files = ["app/models/post.rb", "app/controllers/posts_controller.rb"]
|
85
|
+
command_output = "app/controllers/temp.tmp\n"
|
86
|
+
|
87
|
+
allow(Open3).to receive(:popen3).with('git check-ignore --stdin').and_yield(
|
88
|
+
instance_double(IO, puts: nil, close: nil),
|
89
|
+
StringIO.new(command_output),
|
90
|
+
StringIO.new(''),
|
91
|
+
instance_double(Process::Waiter, value: instance_double(Process::Status, success?: true))
|
92
|
+
)
|
93
|
+
allow(Dir).to receive(:glob).and_return(all_files)
|
94
|
+
|
95
|
+
expect(described_class.glob(file_patterns)).to match_array(not_ignored_files)
|
96
|
+
end
|
71
97
|
end
|
72
98
|
|
73
99
|
it 'filters only paths' do
|
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.33.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: 2024-02-
|
11
|
+
date: 2024-02-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|