-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
122 additions
and
107 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
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,37 @@ | ||
// | ||
// GorushFactory.swift | ||
// Gorush | ||
// | ||
// Created by Simon Kempendorf on 25.08.20. | ||
// | ||
|
||
import Foundation | ||
import Vapor | ||
|
||
public struct GorushFactory { | ||
var make: ((Request) -> Gorush)? | ||
public mutating func use(_ make: @escaping ((Request) -> Gorush)) { | ||
self.make = make | ||
} | ||
} | ||
|
||
extension Application { | ||
private struct GorushKey: StorageKey { | ||
typealias Value = GorushFactory | ||
} | ||
|
||
public var gorush: GorushFactory { | ||
get { | ||
self.storage[GorushKey.self] ?? .init() | ||
} | ||
set { | ||
self.storage[GorushKey.self] = newValue | ||
} | ||
} | ||
} | ||
|
||
extension Request { | ||
public var gorush: Gorush { | ||
self.application.gorush.make!(self) | ||
} | ||
} |