Skip to content

Commit

Permalink
First pass at documentation updates for the Memory Adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
veeweeherman committed Oct 12, 2023
1 parent 6594028 commit 6995f4a
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions docs/memory.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ Under the hood, the memory adapter stores data in a dictionary like so:
User1: true,
User2: false
}
},
some_flag_name_with_treatments: {
treatment_contexts: {
User1: 'treatment_name_1',
User2: 'treatment_name_2',
User3: 'treatment_name_3'
}
}
}
```
Expand Down Expand Up @@ -79,6 +86,47 @@ ThisFeature.test_adapter.on!(:flag_name, context: user) # with context
ThisFeature.test_adapter.off!(:flag_name) # without context
```

### **#enable_treatment!**

This method is useful when you need to enable a feature flag with a treatment (or multiple treatments), and not just `"on"` and `"off"`.

Usage example of these:

```ruby
# If you have configured the in-memory adapter as the default
ThisFeature.test_adapter.enable_treatment!(:flag_name, treatment: 'treatment_name', context: user)
```
#### This method requires 3 arguments:
1. `flag_name`: String or Symbol (not a named argument)
2. `treatment`: String
3. `context`: User or Org object

Per flag name, there can only be one treatment per `context_key` (the ID of object that is provided as `context`). So multiple calls with the same `context`, but different treatment names, will be overwritten.

```ruby
ThisFeature.test_adapter.enable_treatment!('flag_a', treatment: 'treatment_1', context: user1)
ThisFeature.test_adapter.storage # => { 'flag_a' => { :treatment_contexts => { 'User1': 'treatment_1' } } }

ThisFeature.test_adapter.enable_treatment!(:flag_a, treatment: 'treatment_2', context: user1)
ThisFeature.test_adapter.storage # => { 'flag_a' => { :treatment_contexts => { 'User1': 'treatment_2' } } }
```

### **#treatment_value**

You can retrieve the flag's treatment name for a specific context.

Usage example of these:

```ruby
# If you have configured the in-memory adapter as the default
ThisFeature.test_adapter.treatment_value(:flag_name, context: user)
```

#### This method requires 2 arguments:
1. `flag_name`: String or Symbol (not a named argument)
2. `context`: User or Org object

When the Memory storage does not contain the given flag_name or if there is no provided `context`, `"control"` is returned. This is meant to mimic what SplitIO would return in the case of no configured treatment for the given `context`.
### **#clear**

Since the memory adapter stores flags in memory, it won't automatically get cleaned up in your tests. You can use this method to reset the memory adapter state.
Expand Down

0 comments on commit 6995f4a

Please sign in to comment.