featureflow 0.3.7 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/Gemfile.lock +1 -1
- data/README.md +39 -7
- data/lib/featureflow/evaluate.rb +1 -1
- data/lib/featureflow/polling_client.rb +2 -2
- data/lib/featureflow/rails/rails_client.rb +19 -0
- data/lib/featureflow/rails/railtie.rb +42 -0
- data/lib/featureflow/version.rb +1 -1
- data/lib/featureflow.rb +3 -1
- data/lib/generators/featureflow_generator.rb +24 -0
- data/test.rb +10 -10
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bb85e275ba7fc47744ef930e0a983e75a15323fd
|
4
|
+
data.tar.gz: 037f88e647b2ba2f72f3389f357bbb830e35ce23
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ccaac50587ea54480ac8beef8d3346cb905f9ce98e5158da9085bc1aa92a8769d40923ee41cd947e5a9188802c05f1c2d12faa4ac9279baf3cdbc8fae7395760
|
7
|
+
data.tar.gz: 6716daafbc92e7c94a2f0f10b7c065d5908181c50dc6ae1d2990837ab4377b7a0b195b9051269ff3ff1495fefa2bd332e7bfa359d8d90f90ec2bf9b4249e8912
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -36,17 +36,48 @@ The usage of each class is documented below.
|
|
36
36
|
|
37
37
|
### Quick start
|
38
38
|
|
39
|
-
|
39
|
+
Firstly you will need to get your environment's Featureflow Server API key and initialise a new Featureflow client
|
40
|
+
|
41
|
+
This will load the rules for each feature for the current environment, specified by the api key.
|
42
|
+
These rules can be changed at `https://<your-org-key>.featureflow.io`.
|
43
|
+
When the rules are updated, the changes made will be applied to your application.
|
44
|
+
|
45
|
+
##### Ruby Quick Start
|
46
|
+
|
47
|
+
If you are using ruby you can create a featureflow client like this:
|
40
48
|
|
41
49
|
```ruby
|
42
|
-
|
43
|
-
|
50
|
+
featureflow = Featureflow::Client.new api_key: '<Your server api key goes here>'
|
51
|
+
```
|
52
|
+
|
53
|
+
Or, you can set the environment variable `FEATUREFLOW_SERVER_KEY` and just write:
|
54
|
+
|
55
|
+
```ruby
|
56
|
+
featureflow = Featureflow::Client.new
|
57
|
+
```
|
58
|
+
**Note: `featureflow`, as instantiated above, should be treated as a singleton. You are responsible for sharing it with the rest of your application**
|
59
|
+
|
60
|
+
##### Rails Quick Start
|
61
|
+
|
62
|
+
If you are using rails you can run the generator to setup Featureflow in your Rails application.
|
63
|
+
|
64
|
+
```bash
|
65
|
+
$ rails generator featureflow <Your server api key goes here>
|
66
|
+
```
|
67
|
+
|
68
|
+
Or, you can set the environment variable `FEATUREFLOW_SERVER_KEY` and the Rails Featureflow client will pick it up and use that.
|
69
|
+
|
70
|
+
You will then be able to access your Featureflow client in your controllers, for example:
|
71
|
+
|
72
|
+
```ruby
|
73
|
+
class MainController < ApplicationController
|
74
|
+
def index
|
75
|
+
featureflow # this method will now reference the featureflow client
|
76
|
+
end
|
77
|
+
end
|
44
78
|
```
|
45
79
|
|
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
80
|
|
49
|
-
**Note: You are responsible for passing the featureflow instance around your application**
|
50
81
|
|
51
82
|
#### Defining Context
|
52
83
|
|
@@ -128,7 +159,8 @@ Further documentation can be found [here](http://docs.featureflow.io/docs)
|
|
128
159
|
## Roadmap
|
129
160
|
- [x] Write documentation
|
130
161
|
- [x] Release to RubyGems
|
131
|
-
- [
|
162
|
+
- [x] Write Ruby on Rails integration
|
163
|
+
- [ ] Add Ruby on Rails helper to user featureflow in views
|
132
164
|
|
133
165
|
## License
|
134
166
|
|
data/lib/featureflow/evaluate.rb
CHANGED
@@ -4,7 +4,7 @@ require 'json'
|
|
4
4
|
module Featureflow
|
5
5
|
class PollingClient
|
6
6
|
DEFAULT_OPTIONS = {
|
7
|
-
|
7
|
+
poll_interval: 30,
|
8
8
|
timeout: 30
|
9
9
|
}.freeze
|
10
10
|
def initialize(url, api_key, options = {}, &set_features)
|
@@ -17,7 +17,7 @@ module Featureflow
|
|
17
17
|
load_features
|
18
18
|
Thread.new do
|
19
19
|
loop do
|
20
|
-
sleep @options[:
|
20
|
+
sleep @options[:poll_interval]
|
21
21
|
load_features
|
22
22
|
end
|
23
23
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'featureflow/client'
|
2
|
+
|
3
|
+
module Featureflow
|
4
|
+
class RailsClient
|
5
|
+
def initialize(request)
|
6
|
+
@request = request
|
7
|
+
end
|
8
|
+
def evaluate(key, context)
|
9
|
+
request_context_values = {
|
10
|
+
'featureflow.ip' => @request.remote_ip,
|
11
|
+
'featureflow.url' => @request.original_url
|
12
|
+
}
|
13
|
+
context = {key: context, values: {}} if context.is_a?(String)
|
14
|
+
Featureflow.featureflow.evaluate(key,
|
15
|
+
key: context[:key],
|
16
|
+
values: request_context_values.merge(context[:values]))
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'featureflow/rails/rails_client'
|
2
|
+
module Featureflow
|
3
|
+
LOCK = Mutex.new
|
4
|
+
|
5
|
+
class << self
|
6
|
+
def configure(config_hash=nil)
|
7
|
+
if config_hash
|
8
|
+
configuration.merge!(config_hash)
|
9
|
+
end
|
10
|
+
|
11
|
+
yield(configuration) if block_given?
|
12
|
+
yield(featureflow) if block_given?
|
13
|
+
end
|
14
|
+
|
15
|
+
# Configuration getters
|
16
|
+
def configuration
|
17
|
+
@configuration = nil unless defined?(@configuration)
|
18
|
+
@configuration || LOCK.synchronize { @configuration ||= {} }
|
19
|
+
end
|
20
|
+
|
21
|
+
# Configuration getters
|
22
|
+
def featureflow
|
23
|
+
@featureflow = nil unless defined?(@featureflow)
|
24
|
+
@featureflow || LOCK.synchronize { @featureflow ||= Featureflow::Client.new(configuration) }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
class FeatureflowRailtie < Rails::Railtie
|
29
|
+
|
30
|
+
config.before_initialize do
|
31
|
+
ActiveSupport.on_load(:action_controller) do
|
32
|
+
# @client =
|
33
|
+
ActionController::Base.class_eval do
|
34
|
+
def featureflow
|
35
|
+
Featureflow::RailsClient.new(request)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
data/lib/featureflow/version.rb
CHANGED
data/lib/featureflow.rb
CHANGED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
class FeatureflowGenerator < Rails::Generators::Base
|
3
|
+
source_root File.expand_path('../templates', __FILE__)
|
4
|
+
|
5
|
+
argument :api_key, required: true, :desc => "required"
|
6
|
+
|
7
|
+
gem "featureflow"
|
8
|
+
|
9
|
+
desc "Configures the featureflow with your API key"
|
10
|
+
|
11
|
+
def create_initializer_file
|
12
|
+
unless /^srv-env-[a-f0-9]{32}$/ =~ api_key
|
13
|
+
raise Thor::Error, "Invalid featureflow environment api key #{api_key.inspect}\nYou can find your environment api key on your featureflow dashboard at https://[APP-NAME].featureflow.io/"
|
14
|
+
end
|
15
|
+
|
16
|
+
initializer "featureflow.rb" do
|
17
|
+
<<-EOF
|
18
|
+
Featureflow.configure(
|
19
|
+
api_key: #{api_key.inspect}
|
20
|
+
)
|
21
|
+
EOF
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/test.rb
CHANGED
@@ -7,15 +7,15 @@ with_features = [
|
|
7
7
|
|
8
8
|
|
9
9
|
|
10
|
-
api_key = 'srv-env-9b5fff890c724d119a334a64ed4d2eb2'
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
featureflow_client.evaluate('
|
15
|
-
featureflow_client.evaluate('
|
10
|
+
# api_key = 'srv-env-9b5fff890c724d119a334a64ed4d2eb2'
|
11
|
+
api_key = 'srv-env-f472cfa8c2774ea2b3678fc5a3dbfe13'
|
12
|
+
featureflow_client = Featureflow::Client.new(api_key: api_key, with_features: with_features, url: 'http://10.10.2.163:8081')
|
13
|
+
context = Featureflow::ContextBuilder.new('user1').build
|
14
|
+
puts('test-integration is on? ' + featureflow_client.evaluate('test-integration', context).on?.to_s)
|
15
|
+
featureflow_client.evaluate('nooooo', context).on?
|
16
|
+
featureflow_client.evaluate('default', context).on?
|
16
17
|
|
17
18
|
#
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
# end
|
19
|
+
loop do
|
20
|
+
sleep 1
|
21
|
+
end
|
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.
|
4
|
+
version: 0.4.0
|
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-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -105,7 +105,10 @@ files:
|
|
105
105
|
- lib/featureflow/events_client.rb
|
106
106
|
- lib/featureflow/feature.rb
|
107
107
|
- lib/featureflow/polling_client.rb
|
108
|
+
- lib/featureflow/rails/rails_client.rb
|
109
|
+
- lib/featureflow/rails/railtie.rb
|
108
110
|
- lib/featureflow/version.rb
|
111
|
+
- lib/generators/featureflow_generator.rb
|
109
112
|
- test.rb
|
110
113
|
homepage: https://github.com/featureflow/featureflow-ruby-sdk
|
111
114
|
licenses:
|