0001 // BranchMiddleware.swift 0002 // 0003 // The MIT License (MIT) 0004 // 0005 // Copyright (c) 2015 Zewo 0006 // 0007 // Permission is hereby granted, free of charge, to any person obtaining a copy 0008 // of this software and associated documentation files (the "Software"), to deal 0009 // in the Software without restriction, including without limitation the rights 0010 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 0011 // copies of the Software, and to permit persons to whom the Software is 0012 // furnished to do so, subject to the following conditions: 0013 // 0014 // The above copyright notice and this permission notice shall be included in all 0015 // copies or substantial portions of the Software. 0016 // 0017 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 0018 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 0019 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 0020 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 0021 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 0022 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 0023 // SOFTWARE. 0024 0025 public struct BranchCondition{ 0026 public let shouldBranch
BranchMiddleware.swift:33 public func branch(condition: BranchCondition, yes: MiddlewareType, no: MiddlewareType? = nil) -> BranchMiddleware {BranchMiddleware.swift:38 let condition: BranchConditionBranchMiddleware.swift:42 public init(_ condition: BranchCondition, yes truthy: MiddlewareType, no falsy: MiddlewareType? = nil) {: Request throws -> Bool 0027 0028 public init(shouldBranch: Request throws -> Bool) { 0029 self.shouldBranch = shouldBranch 0030 } 0031 } 0032 0033 public func branch(condition: BranchCondition, yes: MiddlewareType, no: MiddlewareType? = nil) -> BranchMiddleware { 0034 return BranchMiddleware(condition, yes: yes, no: no) 0035 } 0036 0037 public struct BranchMiddleware
BranchMiddleware.swift:29 self.shouldBranch = shouldBranchBranchMiddleware.swift:49 if try condition.shouldBranch(request) {: MiddlewareType { 0038 let condition
BranchMiddleware.swift:33 public func branch(condition: BranchCondition, yes: MiddlewareType, no: MiddlewareType? = nil) -> BranchMiddleware {BranchMiddleware.swift:34 return BranchMiddleware(condition, yes: yes, no: no): BranchCondition 0039 let truthy
BranchMiddleware.swift:43 self.condition = conditionBranchMiddleware.swift:49 if try condition.shouldBranch(request) {: MiddlewareType 0040 let falsy
BranchMiddleware.swift:44 self.truthy = truthyBranchMiddleware.swift:50 return try truthy.intercept(chain).proceed(request): MiddlewareType? 0041 0042 public init
BranchMiddleware.swift:45 self.falsy = falsyBranchMiddleware.swift:52 if let falsy = falsy {(_ condition: BranchCondition, yes truthy: MiddlewareType, no falsy: MiddlewareType? = nil) { 0043 self.condition = condition 0044 self.truthy = truthy 0045 self.falsy = falsy 0046 } 0047 0048 public func respond(request: Request, chain: ChainType) throws -> Response { 0049 if try condition.shouldBranch(request) { 0050 return try truthy.intercept(chain).proceed(request) 0051 } else { 0052 if let falsy = falsy { 0053 return try falsy.intercept(chain).proceed(request) 0054 } else { 0055 return try chain.proceed(request) 0056 } 0057 } 0058 } 0059 } 0060 0061
BranchMiddleware.swift:34 return BranchMiddleware(condition, yes: yes, no: no)