Skip to content

Commit 39ceaaa

Browse files
committed
🧹 Use self.init for similar initializers.
1 parent ac7d1cb commit 39ceaaa

File tree

8 files changed

+73
-75
lines changed

8 files changed

+73
-75
lines changed

‎Sources/VaporRouteBuilder/RouteComponents/Groups/Group+Middleware.swift‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ extension Group {
4343
middleware: any Vapor.Middleware...,
4444
@RouteBuilder content: () -> Content
4545
) where Middlewares == [any Vapor.Middleware] {
46-
self.middleware = middleware
47-
self.content = content()
46+
self.init(middleware: middleware, content: content)
4847
}
4948

5049
@inlinable

‎Sources/VaporRouteBuilder/RouteComponents/Groups/Group+Path.swift‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ extension Group {
4343
path: PathComponent...,
4444
@RouteBuilder content: () -> Content
4545
) where Path == [PathComponent] {
46-
self.path = path
47-
self.content = content()
46+
self.init(path: path, content: content)
4847
}
4948

5049
@inlinable

‎Sources/VaporRouteBuilder/RouteComponents/Groups/Group.swift‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public struct Group<Content: RouteComponent>: RouteComponent {
9393
path: PathComponent...,
9494
@RouteBuilder content: () -> C
9595
) where Content == Group<C>.Path<[PathComponent]> {
96-
self.content = Content(path: path, content: content)
96+
self.init(path: path, content: content)
9797
}
9898

9999
/// Creates a group, nesting the provided `content` underneath the provided `path`.
@@ -146,7 +146,7 @@ public struct Group<Content: RouteComponent>: RouteComponent {
146146
middleware: any Vapor.Middleware...,
147147
@RouteBuilder content: () -> C
148148
) where Content == Group<C>.Middleware<[any Vapor.Middleware]> {
149-
self.content = Content(middleware: middleware, content: content)
149+
self.init(middleware: middleware, content: content)
150150
}
151151

152152
/// Creates a group, nested the provided `content` underneath the provided `middleware`.

‎Sources/VaporRouteBuilder/RouteComponents/HTTPMethods/DELETE.swift‎

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ public struct DELETE: RouteComponent {
4343
/// - strategy: The body streaming strategy.
4444
/// - use: The closure handler for incoming requests.
4545
@inlinable
46-
public init<Path: Collection, Response: ResponseEncodable>(
47-
_ path: Path,
46+
public init<Response: ResponseEncodable>(
47+
_ path: PathComponent...,
4848
strategy: HTTPBodyStreamStrategy = .collect,
4949
use: @Sendable @escaping (Request) throws -> Response
50-
) where Path.Element == PathComponent {
51-
self.route = Route(.DELETE, path, body: strategy, use: use)
50+
) {
51+
self.init(path, strategy: strategy, use: use)
5252
}
5353

5454
/// Creates a `Route` with the `DELETE` HTTP Method at the provided path.
@@ -58,12 +58,12 @@ public struct DELETE: RouteComponent {
5858
/// - strategy: The body streaming strategy.
5959
/// - use: The closure handler for incoming requests.
6060
@inlinable
61-
public init<Path: Collection, Response: AsyncResponseEncodable>(
62-
_ path: Path,
61+
public init<Response: AsyncResponseEncodable>(
62+
_ path: PathComponent...,
6363
strategy: HTTPBodyStreamStrategy = .collect,
6464
use: @Sendable @escaping (Request) async throws -> Response
65-
) where Path.Element == PathComponent {
66-
self.route = Route(.DELETE, path, body: strategy, use: use)
65+
) {
66+
self.init(path, strategy: strategy, use: use)
6767
}
6868

6969
/// Creates a `Route` with the `DELETE` HTTP Method at the provided path.
@@ -73,11 +73,11 @@ public struct DELETE: RouteComponent {
7373
/// - strategy: The body streaming strategy.
7474
/// - use: The closure handler for incoming requests.
7575
@inlinable
76-
public init<Response: ResponseEncodable>(
77-
_ path: PathComponent...,
76+
public init<Path: Collection, Response: ResponseEncodable>(
77+
_ path: Path,
7878
strategy: HTTPBodyStreamStrategy = .collect,
7979
use: @Sendable @escaping (Request) throws -> Response
80-
) {
80+
) where Path.Element == PathComponent {
8181
self.route = Route(.DELETE, path, body: strategy, use: use)
8282
}
8383

@@ -88,11 +88,11 @@ public struct DELETE: RouteComponent {
8888
/// - strategy: The body streaming strategy.
8989
/// - use: The closure handler for incoming requests.
9090
@inlinable
91-
public init<Response: AsyncResponseEncodable>(
92-
_ path: PathComponent...,
91+
public init<Path: Collection, Response: AsyncResponseEncodable>(
92+
_ path: Path,
9393
strategy: HTTPBodyStreamStrategy = .collect,
9494
use: @Sendable @escaping (Request) async throws -> Response
95-
) {
95+
) where Path.Element == PathComponent {
9696
self.route = Route(.DELETE, path, body: strategy, use: use)
9797
}
9898

‎Sources/VaporRouteBuilder/RouteComponents/HTTPMethods/GET.swift‎

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ public struct GET: RouteComponent {
4343
/// - strategy: The body streaming strategy.
4444
/// - use: The closure handler for incoming requests.
4545
@inlinable
46-
public init<Path: Collection, Response: ResponseEncodable>(
47-
_ path: Path,
46+
public init<Response: ResponseEncodable>(
47+
_ path: PathComponent...,
4848
strategy: HTTPBodyStreamStrategy = .collect,
4949
use: @Sendable @escaping (Request) throws -> Response
50-
) where Path.Element == PathComponent {
51-
self.route = Route(.GET, path, body: strategy, use: use)
50+
) {
51+
self.init(path, strategy: strategy, use: use)
5252
}
5353

5454
/// Creates a `Route` with the `GET` HTTP Method at the provided path.
@@ -58,12 +58,12 @@ public struct GET: RouteComponent {
5858
/// - strategy: The body streaming strategy.
5959
/// - use: The closure handler for incoming requests.
6060
@inlinable
61-
public init<Path: Collection, Response: AsyncResponseEncodable>(
62-
_ path: Path,
61+
public init<Response: AsyncResponseEncodable>(
62+
_ path: PathComponent...,
6363
strategy: HTTPBodyStreamStrategy = .collect,
6464
use: @Sendable @escaping (Request) async throws -> Response
65-
) where Path.Element == PathComponent {
66-
self.route = Route(.GET, path, body: strategy, use: use)
65+
) {
66+
self.init(path, strategy: strategy, use: use)
6767
}
6868

6969
/// Creates a `Route` with the `GET` HTTP Method at the provided path.
@@ -73,11 +73,11 @@ public struct GET: RouteComponent {
7373
/// - strategy: The body streaming strategy.
7474
/// - use: The closure handler for incoming requests.
7575
@inlinable
76-
public init<Response: ResponseEncodable>(
77-
_ path: PathComponent...,
76+
public init<Path: Collection, Response: ResponseEncodable>(
77+
_ path: Path,
7878
strategy: HTTPBodyStreamStrategy = .collect,
7979
use: @Sendable @escaping (Request) throws -> Response
80-
) {
80+
) where Path.Element == PathComponent {
8181
self.route = Route(.GET, path, body: strategy, use: use)
8282
}
8383

@@ -88,11 +88,11 @@ public struct GET: RouteComponent {
8888
/// - strategy: The body streaming strategy.
8989
/// - use: The closure handler for incoming requests.
9090
@inlinable
91-
public init<Response: AsyncResponseEncodable>(
92-
_ path: PathComponent...,
91+
public init<Path: Collection, Response: AsyncResponseEncodable>(
92+
_ path: Path,
9393
strategy: HTTPBodyStreamStrategy = .collect,
9494
use: @Sendable @escaping (Request) async throws -> Response
95-
) {
95+
) where Path.Element == PathComponent {
9696
self.route = Route(.GET, path, body: strategy, use: use)
9797
}
9898

‎Sources/VaporRouteBuilder/RouteComponents/HTTPMethods/PATCH.swift‎

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ public struct PATCH: RouteComponent {
4343
/// - strategy: The body streaming strategy.
4444
/// - use: The closure handler for incoming requests.
4545
@inlinable
46-
public init<Path: Collection, Response: ResponseEncodable>(
47-
_ path: Path,
46+
public init<Response: ResponseEncodable>(
47+
_ path: PathComponent...,
4848
strategy: HTTPBodyStreamStrategy = .collect,
4949
use: @Sendable @escaping (Request) throws -> Response
50-
) where Path.Element == PathComponent {
51-
self.route = Route(.PATCH, path, body: strategy, use: use)
50+
) {
51+
self.init(path, strategy: strategy, use: use)
5252
}
5353

5454
/// Creates a `Route` with the `PATCH` HTTP Method at the provided path.
@@ -58,12 +58,12 @@ public struct PATCH: RouteComponent {
5858
/// - strategy: The body streaming strategy.
5959
/// - use: The closure handler for incoming requests.
6060
@inlinable
61-
public init<Path: Collection, Response: AsyncResponseEncodable>(
62-
_ path: Path,
61+
public init<Response: AsyncResponseEncodable>(
62+
_ path: PathComponent...,
6363
strategy: HTTPBodyStreamStrategy = .collect,
6464
use: @Sendable @escaping (Request) async throws -> Response
65-
) where Path.Element == PathComponent {
66-
self.route = Route(.PATCH, path, body: strategy, use: use)
65+
) {
66+
self.init(path, strategy: strategy, use: use)
6767
}
6868

6969
/// Creates a `Route` with the `PATCH` HTTP Method at the provided path.
@@ -73,11 +73,11 @@ public struct PATCH: RouteComponent {
7373
/// - strategy: The body streaming strategy.
7474
/// - use: The closure handler for incoming requests.
7575
@inlinable
76-
public init<Response: ResponseEncodable>(
77-
_ path: PathComponent...,
76+
public init<Path: Collection, Response: ResponseEncodable>(
77+
_ path: Path,
7878
strategy: HTTPBodyStreamStrategy = .collect,
7979
use: @Sendable @escaping (Request) throws -> Response
80-
) {
80+
) where Path.Element == PathComponent {
8181
self.route = Route(.PATCH, path, body: strategy, use: use)
8282
}
8383

@@ -88,11 +88,11 @@ public struct PATCH: RouteComponent {
8888
/// - strategy: The body streaming strategy.
8989
/// - use: The closure handler for incoming requests.
9090
@inlinable
91-
public init<Response: AsyncResponseEncodable>(
92-
_ path: PathComponent...,
91+
public init<Path: Collection, Response: AsyncResponseEncodable>(
92+
_ path: Path,
9393
strategy: HTTPBodyStreamStrategy = .collect,
9494
use: @Sendable @escaping (Request) async throws -> Response
95-
) {
95+
) where Path.Element == PathComponent {
9696
self.route = Route(.PATCH, path, body: strategy, use: use)
9797
}
9898

‎Sources/VaporRouteBuilder/RouteComponents/HTTPMethods/POST.swift‎

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ public struct POST: RouteComponent {
4343
/// - strategy: The body streaming strategy.
4444
/// - use: The closure handler for incoming requests.
4545
@inlinable
46-
public init<Path: Collection, Response: ResponseEncodable>(
47-
_ path: Path,
46+
public init<Response: ResponseEncodable>(
47+
_ path: PathComponent...,
4848
strategy: HTTPBodyStreamStrategy = .collect,
4949
use: @Sendable @escaping (Request) throws -> Response
50-
) where Path.Element == PathComponent {
51-
self.route = Route(.POST, path, body: strategy, use: use)
50+
) {
51+
self.init(path, strategy: strategy, use: use)
5252
}
5353

5454
/// Creates a `Route` with the `POST` HTTP Method at the provided path.
@@ -58,12 +58,12 @@ public struct POST: RouteComponent {
5858
/// - strategy: The body streaming strategy.
5959
/// - use: The closure handler for incoming requests.
6060
@inlinable
61-
public init<Path: Collection, Response: AsyncResponseEncodable>(
62-
_ path: Path,
61+
public init<Response: AsyncResponseEncodable>(
62+
_ path: PathComponent...,
6363
strategy: HTTPBodyStreamStrategy = .collect,
6464
use: @Sendable @escaping (Request) async throws -> Response
65-
) where Path.Element == PathComponent {
66-
self.route = Route(.POST, path, body: strategy, use: use)
65+
) {
66+
self.init(path, strategy: strategy, use: use)
6767
}
6868

6969
/// Creates a `Route` with the `POST` HTTP Method at the provided path.
@@ -73,11 +73,11 @@ public struct POST: RouteComponent {
7373
/// - strategy: The body streaming strategy.
7474
/// - use: The closure handler for incoming requests.
7575
@inlinable
76-
public init<Response: ResponseEncodable>(
77-
_ path: PathComponent...,
76+
public init<Path: Collection, Response: ResponseEncodable>(
77+
_ path: Path,
7878
strategy: HTTPBodyStreamStrategy = .collect,
7979
use: @Sendable @escaping (Request) throws -> Response
80-
) {
80+
) where Path.Element == PathComponent {
8181
self.route = Route(.POST, path, body: strategy, use: use)
8282
}
8383

@@ -88,11 +88,11 @@ public struct POST: RouteComponent {
8888
/// - strategy: The body streaming strategy.
8989
/// - use: The closure handler for incoming requests.
9090
@inlinable
91-
public init<Response: AsyncResponseEncodable>(
92-
_ path: PathComponent...,
91+
public init<Path: Collection, Response: AsyncResponseEncodable>(
92+
_ path: Path,
9393
strategy: HTTPBodyStreamStrategy = .collect,
9494
use: @Sendable @escaping (Request) async throws -> Response
95-
) {
95+
) where Path.Element == PathComponent {
9696
self.route = Route(.POST, path, body: strategy, use: use)
9797
}
9898

‎Sources/VaporRouteBuilder/RouteComponents/HTTPMethods/PUT.swift‎

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ public struct PUT: RouteComponent {
4343
/// - strategy: The body streaming strategy.
4444
/// - use: The closure handler for incoming requests.
4545
@inlinable
46-
public init<Path: Collection, Response: ResponseEncodable>(
47-
_ path: Path,
46+
public init<Response: ResponseEncodable>(
47+
_ path: PathComponent...,
4848
strategy: HTTPBodyStreamStrategy = .collect,
4949
use: @Sendable @escaping (Request) throws -> Response
50-
) where Path.Element == PathComponent {
50+
) {
5151
self.route = Route(.PUT, path, body: strategy, use: use)
5252
}
5353

@@ -58,12 +58,12 @@ public struct PUT: RouteComponent {
5858
/// - strategy: The body streaming strategy.
5959
/// - use: The closure handler for incoming requests.
6060
@inlinable
61-
public init<Path: Collection, Response: AsyncResponseEncodable>(
62-
_ path: Path,
61+
public init<Response: AsyncResponseEncodable>(
62+
_ path: PathComponent...,
6363
strategy: HTTPBodyStreamStrategy = .collect,
6464
use: @Sendable @escaping (Request) async throws -> Response
65-
) where Path.Element == PathComponent {
66-
self.route = Route(.PUT, path, body: strategy, use: use)
65+
) {
66+
self.init(path, strategy: strategy, use: use)
6767
}
6868

6969
/// Creates a `Route` with the `PUT` HTTP Method at the provided path.
@@ -73,11 +73,11 @@ public struct PUT: RouteComponent {
7373
/// - strategy: The body streaming strategy.
7474
/// - use: The closure handler for incoming requests.
7575
@inlinable
76-
public init<Response: ResponseEncodable>(
77-
_ path: PathComponent...,
76+
public init<Path: Collection, Response: ResponseEncodable>(
77+
_ path: Path,
7878
strategy: HTTPBodyStreamStrategy = .collect,
7979
use: @Sendable @escaping (Request) throws -> Response
80-
) {
80+
) where Path.Element == PathComponent {
8181
self.route = Route(.PUT, path, body: strategy, use: use)
8282
}
8383

@@ -88,11 +88,11 @@ public struct PUT: RouteComponent {
8888
/// - strategy: The body streaming strategy.
8989
/// - use: The closure handler for incoming requests.
9090
@inlinable
91-
public init<Response: AsyncResponseEncodable>(
92-
_ path: PathComponent...,
91+
public init<Path: Collection, Response: AsyncResponseEncodable>(
92+
_ path: Path,
9393
strategy: HTTPBodyStreamStrategy = .collect,
9494
use: @Sendable @escaping (Request) async throws -> Response
95-
) {
95+
) where Path.Element == PathComponent {
9696
self.route = Route(.PUT, path, body: strategy, use: use)
9797
}
9898

0 commit comments

Comments
 (0)