Skip to content

Commit

Permalink
Support passing in individual Swift source files (#220)
Browse files Browse the repository at this point in the history
This makes debugging and testing easier. I also intent to use this as the test method for Homebrew formula.
  • Loading branch information
neakor authored Dec 10, 2018
1 parent 565fd40 commit e08b1ad
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class UrlFilter: FileFilter {
///
/// - returns: `true` if the URL should be parsed. `false` otherwise.
func filter() -> Bool {
if !isUrlSwiftSource || urlHasExcludedSuffix || urlHasExcludedPath {
if !url.isSwiftSource || urlHasExcludedSuffix || urlHasExcludedPath {
return false
}
return true
Expand All @@ -50,10 +50,6 @@ class UrlFilter: FileFilter {
private let exclusionSuffixes: [String]
private let exclusionPaths: [String]

private var isUrlSwiftSource: Bool {
return url.pathExtension == "swift"
}

private var urlHasExcludedSuffix: Bool {
let name = url.deletingPathExtension().lastPathComponent
for suffix in exclusionSuffixes {
Expand Down
9 changes: 9 additions & 0 deletions Generator/Sources/NeedleFramework/Utilities/Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,13 @@ extension URL {
self.init(fileURLWithPath: path)
}
}

/// Check if this URL represents a Swift source file by examining its
/// file extenson.
///
/// - returns: `true` if the URL is a Swift source file. `false`
/// otherwise.
var isSwiftSource: Bool {
return pathExtension == "swift"
}
}
12 changes: 8 additions & 4 deletions Generator/Sources/NeedleFramework/Utilities/FileEnumerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,14 @@ class FileEnumerator {
/// - throws: `FileEnumerationError` if any errors occurred.
func enumerate(from rootUrl: URL, withSourcesListFormat sourcesListFormatValue: String?, handler: (URL) -> Void) throws {
if rootUrl.isFileURL {
let format = try sourcesListFileFormat(from: sourcesListFormatValue, withDefault: .newline)
let fileUrls = try self.fileUrls(fromSourcesList: rootUrl, with: format)
for fileUrl in fileUrls {
handler(fileUrl)
if rootUrl.isSwiftSource {
handler(rootUrl)
} else {
let format = try sourcesListFileFormat(from: sourcesListFormatValue, withDefault: .newline)
let fileUrls = try self.fileUrls(fromSourcesList: rootUrl, with: format)
for fileUrl in fileUrls {
handler(fileUrl)
}
}
} else {
let enumerator = try newFileEnumerator(for: rootUrl)
Expand Down

0 comments on commit e08b1ad

Please sign in to comment.