-
-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from vapor/multi-slug
2.0 - multi slugs
- Loading branch information
Showing
8 changed files
with
86 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,4 @@ Packages | |
.build | ||
.DS_Store | ||
*.xcodeproj | ||
|
||
Package.pins |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
struct SubBranchMap<Output> { | ||
var paramBranches: [String: Branch<Output>] = [:] | ||
var slugBranches: [Branch<Output>] = [] | ||
var wildcard: Branch<Output>? | ||
|
||
var allBranches: [Branch<Output>] { | ||
var all = [Branch<Output>]() | ||
all += paramBranches.values | ||
all += slugBranches | ||
if let wildcard = wildcard { | ||
all.append(wildcard) | ||
} | ||
return all | ||
} | ||
|
||
init() {} | ||
|
||
subscript(key: String) -> Branch<Output>? { | ||
get { | ||
if key == "*" { | ||
return wildcard | ||
} else if key.hasPrefix(":") { | ||
return slugBranches.lazy.filter { $0.name == key } .first | ||
} else { | ||
return paramBranches[key] | ||
} | ||
} | ||
set { | ||
if key == "*" { | ||
wildcard = newValue | ||
} else if key.hasPrefix(":") { | ||
if let existing = slugBranches.index(where: { $0.name == key }) { | ||
if let value = newValue { | ||
slugBranches[existing] = value | ||
} else { | ||
slugBranches.remove(at: existing) | ||
} | ||
} else if let value = newValue { | ||
slugBranches.append(value) | ||
} | ||
} else { | ||
paramBranches[key] = newValue | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
test: | ||
override: | ||
- eval "$(curl -sL https://swift.vapor.sh/ci)" | ||
- eval "$(curl -sL https://swift.vapor.sh/ci-3.1)" |