Skip to content

Commit

Permalink
feat(configuration): add context to loadFromEnvironment (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
portellaa authored Jun 7, 2023
1 parent 0fa3ef6 commit 89d2105
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 14 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"cmake.configureOnOpen": false
}
20 changes: 10 additions & 10 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,17 @@
"repositoryURL": "https://github.com/vapor/fluent.git",
"state": {
"branch": null,
"revision": "2da106f46b093885f77fa03e3c719ab5bb8cfab4",
"version": "4.6.0"
"revision": "4b4d8bf15a06fd60137e9c543e5503c4b842654e",
"version": "4.8.0"
}
},
{
"package": "fluent-kit",
"repositoryURL": "https://github.com/vapor/fluent-kit.git",
"state": {
"branch": null,
"revision": "be7912ee4991bcc8a5390fac0424d1d08221dcc6",
"version": "1.36.1"
"revision": "21d99b0c66cf86867a779bac831d800aac22f5e6",
"version": "1.41.0"
}
},
{
Expand All @@ -69,8 +69,8 @@
"repositoryURL": "https://github.com/vapor/sql-kit.git",
"state": {
"branch": null,
"revision": "d2027b4b81a19d2ac7bd01936e7a778d7f0afa02",
"version": "3.15.0"
"revision": "fcc29f543b3de7b661cbe7540805974234cb9740",
"version": "3.24.0"
}
},
{
Expand Down Expand Up @@ -123,8 +123,8 @@
"repositoryURL": "https://github.com/apple/swift-log.git",
"state": {
"branch": null,
"revision": "5d66f7ba25daf4f94100e7022febf3c75e37a6c7",
"version": "1.4.2"
"revision": "32e8d724467f8fe623624570367e3d50c5638e46",
"version": "1.5.2"
}
},
{
Expand Down Expand Up @@ -195,8 +195,8 @@
"repositoryURL": "https://github.com/vapor/vapor.git",
"state": {
"branch": null,
"revision": "7b76fe01a8eb02aa7f61d9ca10624f98b25a5735",
"version": "4.69.2"
"revision": "9a340de4995e5a9dade4ff4c51cd2e6ae30c12d6",
"version": "4.77.0"
}
},
{
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ let package = Package(
],
dependencies: [
// Dependencies declare other packages that this package depends on.
.package(url: "https://github.com/vapor/vapor.git", from: "4.76.2"),
.package(url: "https://github.com/vapor/vapor.git", from: "4.77.0"),
.package(url: "https://github.com/vapor/fluent.git", from: "4.8.0")
],
targets: [
Expand Down
18 changes: 17 additions & 1 deletion Sources/YData/Core/Configuration/Configuration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,32 @@ public protocol Configuration {
associatedtype Error: ConfigurationError

static func loadFromEnvironment() -> Result<Self, Error>

static func loadFromEnvironment() throws -> Self

static func loadFromEnvironment<C: Context>(context: C) -> Result<Self, Error>
static func loadFromEnvironment<C: Context>(context: C) throws -> Self
}

public extension Configuration {
static func loadFromEnvironment() -> Result<Self, Error> {
return .failure(NotImplementedError() as! Self.Error)
}

static func loadFromEnvironment() throws -> Self {
let result: Result<Self, Error> = loadFromEnvironment()
switch result {
case .success(let success): return success
case .failure(let error): throw error
}
}

static func loadFromEnvironment<C: Context>(context: C) -> Result<Self, Error> {
loadFromEnvironment()
}

static func loadFromEnvironment<C: Context>(context: C) throws -> Self {
try loadFromEnvironment()
}
}

public struct NotImplementedError: ConfigurationError {}
3 changes: 3 additions & 0 deletions Sources/YData/Core/Context/Context.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import Foundation

public protocol Context {}
2 changes: 1 addition & 1 deletion Sources/YData/Core/Context/EventLoopContext.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Foundation
import protocol NIO.EventLoop

public protocol EventLoopContext {
public protocol EventLoopContext: Context {
var eventLoop: EventLoop { get }
}
2 changes: 1 addition & 1 deletion Sources/YData/Core/Context/LoggerContext.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Foundation
import Vapor

public protocol LoggerContext {
public protocol LoggerContext: Context {
var logger: Logger { get }
}

0 comments on commit 89d2105

Please sign in to comment.