featureflow 0.3.6 → 0.3.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/Gemfile.lock +1 -1
- data/README.md +138 -1
- data/lib/featureflow/client.rb +7 -1
- data/lib/featureflow/feature.rb +1 -1
- data/lib/featureflow/version.rb +1 -1
- data/test.rb +7 -4
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 47b0db4c710ccf1fcff7d0042b2df43a14fb5ea1
|
4
|
+
data.tar.gz: d7b00c1a246338da291a2bb65db33b57bbbaada9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bf23b554a973e5ec9c4fb1169f6575750b40198f01e94c4018b5f0d820bb3a1f88733be3c5f76afecf90917224a5c35b72995f95e45aa3390e78c0c43451b64e
|
7
|
+
data.tar.gz: 8e2171aa3d6ce88e209912b32e2ff63c093a3efbfcd37124f5f392d25b90057bfe1af56011da43a52315f282cfcb28de6e04a64bb8f80418a882f094363123b7
|
data/CHANGELOG.md
ADDED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,141 @@
|
|
1
1
|
# featureflow-ruby-sdk
|
2
2
|
Ruby SDK for featureflow
|
3
3
|
|
4
|
-
|
4
|
+
[![][dependency-img]][dependency-url]
|
5
|
+
|
6
|
+
[![][rubygems-img]][rubygems-url]
|
7
|
+
|
8
|
+
> Featureflow Ruby SDK
|
9
|
+
|
10
|
+
Get your Featureflow account at [featureflow.io](http://www.featureflow.io)
|
11
|
+
|
12
|
+
## Get Started
|
13
|
+
|
14
|
+
The easiest way to get started is to follow the [Featureflow quick start guides](http://docs.featureflow.io/docs)
|
15
|
+
|
16
|
+
## Change Log
|
17
|
+
|
18
|
+
Please see [CHANGELOG](https://github.com/featureflow/featureflow-node-sdk/blob/master/CHANGELOG.md).
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
### Getting Started
|
23
|
+
|
24
|
+
##### Ruby
|
25
|
+
|
26
|
+
Add the following line to your Gemfile
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
gem 'featureflow'
|
30
|
+
```
|
31
|
+
|
32
|
+
Requiring `featureflow` in your ruby application will expose the classes
|
33
|
+
`Featureflow::Client`, `Featuerflow::ContextBuilder` and `Featureflow::Feature`.
|
34
|
+
|
35
|
+
The usage of each class is documented below.
|
36
|
+
|
37
|
+
### Quick start
|
38
|
+
|
39
|
+
Get your environment's Featureflow Server API key and initialise a new Featureflow client
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
FEATUREFLOW_SERVER_KEY = '<Your server api key goes here>'
|
43
|
+
featureflow = Featureflow::Client.new api_key: FEATUREFLOW_SERVER_KEY
|
44
|
+
```
|
45
|
+
|
46
|
+
This will load the rules for each feature for the current environment specified by the api key.
|
47
|
+
These rules can be changed at `https://<your-org-key>.featureflow.io`, and the changes will be applied to your application.
|
48
|
+
|
49
|
+
**Note: You are responsible for passing the featureflow instance around your application**
|
50
|
+
|
51
|
+
#### Defining Context
|
52
|
+
|
53
|
+
Before evaluating a feature you must define a context for the current user.
|
54
|
+
Featureflow uses context to target different user groups to specific feature variants.
|
55
|
+
A featureflow context has a `key`, which should uniquely identify the current user, and optionally additional `values`.
|
56
|
+
Featureflow requires the context `key` to be unique per user for gradual rollout of features.
|
57
|
+
|
58
|
+
There are two ways to define context:
|
59
|
+
```ruby
|
60
|
+
require 'featureflow'
|
61
|
+
context_key = '<unique_user_identifier>'
|
62
|
+
|
63
|
+
# option 1, use the context builder
|
64
|
+
context = Featureflow::ContextBuilder.new(context_key)
|
65
|
+
.with_values(country: 'US',
|
66
|
+
roles: %w[USER_ADMIN, BETA_CUSTOMER])
|
67
|
+
.build
|
68
|
+
|
69
|
+
# option 2, use just a string
|
70
|
+
context = context_key
|
71
|
+
```
|
72
|
+
|
73
|
+
#### Evaluating Features
|
74
|
+
|
75
|
+
In your code, you can test the value of your feature using something similar to below
|
76
|
+
For these examples below, assume the feature `my-feature-key` is equal to `'on'` for the current `context`
|
77
|
+
```ruby
|
78
|
+
if featureflow.evaluate('my-feature-key', context).is? 'on'
|
79
|
+
# this code will be run because 'my-feature-key' is set to 'on' for the given context
|
80
|
+
end
|
81
|
+
```
|
82
|
+
Because the most common variants for a feature are `'on'` and `'off'`, we have provided two helper methods `.on?` and `.off?`
|
83
|
+
|
84
|
+
```ruby
|
85
|
+
if featureflow.evaluate('my-feature-key', context).on?
|
86
|
+
# this feature code will be run because 'my-feature-key' is set to 'on'
|
87
|
+
end
|
88
|
+
|
89
|
+
if featureflow.evaluate('my-feature-key', context).off?
|
90
|
+
# this feature code won't be run because 'my-feature-key' is not set to 'off'
|
91
|
+
end
|
92
|
+
```
|
93
|
+
|
94
|
+
#### Pre-registering Features
|
95
|
+
|
96
|
+
Featureflow allows you to pre-register features that may not be defined in your Featureflow project to ensure that those
|
97
|
+
features are available when that version of your code is running.
|
98
|
+
If in the off-chance your application is unable to access the Featureflow servers and you don't have access
|
99
|
+
to a cached version of the features, you can specify a failover variant for any feature.
|
100
|
+
|
101
|
+
The failover variant allows you to control what variant a feature will evaluate to when no rules are available for the feature.
|
102
|
+
If a failover variant isn't defined, each feature will use a default feailover variant of `'off'`.
|
103
|
+
|
104
|
+
You can pre-register features at the initialisation of your featureflow client like below:
|
105
|
+
|
106
|
+
```ruby
|
107
|
+
require 'featureflow'
|
108
|
+
|
109
|
+
FEATUREFLOW_SERVER_KEY = '<Your server api key goes here>'
|
110
|
+
|
111
|
+
featureflow = Featureflow::Client.new(api_key: FEATUREFLOW_SERVER_KEY,
|
112
|
+
with_features: [
|
113
|
+
Featureflow::Feature.create('key-one', 'on'),
|
114
|
+
Featureflow::Feature.create('key-two'),
|
115
|
+
Featureflow::Feature.create('key-three', 'custom'),
|
116
|
+
])
|
117
|
+
|
118
|
+
# ... app has been started offline
|
119
|
+
featureflow.evaluate('key-one', context).on? # == true
|
120
|
+
featureflow.evaluate('key-two', context).off? # == true
|
121
|
+
featureflow.evaluate('key-three', context).is? 'custom' # == true
|
122
|
+
|
123
|
+
```
|
124
|
+
|
125
|
+
#### Further documentation
|
126
|
+
Further documentation can be found [here](http://docs.featureflow.io/docs)
|
127
|
+
|
128
|
+
## Roadmap
|
129
|
+
- [x] Write documentation
|
130
|
+
- [x] Release to RubyGems
|
131
|
+
- [ ] Write Ruby on Rails integration
|
132
|
+
|
133
|
+
## License
|
134
|
+
|
135
|
+
Apache-2.0
|
136
|
+
|
137
|
+
[rubygems-url]: https://rubygems.org/gems/featureflow
|
138
|
+
[rubygems-img]: https://badge.fury.io/rb/featureflow.png
|
139
|
+
|
140
|
+
[dependency-url]: https://www.featureflow.io
|
141
|
+
[dependency-img]: https://www.featureflow.io/wp-content/uploads/2016/12/featureflow-web.png
|
data/lib/featureflow/client.rb
CHANGED
@@ -50,7 +50,13 @@ module Featureflow
|
|
50
50
|
|
51
51
|
def evaluate(key, context)
|
52
52
|
raise ArgumentError, 'key must be a string' unless key.is_a?(String)
|
53
|
-
raise ArgumentError, 'context is required
|
53
|
+
raise ArgumentError, 'context is required' unless context
|
54
|
+
unless context.is_a?(String) || context.is_a?(Hash)
|
55
|
+
raise ArgumentError, 'context must be either a string context key,' + \
|
56
|
+
' or a Hash built using Featureflow::ContextBuilder)'
|
57
|
+
end
|
58
|
+
|
59
|
+
context = ContextBuilder.new(context).build if context.is_a?(String)
|
54
60
|
|
55
61
|
context = context.dup
|
56
62
|
context[:values] = context[:values].merge('featureflow.key' => context[:key],
|
data/lib/featureflow/feature.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module Featureflow
|
2
2
|
class Feature
|
3
|
-
def self.create(key, failover_variant)
|
3
|
+
def self.create(key, failover_variant = 'off')
|
4
4
|
raise ArgumentError, 'Parameter key must be a String' unless valid_key?(key)
|
5
5
|
raise ArgumentError, 'Parameter default_variant must be a String' unless valid_key?(failover_variant) || failover_variant.is_a?(NilClass)
|
6
6
|
{
|
data/lib/featureflow/version.rb
CHANGED
data/test.rb
CHANGED
@@ -4,12 +4,15 @@ require 'featureflow'
|
|
4
4
|
with_features = [
|
5
5
|
Featureflow::Feature.create('default', 'variant')
|
6
6
|
]
|
7
|
+
|
8
|
+
|
9
|
+
|
7
10
|
api_key = 'srv-env-9b5fff890c724d119a334a64ed4d2eb2'
|
8
11
|
featureflow_client = Featureflow::Client.new(api_key: api_key, with_features: with_features)
|
9
|
-
context = Featureflow::ContextBuilder.new('user1').build
|
10
|
-
puts('test-integration is on? ' + featureflow_client.evaluate('test-integration',
|
11
|
-
featureflow_client.evaluate('nooooo',
|
12
|
-
featureflow_client.evaluate('default',
|
12
|
+
# context = Featureflow::ContextBuilder.new('user1').build
|
13
|
+
puts('test-integration is on? ' + featureflow_client.evaluate('test-integration', 'user1').on?.to_s)
|
14
|
+
featureflow_client.evaluate('nooooo', 'user1').on?
|
15
|
+
featureflow_client.evaluate('default', 'user1').on?
|
13
16
|
|
14
17
|
#
|
15
18
|
# loop do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: featureflow
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Henry Young
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-06-
|
11
|
+
date: 2017-06-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -89,6 +89,7 @@ extra_rdoc_files: []
|
|
89
89
|
files:
|
90
90
|
- ".gitignore"
|
91
91
|
- ".rubocop.yml"
|
92
|
+
- CHANGELOG.md
|
92
93
|
- Gemfile
|
93
94
|
- Gemfile.lock
|
94
95
|
- LICENSE
|