File tree Expand file tree Collapse file tree 5 files changed +87
-38
lines changed Expand file tree Collapse file tree 5 files changed +87
-38
lines changed Original file line number Diff line number Diff line change 7
7
GEM
8
8
remote: https://rubygems.org/
9
9
specs:
10
- diff-lcs (1.5.0 )
10
+ debug (1.9.2 )
11
+ irb (~> 1.10 )
12
+ reline (>= 0.3.8 )
13
+ diff-lcs (1.5.1 )
14
+ io-console (0.7.2 )
15
+ irb (1.14.0 )
16
+ rdoc (>= 4.0.0 )
17
+ reline (>= 0.4.2 )
11
18
psych (5.1.2 )
12
19
stringio
13
- rake (13.0.6 )
14
- rspec (3.11.0 )
15
- rspec-core (~> 3.11.0 )
16
- rspec-expectations (~> 3.11.0 )
17
- rspec-mocks (~> 3.11.0 )
18
- rspec-core (3.11.0 )
19
- rspec-support (~> 3.11.0 )
20
- rspec-expectations (3.11.1 )
20
+ rake (13.2.1 )
21
+ rdoc (6.7.0 )
22
+ psych (>= 4.0.0 )
23
+ reline (0.5.10 )
24
+ io-console (~> 0.5 )
25
+ rspec (3.13.0 )
26
+ rspec-core (~> 3.13.0 )
27
+ rspec-expectations (~> 3.13.0 )
28
+ rspec-mocks (~> 3.13.0 )
29
+ rspec-core (3.13.1 )
30
+ rspec-support (~> 3.13.0 )
31
+ rspec-expectations (3.13.3 )
21
32
diff-lcs (>= 1.2.0 , < 2.0 )
22
- rspec-support (~> 3.11 .0 )
23
- rspec-mocks (3.11 .1 )
33
+ rspec-support (~> 3.13 .0 )
34
+ rspec-mocks (3.13 .1 )
24
35
diff-lcs (>= 1.2.0 , < 2.0 )
25
- rspec-support (~> 3.11 .0 )
26
- rspec-support (3.11 .1 )
27
- stringio (3.1.0 )
36
+ rspec-support (~> 3.13 .0 )
37
+ rspec-support (3.13 .1 )
38
+ stringio (3.1.1 )
28
39
29
40
PLATFORMS
30
41
arm64-darwin-21
@@ -34,8 +45,9 @@ PLATFORMS
34
45
35
46
DEPENDENCIES
36
47
code_manifest !
48
+ debug
37
49
rake (~> 13.0 )
38
- rspec ( ~> 3.0 )
50
+ rspec
39
51
40
52
BUNDLED WITH
41
53
2.5.4
Original file line number Diff line number Diff line change @@ -21,5 +21,6 @@ Gem::Specification.new do |spec|
21
21
22
22
spec . add_dependency "psych" , ">= 4.0.0"
23
23
24
- spec . add_development_dependency 'rspec' , '~> 3.0'
24
+ spec . add_development_dependency 'rspec'
25
+ spec . add_development_dependency 'debug'
25
26
end
Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ def initialize(patterns)
13
13
@rules ||= Array ( patterns ) . map do |pattern |
14
14
Rule . new ( pattern )
15
15
end
16
+ @cache = { }
16
17
end
17
18
18
19
def files
@@ -33,14 +34,15 @@ def digest
33
34
end
34
35
35
36
def matches ( paths )
36
- result_paths = Array ( paths ) . select do |path |
37
- inclusion_rules . any? { |rule | rule . match? ( path ) }
38
- end
39
- result_paths . reject! do |path |
40
- exclusion_rules . any? { |rule | rule . match? ( path ) }
41
- end
42
-
43
- result_paths . sort!
37
+ Array ( paths ) . select do |path |
38
+ if @cache . key? ( path )
39
+ @cache . fetch ( path )
40
+ else
41
+ @cache [ path ] =
42
+ inclusion_rules . any? { |rule | rule . match? ( path ) } &&
43
+ exclusion_rules . none? { |rule | rule . match? ( path ) }
44
+ end
45
+ end . sort!
44
46
end
45
47
46
48
def matches_all? ( paths )
Original file line number Diff line number Diff line change 107
107
let ( :paths ) do
108
108
[
109
109
'bar/exclude' ,
110
- 'bar/iniclude ' ,
110
+ 'bar/include ' ,
111
111
'foo' ,
112
112
'baz/baz.md'
113
113
]
114
114
end
115
115
116
- around do |example |
117
- root . mkpath
118
- root . join ( 'bar' ) . mkpath
119
- root . join ( 'baz' ) . mkpath
116
+ it 'returns matched paths' do
117
+ expect ( manifest . matches ( paths ) ) . to match_array ( [
118
+ 'bar/include' ,
119
+ 'foo'
120
+ ] )
121
+ end
120
122
121
- paths . each do |path |
122
- FileUtils . touch ( root . join ( path ) )
123
+ context 'caching concerns' do
124
+ let ( :patterns ) { [ '/foo' , '!bar/exclude' ] }
125
+ let ( :paths ) { [ 'foo' ] }
126
+
127
+ it 'caches rule lookups' do
128
+ include_rule = manifest . rules [ 0 ]
129
+ exclude_rule = manifest . rules [ 1 ]
130
+
131
+ expect ( include_rule ) . to receive ( :match? ) . with ( 'foo' ) . once . and_return ( true )
132
+ expect ( exclude_rule ) . to receive ( :match? ) . with ( 'foo' ) . once . and_return ( false )
133
+
134
+ manifest . matches ( paths )
135
+ manifest . matches ( paths )
123
136
end
137
+ end
138
+ end
124
139
125
- example . run
126
- root . rmtree
140
+ describe '#matches_all?' do
141
+ let ( :patterns ) { [ '/foo' , 'bar/*' , '!bar/exclude' ] }
142
+ let ( :manifest ) { described_class . new ( patterns ) }
143
+ let ( :paths ) do
144
+ [
145
+ 'foo' ,
146
+ 'bar/include2' ,
147
+ 'bar/include1' ,
148
+ ]
127
149
end
128
150
129
- it 'returns matched paths' do
130
- expect ( manifest . matches ( paths ) ) . to match_array ( [
131
- 'bar/iniclude' ,
132
- 'foo'
133
- ] )
151
+ it 'returns true if all paths are matched' do
152
+ expect ( manifest . matches_all? ( paths ) ) . to be ( true )
153
+ end
154
+
155
+ context 'when not all paths are matched' do
156
+ let ( :paths ) do
157
+ [
158
+ 'bar/include' ,
159
+ 'bar/exclude' ,
160
+ 'foo'
161
+ ]
162
+ end
163
+
164
+ it 'returns false' do
165
+ expect ( manifest . matches_all? ( paths ) ) . to be ( false )
166
+ end
134
167
end
135
168
end
136
169
end
Original file line number Diff line number Diff line change 18
18
19
19
require 'code_manifest'
20
20
require 'fileutils'
21
+ require 'debug/prelude'
21
22
22
23
RSpec . configure do |config |
23
24
# rspec-expectations config goes here. You can use an alternate
You can’t perform that action at this time.
0 commit comments