Skip to content

Commit

Permalink
Fix swiftlint
Browse files Browse the repository at this point in the history
  • Loading branch information
Supereg committed Jul 20, 2023
1 parent feb67f8 commit b7510c3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
25 changes: 21 additions & 4 deletions Sources/Spezi/SharedRepository/SharedRepository.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,26 +68,41 @@ public protocol SharedRepository<Anchor> {
/// - Returns: The stored ``KnowledgeSource/Value`` or the ``DefaultProvidingKnowledgeSource/defaultValue``.
subscript<Source: DefaultProvidingKnowledgeSource<Anchor>>(_ source: Source.Type) -> Source.Value { get }

/// A subscript to retrieve or set a ``ComputedKnowledgeSource``.
/// A subscript to retrieve a ``ComputedKnowledgeSource``.
///
/// - Note: If the value was not present and got computed, the computed value will be stored in the repository.
/// - Note: This is the implementation for the ``ComputedKnowledgeSource/Store`` policy.
/// If the value was not present and got computed, the computed value will be stored in the repository.
/// - Parameter source: The ``ComputedKnowledgeSource`` type.
/// - Returns: The stored ``KnowledgeSource/Value`` or calls ``ComputedKnowledgeSource/compute(from:)`` to compute the value.
subscript<Source: ComputedKnowledgeSource<Anchor>>(_ source: Source.Type)
-> Source.Value where Source.StoragePolicy == _StoreComputePolicy { mutating get }

/// A subscript to retrieve a ``ComputedKnowledgeSource``.
///
/// - Note: This is the implementation for the ``ComputedKnowledgeSource/AlwaysCompute`` policy.
/// The ``ComputedKnowledgeSource/compute(from:)`` method will always be called as a result of this subscript call.
/// - Parameter source: The ``ComputedKnowledgeSource`` type.
/// - Returns: The calls ``ComputedKnowledgeSource/compute(from:)`` to compute the value.
subscript<Source: ComputedKnowledgeSource<Anchor>>(_ source: Source.Type)
-> Source.Value where Source.StoragePolicy == _AlwaysComputePolicy { get }

/// A subscript to retrieve or set a ``OptionalComputedKnowledgeSource``.
/// A subscript to retrieve a ``OptionalComputedKnowledgeSource``.
///
/// - Note: If the value was not present and got computed, the computed value will be stored in the repository.
/// - Note: This is the implementation for the ``OptionalComputedKnowledgeSource/Store`` policy.
/// If the value was not present and got computed, the computed value will be stored in the repository.
/// - Parameter source: The ``OptionalComputedKnowledgeSource`` type.
/// - Returns: The stored ``KnowledgeSource/Value`` or calls ``OptionalComputedKnowledgeSource/compute(from:)`` to compute the value
/// or `nil` if the `compute` method returned nil.
subscript<Source: OptionalComputedKnowledgeSource<Anchor>>(_ source: Source.Type)
-> Source.Value? where Source.StoragePolicy == _StoreComputePolicy { mutating get }

/// A subscript to retrieve a ``OptionalComputedKnowledgeSource``.
///
/// - Note: This is the implementation for the ``OptionalComputedKnowledgeSource/AlwaysCompute`` policy.
/// The ``OptionalComputedKnowledgeSource/compute(from:)`` method will always be called as a result of this subscript call.
/// - Parameter source: The ``OptionalComputedKnowledgeSource`` type.
/// - Returns: The calls ``OptionalComputedKnowledgeSource/compute(from:)`` to compute the value
/// or `nil` if the `compute` method returned nil.
subscript<Source: OptionalComputedKnowledgeSource<Anchor>>(_ source: Source.Type)
-> Source.Value? where Source.StoragePolicy == _AlwaysComputePolicy { get }
}
Expand Down Expand Up @@ -129,6 +144,7 @@ extension SharedRepository {
}
}

/// Default subscript implementation delegating calling ``ComputedKnowledgeSource/compute(from:)``.
public subscript<Source: ComputedKnowledgeSource<Anchor>>(_ source: Source.Type)
-> Source.Value where Source.StoragePolicy == _AlwaysComputePolicy {
source.compute(from: self)
Expand All @@ -149,6 +165,7 @@ extension SharedRepository {
}
}

/// Default subscript implementation delegating calling ``OptionalComputedKnowledgeSource/compute(from:)``.
public subscript<Source: OptionalComputedKnowledgeSource<Anchor>>(_ source: Source.Type)
-> Source.Value? where Source.StoragePolicy == _AlwaysComputePolicy {
source.compute(from: self)
Expand Down
3 changes: 2 additions & 1 deletion Tests/SpeziTests/HelperTests/SharedRepositoryTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -254,10 +254,11 @@ final class SharedRepositoryTests: XCTestCase {
}
}

private var repos: [AnyTestInstance] = []
static var computedValue: Int = 3
static var optionalComputedValue: Int?

private var repos: [AnyTestInstance] = []

override func setUp() {
repos = [TestInstance(HeapRepository<TestAnchor>()), TestInstance(ValueRepository<TestAnchor>())]
Self.computedValue = 3
Expand Down

0 comments on commit b7510c3

Please sign in to comment.