Skip to content

Commit

Permalink
Update Memory documentation for storage data structure that includes …
Browse files Browse the repository at this point in the history
…config data on every treatment context
  • Loading branch information
veeweeherman committed Oct 12, 2023
1 parent b06d36e commit d8cf9c7
Showing 1 changed file with 26 additions and 7 deletions.
33 changes: 26 additions & 7 deletions docs/memory.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ Under the hood, the memory adapter stores data in a dictionary like so:
}
},
some_flag_name_with_treatments: {
User1: 'treatment_name_1',
User2: 'treatment_name_2',
User3: 'treatment_name_3'
User1: { treatment: 'treatment_name_1', config: { account_id: 123} },
User2: { treatment: 'treatment_name_2', config: nil },
User3: { treatment: 'treatment_name_3'}
}
}
```
Expand Down Expand Up @@ -103,21 +103,40 @@ Per flag name, there can only be one treatment per `context_key` (the ID of obje

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

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

### **#treatment_value**
#### Enabling with config data
You may want to also store configuration data with the treatment and context. You can pass the config data, with the optional `data` argument. The `data` is a Hash type, and must have a `config` as a key with its value as another Hash.

You can retrieve the flag's treatment name for a specific context.
```ruby
ThisFeature.test_adapter.enable_treatment!('flag_a', treatment: 'treatment_1', context: user1, data: { config: { key1: value1 } })
ThisFeature.test_adapter.storage # =>
{
'flag_a' => {
'User1': {
treatment: 'treatment_1',
config: {
key1: value1
}
}
}
}
```

### **#treatment_value / #treatment_config**

You can retrieve the flag's treatment name or config data 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)
ThisFeature.test_adapter.treatment_context(:flag_name, context: user)
```

#### This method requires 2 arguments:
Expand Down

0 comments on commit d8cf9c7

Please sign in to comment.