Skip to content

Commit

Permalink
0.2.0 Documentation fixes (#5)
Browse files Browse the repository at this point in the history
- Add boolean for enabled, removing contract extension. This is in favor
of java users, since kotlin ones already have sealed-class usage +
reactive one. Still, kotlin ones can use the property altough they are
losing contract for type inference (not a big deal since the existence
of sealed classes + reactive ones)
- Add examples in all documentations
- Add invoke companion operator to create lambda inlined providers
- Remove both creational methods in favor of a single overloaded one
  • Loading branch information
saantiaguilera authored Feb 9, 2020
1 parent 3431659 commit 5a34e76
Show file tree
Hide file tree
Showing 14 changed files with 43 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ If all results are missing types, then the default feature value (missing) will

Example of a basic multi-prioritized group using static integers for priorities:

```
``` kotlin
// Simple wrapper class for creating providers with an int priority
class StaticPriorityProvider(
private val provider: FeatureFlagProvider,
Expand All @@ -32,16 +32,15 @@ class StaticPriorityComparator : Comparator<StaticPriority> {
}
}

// Usage:
// Usage with 2 providers (of course it can be N):
fun using() {
val provider = PriorityFeatureFlagProvider(
listOf(
StaticPriorityProvider(yourProviderOne, priorityProviderOne),
StaticPriorityProvider(yourProviderTwo, priorityProviderTwo)
/* ... */
),
StaticPriorityComparator()
}
),
StaticPriorityComparator()
)
}
```

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ If all results are missing types, then the default feature value (missing) will

Example of a basic multi-prioritized group using static integers for priorities:

```
``` kotlin
// Simple wrapper class for creating providers with an int priority
class StaticPriorityProvider(
private val provider: FeatureFlagProvider,
Expand All @@ -32,17 +32,16 @@ class StaticPriorityComparator : Comparator<StaticPriority> {
}
}

// Usage:
// Usage with 2 providers (of course it can be N):
fun using() {
val provider = PriorityFeatureFlagProvider(
listOf(
StaticPriorityProvider(yourProviderOne, priorityProviderOne),
StaticPriorityProvider(yourProviderTwo, priorityProviderTwo)
/* ... */
),
StaticPriorityComparator()
}
),
StaticPriorityComparator()
)
}
```

### Constructors
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Package com.saantiaguilera.featureflags.prioritized

Priority public API package. Elements that allow prioritized behaviours reside here

### Types

| Name | Summary |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ the state of a flag, it's ok.

Basic example

```
``` kotlin
val provider = FeatureFlagProvider { feature ->
// check if the feature is enabled or not.
}
Expand All @@ -21,7 +21,7 @@ val provider = FeatureFlagProvider { feature ->
If a provider doesn't have the requested feature, it should respond with a missing one using
[FeatureFlagResult.create](../-feature-flag-result/create.md) (specifying as a second parameter that it doesn't)

```
``` kotlin
val provider = FeatureFlagProvider { feature ->
if (!/* check feature existence */) {
// feature.value is the default provided value. We should also denote it doesn't exists.
Expand All @@ -30,6 +30,7 @@ val provider = FeatureFlagProvider { feature ->

// If the feature exists. return it from somewhere
return FeatureFlagResult.create(/* get if the feature is enabled / disabled */)
}
```

On a more complex situation, you can create multi-providers such as
Expand All @@ -42,7 +43,7 @@ that constructs with a "User" (or know how to retrieve it) and react from it.

Example:

```
``` kotlin
class UserBasedProvider(
private val userRepository: UserRepository,
private val flagsRepository: MyFlagsRepository
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
Constructs a provider for a lambda. This compact syntax is most useful for inline
providers.

```
``` kotlin
val provider = FeatureFlagProvider { feature: FeatureFlag ->
// Provide a result accordingly.
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ This definition is based on the [flag](https://golang.org/pkg/flag) package defi

Example:

```
``` kotlin
object PaymentsFeatureCatalog {
val enableVisaPayments = FeatureFlag(
"feature.payments.cards.visa",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ This definition is based on the [flag](https://golang.org/pkg/flag) package defi

Example:

```
``` kotlin
object PaymentsFeatureCatalog {
val enableVisaPayments = FeatureFlag(
"feature.payments.cards.visa",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Package com.saantiaguilera.featureflags

General public API package. All the core elements reside here

### Types

| Name | Summary |
Expand Down
4 changes: 2 additions & 2 deletions docs/0.x/feature-flags/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ A Feature Toggle (aka Feature Flags) Kotlin implementation

| Name | Summary |
|---|---|
| [com.saantiaguilera.featureflags](com.saantiaguilera.featureflags/index.md) | |
| [com.saantiaguilera.featureflags.prioritized](com.saantiaguilera.featureflags.prioritized/index.md) | |
| [com.saantiaguilera.featureflags](com.saantiaguilera.featureflags/index.md) | General public API package. All the core elements reside here |
| [com.saantiaguilera.featureflags.prioritized](com.saantiaguilera.featureflags.prioritized/index.md) | Priority public API package. Elements that allow prioritized behaviours reside here |

### Index

Expand Down
10 changes: 9 additions & 1 deletion feature-flags/Module.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# Module feature-flags

A Feature Toggle (aka Feature Flags) Kotlin implementation
A Feature Toggle (aka Feature Flags) Kotlin implementation

# Package com.saantiaguilera.featureflags

General public API package. All the core elements reside here

# Package com.saantiaguilera.featureflags.prioritized

Priority public API package. Elements that allow prioritized behaviours reside here
2 changes: 1 addition & 1 deletion feature-flags/publishing.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apply plugin: 'maven-publish'

group = 'com.saantiaguilera.featureflags'
version = '0.1.0'
version = '0.2.0'

ext {
bintrayRepo = 'maven'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import java.io.Serializable
* This definition is based on the [flag](https://golang.org/pkg/flag) package definition.
*
* Example:
* ```
* ```kotlin
* object PaymentsFeatureCatalog {
* val enableVisaPayments = FeatureFlag(
* "feature.payments.cards.visa",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ package com.saantiaguilera.featureflags
* the state of a flag, it's ok.
*
* Basic example
* ```
* ```kotlin
* val provider = FeatureFlagProvider { feature ->
* // check if the feature is enabled or not.
* }
Expand All @@ -17,7 +17,7 @@ package com.saantiaguilera.featureflags
* If a provider doesn't have the requested feature, it should respond with a missing one using
* [FeatureFlagResult.create] (specifying as a second parameter that it doesn't)
*
* ```
* ```kotlin
* val provider = FeatureFlagProvider { feature ->
* if (!/* check feature existence */) {
* // feature.value is the default provided value. We should also denote it doesn't exists.
Expand All @@ -26,6 +26,7 @@ package com.saantiaguilera.featureflags
*
* // If the feature exists. return it from somewhere
* return FeatureFlagResult.create(/* get if the feature is enabled / disabled */)
* }
* ```
*
* On a more complex situation, you can create multi-providers such as
Expand All @@ -37,7 +38,7 @@ package com.saantiaguilera.featureflags
* that constructs with a "User" (or know how to retrieve it) and react from it.
*
* Example:
* ```
* ```kotlin
* class UserBasedProvider(
* private val userRepository: UserRepository,
* private val flagsRepository: MyFlagsRepository
Expand Down Expand Up @@ -73,7 +74,7 @@ interface FeatureFlagProvider {
* Constructs a provider for a lambda. This compact syntax is most useful for inline
* providers.
*
* ```
* ```kotlin
* val provider = FeatureFlagProvider { feature: FeatureFlag ->
* // Provide a result accordingly.
* }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import com.saantiaguilera.featureflags.FeatureFlagResult
* If all results are missing types, then the default feature value (missing) will be returned.
*
* Example of a basic multi-prioritized group using static integers for priorities:
* ```
* ```kotlin
* // Simple wrapper class for creating providers with an int priority
* class StaticPriorityProvider(
* private val provider: FeatureFlagProvider,
Expand All @@ -32,17 +32,16 @@ import com.saantiaguilera.featureflags.FeatureFlagResult
* }
* }
*
* // Usage:
* // Usage with 2 providers (of course it can be N):
* fun using() {
* val provider = PriorityFeatureFlagProvider(
* listOf(
* StaticPriorityProvider(yourProviderOne, priorityProviderOne),
* StaticPriorityProvider(yourProviderTwo, priorityProviderTwo)
* /* ... */
* ),
* StaticPriorityComparator()
* }
* )
* )
* }
* ```
*/
class PriorityFeatureFlagProvider<P : FeatureFlagProvider>(
Expand Down

0 comments on commit 5a34e76

Please sign in to comment.