Slather logo

Coverage for "InlineFactory.swift" : 100.00%

(11 of 11 relevant lines covered)

RouteComposer/Classes/Extra/InlineFactory.swift

1
//
2
// RouteComposer
3
// InlineFactory.swift
4
// https://github.com/ekazaev/route-composer
5
//
6
// Created by Eugene Kazaev in 2018-2022.
7
// Distributed under the MIT license.
8
//
9
// Become a sponsor:
10
// https://github.com/sponsors/ekazaev
11
//
12
13
import UIKit
14
15
/// `InlineFactory`. Might be useful for the configuration testing.
16
public struct InlineFactory<VC: UIViewController, C>: Factory {
17
18
    // MARK: Associated types
19
20
    /// Type of `UIViewController` that `Factory` can build
21
    public typealias ViewController = VC
22
23
    /// `Context` to be passed into `UIViewController`
24
    public typealias Context = C
25
26
    // MARK: Properties
27
28
    let inlineBock: (C) throws -> VC
29
30
    // MARK: Functions
31
32
    /// Constructor
33
    /// - Parameter inlineBock: the block to be called when `InlineFactory.build(...)` is requested.
34
    public init(viewController inlineBock: @autoclosure @escaping () throws -> VC) {
1x
35
        self.inlineBock = { _ in
1x
36
            try inlineBock()
1x
37
        }
1x
38
    }
1x
39
40
    /// Constructor
41
    /// - Parameter inlineBock: the block to be called when `InlineFactory.build(...)` is requested.
42
    public init(_ inlineBock: @escaping (C) throws -> VC) {
1x
43
        self.inlineBock = inlineBock
1x
44
    }
1x
45
46
    public func build(with context: C) throws -> VC {
2x
47
        return try inlineBock(context)
2x
48
    }
2x
49
50
}