Skip to content

Commit

Permalink
cleaning up
Browse files Browse the repository at this point in the history
  • Loading branch information
g-Off committed Dec 2, 2019
1 parent 7089699 commit a6a74a2
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 42 deletions.
2 changes: 1 addition & 1 deletion Sources/Pathspec/GitIgnoreSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

class GitIgnoreSpec: Spec {
struct GitIgnoreSpec: Spec {
private(set) var inclusive: Bool = true
let regex: NSRegularExpression

Expand Down
29 changes: 7 additions & 22 deletions Sources/Pathspec/Pathspec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,18 @@
//

public final class Pathspec {
public enum Kind {
case git
case regex
}
private var specs: [Spec] = []
private let specs: [Spec]

public init(kind: Kind, patterns: String...) {
for pattern in patterns {
add(pattern: pattern, kind: kind)
public init(patterns: String...) {
specs = patterns.compactMap {
GitIgnoreSpec(pattern: $0)
}
}

public func match(path: String) -> Bool {
return matchingSpecs(path: path).allSatisfy { $0.inclusive }
}

func add(pattern: String, kind: Kind) {
let spec: Spec?
switch kind {
case .git:
spec = GitIgnoreSpec(pattern: pattern)
case .regex:
spec = RegexSpec()
}
if let spec = spec {
specs.append(spec)
}
let matchingSpecs = self.matchingSpecs(path: path)
guard !matchingSpecs.isEmpty else { return false }
return matchingSpecs.allSatisfy { $0.inclusive }
}

private func matchingSpecs(path: String) -> [Spec] {
Expand Down
16 changes: 0 additions & 16 deletions Sources/Pathspec/RegexSpec.swift

This file was deleted.

9 changes: 6 additions & 3 deletions Tests/PathspecTests/PathspecTests.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// File.swift
//
// PathspecTests.swift
// Pathspec
//
// Created by Geoffrey Foster on 2019-06-29.
//
Expand Down Expand Up @@ -255,5 +255,8 @@ final class PathspecTests: XCTestCase {
)
}

// MARK: -
func testFailingInitializers() {
XCTAssertNil(GitIgnoreSpec(pattern: ""))
XCTAssertNil(GitIgnoreSpec(pattern: "***"))
}
}

0 comments on commit a6a74a2

Please sign in to comment.