-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add initial structure for context and reference (#203)
- Loading branch information
Showing
14 changed files
with
966 additions
and
6 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
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,6 +1,6 @@ | ||
import Vapor | ||
|
||
/// Called after your application has initialized. | ||
public func boot(_ app: Application) throws { | ||
func boot(_ app: Application) throws { | ||
// Your code here | ||
} |
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,79 @@ | ||
import Foundation | ||
|
||
public enum Kind: Codable, Equatable, Hashable { | ||
case user | ||
case multi | ||
case custom(String) | ||
|
||
public init(from decoder: Decoder) throws { | ||
let container = try decoder.singleValueContainer() | ||
|
||
switch try container.decode(String.self) { | ||
case "user": | ||
self = .user | ||
case "multi": | ||
self = .multi | ||
case let custom: | ||
self = .custom(custom) | ||
} | ||
} | ||
|
||
public func encode(to encoder: Encoder) throws { | ||
var container = encoder.singleValueContainer() | ||
try container.encode(self.description) | ||
} | ||
|
||
public func isMulti() -> Bool { | ||
self == .multi || self == .custom("multi") | ||
} | ||
|
||
public func isUser() -> Bool { | ||
self == .user || self == .custom("user") || self == .custom("") | ||
} | ||
|
||
private static func isValid(_ description: String) -> Bool { | ||
description.onlyContainsCharset(Util.validKindCharacterSet) | ||
} | ||
} | ||
|
||
extension Kind: Comparable { | ||
public static func < (lhs: Kind, rhs: Kind) -> Bool { | ||
lhs.description < rhs.description | ||
} | ||
|
||
public static func == (lhs: Kind, rhs: Kind) -> Bool { | ||
lhs.description == rhs.description | ||
} | ||
} | ||
|
||
extension Kind: LosslessStringConvertible { | ||
public init?(_ description: String) { | ||
switch description { | ||
case "kind": | ||
return nil | ||
case "multi": | ||
self = .multi | ||
case "", "user": | ||
self = .user | ||
default: | ||
if !Kind.isValid(description) { | ||
return nil | ||
} | ||
|
||
self = .custom(description) | ||
} | ||
} | ||
} | ||
|
||
extension Kind: CustomStringConvertible { | ||
public var description: String { | ||
switch self { | ||
case .user: | ||
return "user" | ||
case .multi: | ||
return "multi" | ||
case let .custom(val): | ||
return val | ||
} | ||
} | ||
} |
Oops, something went wrong.