File tree Expand file tree Collapse file tree 2 files changed +45
-20
lines changed Expand file tree Collapse file tree 2 files changed +45
-20
lines changed Original file line number Diff line number Diff line change @@ -12,30 +12,25 @@ def each_path_in_patterns(pattern, commandline_patterns = [])
12
12
pats = commandline_patterns . empty? ? pattern . patterns : commandline_patterns
13
13
14
14
pats . each do |path |
15
- absolute_path = base_dir + path
16
-
17
- if absolute_path . file?
18
- relative_path = absolute_path . relative_path_from ( base_dir )
19
- if pattern =~ relative_path
20
- yield relative_path
21
- end
22
- else
23
- files = if absolute_path . directory?
24
- Pathname . glob ( "#{ absolute_path } /**/*#{ pattern . ext } " )
25
- else
26
- Pathname . glob ( absolute_path . to_s )
27
- end
28
-
29
- files . sort . each do |source_path |
30
- if source_path . file?
31
- relative_path = source_path . relative_path_from ( base_dir )
32
- unless pattern . ignore? ( relative_path )
33
- yield relative_path
15
+ Pathname . glob ( ( base_dir + path ) . to_s ) . each do |absolute_path |
16
+ if absolute_path . file?
17
+ relative_path = absolute_path . relative_path_from ( base_dir )
18
+ if pattern =~ relative_path
19
+ yield relative_path
20
+ end
21
+ else
22
+ files = Pathname . glob ( "#{ absolute_path } /**/*#{ pattern . ext } " )
23
+
24
+ files . sort . each do |source_path |
25
+ if source_path . file?
26
+ relative_path = source_path . relative_path_from ( base_dir )
27
+ unless pattern . ignore? ( relative_path )
28
+ yield relative_path
29
+ end
34
30
end
35
31
end
36
32
end
37
33
end
38
-
39
34
end
40
35
else
41
36
enum_for :each_path_in_patterns , pattern , commandline_patterns
Original file line number Diff line number Diff line change @@ -33,4 +33,34 @@ def test_each_path_in_patterns
33
33
assert_empty loader . each_path_in_patterns ( pat , [ "Rakefile" ] ) . to_a
34
34
end
35
35
end
36
+
37
+ def test_each_path_in_patterns_with_glob
38
+ in_tmpdir do
39
+ loader = FileLoader . new ( base_dir : current_dir )
40
+
41
+ ( current_dir + "lib/foo/bar" ) . mkpath ( )
42
+ ( current_dir + "lib/foo/bar/baz.rb" ) . write ( "" )
43
+ ( current_dir + "lib/foo/parser.rb" ) . write ( "" )
44
+ ( current_dir + "lib/foo/bar/index.html.erb" ) . write ( "" )
45
+
46
+ pat = Pattern . new ( patterns : [ "lib/*/bar" ] , ext : ".rb" )
47
+
48
+ assert_equal [ Pathname ( "lib/foo/bar/baz.rb" ) ] , loader . each_path_in_patterns ( pat , [ ] ) . to_a
49
+ end
50
+ end
51
+
52
+ def test_each_path_in_patterns_with_glob_and_ext
53
+ in_tmpdir do
54
+ loader = FileLoader . new ( base_dir : current_dir )
55
+
56
+ ( current_dir + "lib/foo/bar" ) . mkpath ( )
57
+ ( current_dir + "lib/foo/bar/baz.rb" ) . write ( "" )
58
+ ( current_dir + "lib/foo/parser.rb" ) . write ( "" )
59
+ ( current_dir + "lib/foo/bar/index.html.erb" ) . write ( "" )
60
+
61
+ pat = Pattern . new ( patterns : [ "lib/*/bar/baz.rb" ] , ext : ".rb" )
62
+
63
+ assert_equal [ Pathname ( "lib/foo/bar/baz.rb" ) ] , loader . each_path_in_patterns ( pat , [ ] ) . to_a
64
+ end
65
+ end
36
66
end
You can’t perform that action at this time.
0 commit comments