Skip to content
This repository has been archived by the owner on Sep 7, 2021. It is now read-only.

Provide a functional default implementation of register in Endpoints #8

Merged
merged 3 commits into from
Apr 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions Sources/Corvus/Endpoints/CRUD.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,4 @@ public final class CRUD<T: CorvusModel>: Endpoint {
}
}
}

/// A method that invokes the `register` function for the component's
/// `content`.
///
/// - Parameter routes: A `RoutesBuilder` containing all the information
/// about the HTTP route leading to the current component.
public func register(to routes: RoutesBuilder) {
content.register(to: routes)
}
}
7 changes: 6 additions & 1 deletion Sources/Corvus/Endpoints/Utilities/EmptyEndpoint.swift
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
import Vapor

/// An empty default value when no `Endpoint` value is needed.
public struct EmptyEndpoint: Endpoint {}
public struct EmptyEndpoint: Endpoint {
/// An empty default implementation of `.register()` to avoid endless loops when registering `EmptyEndpoint`s
public func register(to routes: RoutesBuilder) { }
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ extension EventLoopFuture where Value: Sequence {
func mapEachThrowing<Result>(
_ transform: @escaping (_ element: Value.Element) throws -> Result
) -> EventLoopFuture<[Result]> {
return self.flatMapThrowing { sequence -> [Result] in
self.flatMapThrowing { sequence in
try sequence.map(transform)
}
}
Expand Down
7 changes: 4 additions & 3 deletions Sources/Corvus/Protocols/Endpoints/Endpoint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ extension Endpoint {
/// do not need to be registered.
extension Endpoint {

/// An empty default implementation of `.register()` for components that do
/// not need it.
public func register(to routes: RoutesBuilder) {}
/// A default implementation of `.register()` for components that do not need special behaviour.
public func register(to routes: RoutesBuilder) {
content.register(to: routes)
}
}

/// An extension to make an `Array` of `Endpoint` conform to `Endpoint` and thus
Expand Down