Skip to content

Commit

Permalink
v2.2.0 (#73)
Browse files Browse the repository at this point in the history
* [#69] Implemented a protocol-based initializer in `FeatureFlagResolver` (#70)
* [#68] Added support for mutable `stores` in resolver configuration via a new implementation, `MutableFeatureFlagResolverConfiguration` (#72)
  • Loading branch information
yakovmanshin authored May 20, 2021
2 parents cb10623 + 2f66204 commit 0f5d00b
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: Lint Podspec
run: pod lib lint --verbose
run: pod lib lint --allow-warnings --verbose
1 change: 1 addition & 0 deletions .jazzy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ custom_categories:
- FeatureFlagResolver
- FeatureFlagResolverError
- FeatureFlagResolverConfiguration
- MutableFeatureFlagResolverConfiguration
- TransparentFeatureFlagStore
- RuntimeOverridesStore
- UserDefaultsStore
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//
// MutableFeatureFlagResolverConfiguration.swift
// YMFF
//
// Created by Yakov Manshin on 5/17/21.
// Copyright © 2021 Yakov Manshin. See the LICENSE file for license info.
//

#if !COCOAPODS
import YMFFProtocols
#endif

// MARK: - MutableFeatureFlagResolverConfiguration

/// An object used to configure the resolver, which holds feature flag stores that can be changed.
final public class MutableFeatureFlagResolverConfiguration {

public var stores: [FeatureFlagStore]

public init(stores: [FeatureFlagStore]) {
self.stores = stores
}

}

// MARK: - FeatureFlagResolverConfigurationProtocol

extension MutableFeatureFlagResolverConfiguration: FeatureFlagResolverConfigurationProtocol { }
19 changes: 18 additions & 1 deletion Sources/YMFF/FeatureFlagResolver/FeatureFlagResolver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,27 @@ final public class FeatureFlagResolver {

// MARK: Initializers

public init(configuration: FeatureFlagResolverConfiguration) {
/// Initializes the resolver with an object that conforms to `FeatureFlagResolverConfigurationProtocol`.
///
/// - Parameter configuration: *Required.* The configuration used to read and write feature flag values.
public init(configuration: FeatureFlagResolverConfigurationProtocol) {
self.configuration = configuration
}

@available(*, deprecated, message: "Use init(stores:)")
public convenience init(configuration: FeatureFlagResolverConfiguration) {
self.init(configuration: configuration as FeatureFlagResolverConfigurationProtocol)
}

/// Initializes the resolver with the list of feature flag stores.
///
/// + Passing in an empty array will produce the `noStoreAvailable` error on next read attempt.
///
/// - Parameter stores: *Required.* The array of feature flag stores.
public convenience init(stores: [FeatureFlagStore]) {
self.init(configuration: FeatureFlagResolverConfiguration(stores: stores))
}

deinit {
configuration.stores
.compactMap({ $0.asMutable })
Expand Down
35 changes: 35 additions & 0 deletions Tests/YMFFTests/FeatureFlagResolverConfigurationTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//
// FeatureFlagResolverConfigurationTests.swift
// YMFF
//
// Created by Yakov Manshin on 5/17/21.
// Copyright © 2021 Yakov Manshin. See the LICENSE file for license info.
//

import XCTest

@testable import YMFF

final class FeatureFlagResolverConfigurationTests: XCTestCase {

func testStoreAdditionToMutableConfiguration() {
let configuration = MutableFeatureFlagResolverConfiguration(stores: [])

XCTAssertEqual(configuration.stores.count, 0)

configuration.stores.append(.immutable(TransparentFeatureFlagStore()))

XCTAssertEqual(configuration.stores.count, 1)
}

func testStoreRemovalFromMutableConfiguration() {
let configuration = MutableFeatureFlagResolverConfiguration(stores: [.immutable(TransparentFeatureFlagStore())])

XCTAssertEqual(configuration.stores.count, 1)

configuration.stores.removeAll()

XCTAssertEqual(configuration.stores.count, 0)
}

}
2 changes: 1 addition & 1 deletion Tests/YMFFTests/MutableStoreTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ final class MutableStoreTests: XCTestCase {
mutableStore = MutableFeatureFlagStore(store: .init()) {
saveChangesCount += 1
}
resolver = FeatureFlagResolver(configuration: .init(stores: [.mutable(mutableStore)]))
resolver = FeatureFlagResolver(stores: [.mutable(mutableStore)])

resolver = nil

Expand Down
4 changes: 2 additions & 2 deletions Tests/YMFFTests/UserDefaultsStoreTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ final class UserDefaultsStoreTests: XCTestCase {
override func setUp() {
super.setUp()

resolver = FeatureFlagResolver(configuration: .init(stores: [
resolver = FeatureFlagResolver(stores: [
.mutable(UserDefaultsStore(userDefaults: userDefaults))
]))
])
}

}
Expand Down
2 changes: 1 addition & 1 deletion YMFF.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Pod::Spec.new do |s|
# Basic Info

s.name = "YMFF"
s.version = "2.1.0"
s.version = "2.2.0"
s.summary = "Feature management made easy."

s.description = <<-DESC
Expand Down

0 comments on commit 0f5d00b

Please sign in to comment.