Skip to content
This repository has been archived by the owner on Apr 20, 2024. It is now read-only.

Commit

Permalink
Merge pull request #92 from nodes-vapor/feature/add-tag-context-helper
Browse files Browse the repository at this point in the history
Feature/add tag context helper
  • Loading branch information
siemensikkema authored Feb 17, 2019
2 parents a204e03 + 018245f commit 572b0db
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 9 deletions.
20 changes: 18 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,26 @@

## 📦 Installation

Update your `Package.swift` file.
Add `Sugar` to the package dependencies (in your `Package.swift` file):

```swift
.package(url: "https://github.com/nodes-vapor/sugar.git", from: "4.0.0")
dependencies: [
...,
.package(url: "https://github.com/nodes-vapor/sugar.git", from: "4.0.0-beta")
]
```

as well as to your target (e.g. "App"):

```swift
targets: [
...
.target(
name: "App",
dependencies: [... "Sugar" ...]
),
...
]
```

## Getting started 🚀
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ public final class JWTAuthenticationMiddleware<A: JWTAuthenticatable>: Middlewar
do {
jwt = try JWT<A.JWTPayload>(from: bearer.token, verifiedUsing: signer)
} catch let error as JWTError where error.identifier == "exp" {
return try Future
.transform(to: HTTPResponse(status: .unauthorized), on: req)
.encode(for: req)
return try req.future(HTTPResponse(status: .unauthorized)).encode(for: req)
}

guard shouldAuthenticate else {
Expand Down
4 changes: 0 additions & 4 deletions Sources/Sugar/Helpers/Future.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ public extension Future {
try callback(expectation).map { _ in expectation }
}
}

static func transform(to value: T, on worker: Worker) -> Future<T> {
return Future.map(on: worker) { value }
}
}

public extension Future where Expectation: OptionalType {
Expand Down
10 changes: 10 additions & 0 deletions Sources/Sugar/Helpers/TagContext.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import TemplateKit

extension TagContext {
/// Throws an error if the parameter count is larger than the supplied number `n`.
public func requireParameterCount(upTo n: Int) throws {
guard parameters.count <= n else {
throw error(reason: "Invalid parameter count: \(parameters.count)/\(n)")
}
}
}

0 comments on commit 572b0db

Please sign in to comment.