Slather logo

Coverage for "ContainerStepChainAssembly.swift" : 100.00%

(16 of 16 relevant lines covered)

RouteComposer/Classes/Assemblies/Helpers/ContainerStepChainAssembly.swift

1
//
2
// RouteComposer
3
// ContainerStepChainAssembly.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 Foundation
14
import UIKit
15
16
/// Helper class to build a chain of steps. Can not be used directly.
17
public struct ContainerStepChainAssembly<AcceptableContainer: ContainerViewController, ViewController: UIViewController, Context> {
18
19
    // MARK: Properties
20
21
    let previousSteps: [RoutingStep]
22
23
    // MARK: Methods
24
25
    init(previousSteps: [RoutingStep]) {
67x
26
        self.previousSteps = previousSteps
67x
27
    }
67x
28
29
    /// Adds a single step to the chain
30
    ///
31
    /// - Parameter previousStep: The instance of `StepWithActionAssemblable`
32
    public func from(_ step: ActionToStepIntegrator<AcceptableContainer, Context>) -> ActionConnectingAssembly<ViewController, Context> {
34x
33
        ActionConnectingAssembly<ViewController, Context>(stepToFullFill: step, previousSteps: previousSteps)
34x
34
    }
34x
35
36
    /// Adds a `DestinationStep` to the chain. This step will be the last one in the chain.
37
    ///
38
    /// - Parameter previousStep: The instance of `DestinationStep`
39
    public func from(_ step: DestinationStep<AcceptableContainer, Context>) -> LastStepInChainAssembly<ViewController, Context> {
32x
40
        var previousSteps = previousSteps
32x
41
        previousSteps.append(step)
32x
42
        return LastStepInChainAssembly(previousSteps: previousSteps)
32x
43
    }
32x
44
45
    /// Assembles all the provided settings.
46
    ///
47
    /// - Parameter step: An instance of `DestinationStep` to build a current stack from.
48
    /// - Returns: An instance of `DestinationStep` with all the provided settings inside.
49
    public func assemble(from step: DestinationStep<AcceptableContainer, Context>) -> DestinationStep<ViewController, Context> {
1x
50
        var previousSteps = previousSteps
1x
51
        previousSteps.append(step)
1x
52
        return LastStepInChainAssembly(previousSteps: previousSteps).assemble()
1x
53
    }
1x
54
55
}