Skip to content

Commit

Permalink
Create IgnoreFile.init() to simplify error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
shiraji committed Oct 24, 2016
1 parent 9960b48 commit 45a3293
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
4 changes: 4 additions & 0 deletions R.swift/Util/IgnoreFile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ import Foundation

class IgnoreFile {
private let patterns: [String]

init() {
patterns = []
}

init(ignoreFileURL: URL) throws {
let ignoreFileParentPath = ignoreFileURL.baseURL?.absoluteString ?? ""
Expand Down
13 changes: 4 additions & 9 deletions R.swift/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,24 @@ let IndentationString = " "
let ResourceFilename = "R.generated.swift"

var isEdgeEnabled = false
private func isValidURL(ignoreFile : IgnoreFile?, url: NSURL) -> Bool {
if let ignoreFile = ignoreFile {
return !ignoreFile.match(url: url)
} else {
return true
}
}

do {
let callInformation = try CallInformation(processInfo: ProcessInfo())
isEdgeEnabled = callInformation.edge

let xcodeproj = try Xcodeproj(url: callInformation.xcodeprojURL)

var ignoreFile : IgnoreFile? = nil
let ignoreFile : IgnoreFile
if let rswiftignoreURL = callInformation.rswiftignoreURL {
ignoreFile = try IgnoreFile(ignoreFileURL: rswiftignoreURL)
} else {
ignoreFile = IgnoreFile()
}

let resourceURLs = try xcodeproj.resourcePathsForTarget(callInformation.targetName)
.map(pathResolver(with: callInformation.URLForSourceTreeFolder))
.flatMap { $0 }
.filter { isValidURL(ignoreFile: ignoreFile, url: $0 as NSURL) }
.filter { !ignoreFile.match(url: $0 as NSURL) }

let resources = Resources(resourceURLs: resourceURLs, fileManager: FileManager.default)

Expand Down

0 comments on commit 45a3293

Please sign in to comment.