@@ -36,6 +36,7 @@ object Synchronize {
36
36
type SearchGlob = String
37
37
type ExampleFilename = String
38
38
type FileContent = String
39
+ type IgnoreMask = String
39
40
40
41
val charset = Charset .Standard .utf8
41
42
@@ -46,10 +47,13 @@ object Synchronize {
46
47
} yield content
47
48
}
48
49
49
- def findFiles (fromRootFilename : SearchRoot , globPattern : SearchGlob ): RIO [Blocking , List [ExampleFilename ]] = {
50
+ def findFiles (fromRootFilename : SearchRoot , globPattern : SearchGlob , ignoreMask : Option [ IgnoreMask ] = None ): RIO [Blocking , List [ExampleFilename ]] = {
50
51
val pathMatcher = FileSystem .default.getPathMatcher(s " glob: $globPattern" )
52
+ val ignoreMaskRegex = ignoreMask.map(_.r)
51
53
def pathFilter (path : Path , fileAttrs : BasicFileAttributes ): Boolean = {
52
- pathMatcher.matches(path.toFile.toPath) && ! fileAttrs.isDirectory
54
+ pathMatcher.matches(path.toFile.toPath) &&
55
+ ! fileAttrs.isDirectory &&
56
+ (ignoreMask.isEmpty || ignoreMaskRegex.get.findFirstIn(path.toString).isEmpty)
53
57
}
54
58
val from = Path (fromRootFilename)
55
59
val foundFilesStream = Files .find(from)(pathFilter)
@@ -62,11 +66,12 @@ object Synchronize {
62
66
def examplesFromGivenRoot (
63
67
searchRoot : SearchRoot ,
64
68
globPattern : SearchGlob ,
65
- filesFetcher : (SearchRoot , SearchGlob ) => RIO [Blocking , List [ExampleFilename ]],
69
+ ignoreMask : Option [IgnoreMask ],
70
+ filesFetcher : (SearchRoot , SearchGlob , Option [IgnoreMask ]) => RIO [Blocking , List [ExampleFilename ]],
66
71
contentFetcher : ExampleFilename => RIO [Blocking , FileContent ]
67
72
): RIO [Blocking , List [CodeExample ]] = {
68
73
for {
69
- foundFilenames <- filesFetcher(searchRoot, globPattern)
74
+ foundFilenames <- filesFetcher(searchRoot, globPattern, ignoreMask )
70
75
examplesTasks = foundFilenames.map(file => CodeExample .makeExample(file, searchRoot, contentFetcher(file))).toList
71
76
examples <- RIO .mergeAll(examplesTasks)(List .empty[CodeExample ])((accu, next) => next :: accu)
72
77
} yield examples.filter(_.uuid.isDefined)
@@ -81,8 +86,8 @@ object Synchronize {
81
86
} yield pathsAsStrings
82
87
}
83
88
84
- def examplesCollectFor (searchRoots : List [SearchRoot ], usingGlobPattern : SearchGlob ): RIO [Blocking , Vector [CodeExample ]] = {
85
- val examplesFromRoots = searchRoots.map(fromRoot => examplesFromGivenRoot(fromRoot, usingGlobPattern, findFiles, readFileContent))
89
+ def examplesCollectFor (searchRoots : List [SearchRoot ], usingGlobPattern : SearchGlob , usingIgnoreMask : Option [ IgnoreMask ] ): RIO [Blocking , Vector [CodeExample ]] = {
90
+ val examplesFromRoots = searchRoots.map(fromRoot => examplesFromGivenRoot(fromRoot, usingGlobPattern, usingIgnoreMask, findFiles, readFileContent))
86
91
RIO .mergeAll(examplesFromRoots)(Vector .empty[CodeExample ])((accu, newRoot) => accu.appendedAll(newRoot))
87
92
}
88
93
@@ -98,7 +103,7 @@ object Synchronize {
98
103
config <- getConfig[ApplicationConfig ]
99
104
examplesConfig = config.codeExamplesManagerConfig.examples
100
105
searchRoots <- examplesValidSearchRoots(examplesConfig.searchRootDirectories)
101
- localExamples <- examplesCollectFor(searchRoots, examplesConfig.searchGlob)
106
+ localExamples <- examplesCollectFor(searchRoots, examplesConfig.searchGlob, examplesConfig.searchIgnoreMask )
102
107
_ <- examplesCheckCoherency(localExamples)
103
108
} yield localExamples
104
109
0 commit comments