Skip to content

threeplay/TPFeatureTag

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TPFeatureTag

CI Status Version License Platform

Simple feature tags managment for swift projects

Usage

Define your feature tags

// Subclass FeatureTags to get automatic feature registration
class Features: FeatureTags {
  let feature1 = makeFeature()
  let feature2 = makeFeature(key: "remote_feature1", enabled: true)
}

// Singleton instance for features 
let features = Features()

Check if a feature is enabled or not

...
  if features.feature1.isOn {
      // Code to execute if feature is enabled
  } else {
      // Code to execute if feature is disabled
  }
...

Install resolver(s)

...
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
  ...
  FeatureTags.Manager.install(name: 'local', priority: 10, resolver: FeatureTags.Resolvers.Local(namespace: 'featuretags'))
  ...
}

Update feature tags state in a specific resolver

// Set a value if resolver supports it (ignored if setting is not supported)
FeatureTags.Manager.instance.set(features.feature1, to: true, in: 'local')

// Remove a value and allow an higher priority resolver to resolve a value
FeatureTags.Manager.instance.remove(features.feature1, from: 'local')

Update feature tags state for all resolvers

// Set a value if resolver supports it (ignored if setting is not supported)
FeatureTags.Manager.instance.set(features.feature1, to: true)

// Remove a value and allow an higher priority resolver to resolve a value
FeatureTags.Manager.instance.remove(features.feature1)

Get a list of registered feature tags

let allFeatures = FeatureTags.Manager.instance.allFeatures

Each feature returned contains:

  • name generated by reflection from the variable name
  • namespace generated by reflection from the containing class
  • key assigned by makeFeature
  • isOn current resolved state of the feature from the highest priority resolver that returned a value to that feature tag
  • source the resolver's name that returned the value default if no resolver returns a value and using the makeFeature default

Installation

TPFeatureTag is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'TPFeatureTag'

Author

Eliran Ben-Ezra, eliran@threeplay.com

License

TPFeatureTag is available under the MIT license. See the LICENSE file for more info.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published